Skip to content

Commit 8c0f463

Browse files
committed
fix: issue hydrating non stateful for loop closure
1 parent 2da2ca0 commit 8c0f463

File tree

16 files changed

+506
-15
lines changed

16 files changed

+506
-15
lines changed

.changeset/honest-apes-shout.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@marko/runtime-tags": patch
3+
---
4+
5+
Fix issue with hydrating a closure within a non stateful for loop.

.sizes.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
{
88
"name": "*",
99
"total": {
10-
"min": 18979,
11-
"brotli": 7217
10+
"min": 18988,
11+
"brotli": 7245
1212
}
1313
},
1414
{
@@ -48,12 +48,12 @@
4848
"brotli": 461
4949
},
5050
"runtime": {
51-
"min": 6997,
52-
"brotli": 3003
51+
"min": 7006,
52+
"brotli": 3001
5353
},
5454
"total": {
55-
"min": 7916,
56-
"brotli": 3464
55+
"min": 7925,
56+
"brotli": 3462
5757
}
5858
},
5959
{

.sizes/dom.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// size: 18979 (min) 7217 (brotli)
1+
// size: 18988 (min) 7245 (brotli)
22
var empty = [],
33
rest = Symbol();
44
function attrTag(attrs2) {
@@ -1027,10 +1027,11 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
10271027
loopScopeAccessor = "l" + ownerLoopNodeAccessor,
10281028
loopScopeMapAccessor = "m" + ownerLoopNodeAccessor,
10291029
ownerSignal = (ownerScope) => {
1030-
let scopes =
1031-
ownerScope[loopScopeAccessor] ||
1032-
ownerScope[loopScopeMapAccessor]?.values() ||
1033-
[],
1030+
let scopes = (ownerScope[loopScopeAccessor] ||= ownerScope[
1031+
loopScopeMapAccessor
1032+
]
1033+
? [...ownerScope[loopScopeMapAccessor].values()]
1034+
: []),
10341035
[firstScope] = scopes;
10351036
firstScope &&
10361037
queueRender(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"vars": {
3+
"props": {
4+
"$_$": "o",
5+
"$init": "t",
6+
"$$count$for$content": "a",
7+
"$$count_effect": "m",
8+
"$$count": "r"
9+
}
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Render
2+
```html
3+
0-01-02-03-0
4+
<button>
5+
0
6+
</button>
7+
```
8+
9+
10+
# Render
11+
```js
12+
container.querySelector("button").click();
13+
```
14+
```html
15+
0-11-12-13-1
16+
<button>
17+
1
18+
</button>
19+
```
20+
21+
22+
# Render
23+
```js
24+
container.querySelector("button").click();
25+
```
26+
```html
27+
0-21-22-23-2
28+
<button>
29+
2
30+
</button>
31+
```
32+
33+
34+
# Render
35+
```js
36+
container.querySelector("button").click();
37+
```
38+
```html
39+
0-31-32-33-3
40+
<button>
41+
3
42+
</button>
43+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Render
2+
```html
3+
<!---->
4+
0-01-02-03-0
5+
<button>
6+
0
7+
</button>
8+
```
9+
10+
# Mutations
11+
```
12+
INSERT #comment, #text0, #text1, #text2, #text3, #text4, #text5, #text6, #text7, #text8, #text9, #text10, #text11, button
13+
```
14+
15+
# Render
16+
```js
17+
container.querySelector("button").click();
18+
```
19+
```html
20+
<!---->
21+
0-11-12-13-1
22+
<button>
23+
1
24+
</button>
25+
```
26+
27+
# Mutations
28+
```
29+
UPDATE button/#text "0" => "1"
30+
UPDATE #text2 "0" => "1"
31+
UPDATE #text5 "0" => "1"
32+
UPDATE #text8 "0" => "1"
33+
UPDATE #text11 "0" => "1"
34+
```
35+
36+
# Render
37+
```js
38+
container.querySelector("button").click();
39+
```
40+
```html
41+
<!---->
42+
0-21-22-23-2
43+
<button>
44+
2
45+
</button>
46+
```
47+
48+
# Mutations
49+
```
50+
UPDATE button/#text "1" => "2"
51+
UPDATE #text2 "1" => "2"
52+
UPDATE #text5 "1" => "2"
53+
UPDATE #text8 "1" => "2"
54+
UPDATE #text11 "1" => "2"
55+
```
56+
57+
# Render
58+
```js
59+
container.querySelector("button").click();
60+
```
61+
```html
62+
<!---->
63+
0-31-32-33-3
64+
<button>
65+
3
66+
</button>
67+
```
68+
69+
# Mutations
70+
```
71+
UPDATE button/#text "2" => "3"
72+
UPDATE #text2 "2" => "3"
73+
UPDATE #text5 "2" => "3"
74+
UPDATE #text8 "2" => "3"
75+
UPDATE #text11 "2" => "3"
76+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// size: 176 (min) 123 (brotli)
2+
const $count$for$content = _$.loopClosure(3, 0, ($scope, count) =>
3+
_$.data($scope[1], count),
4+
),
5+
$count_effect = _$.effect("a0", ($scope, { 3: count }) =>
6+
_$.on($scope[1], "click", function () {
7+
$count($scope, count + 1);
8+
}),
9+
),
10+
$count = _$.state(3, ($scope, count) => {
11+
_$.data($scope[2], count),
12+
$count$for$content($scope),
13+
$count_effect($scope);
14+
});
15+
init();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const $template = "<!><!><button> </button>";
2+
export const $walks = /* replace, over(1), get, next(1), get, out(1) */"D%b D l";
3+
import * as _$ from "@marko/runtime-tags/debug/dom";
4+
const $index$for$content = /* @__PURE__ */_$.value("index", ($scope, index) => _$.data($scope["#text/0"], index));
5+
const $count$for$content = /* @__PURE__ */_$.loopClosure("count", "#text/0", ($scope, count) => _$.data($scope["#text/1"], count));
6+
const $params2$for$content = /* @__PURE__ */_$.value("$params2", ($scope, $params2) => $index$for$content($scope, $params2[0]));
7+
const $for_content = /* @__PURE__ */_$.createRenderer("<!>-<!>", /* replace, over(2), replace */"%c%", 0, $params2$for$content, $count$for$content);
8+
const $count_effect = _$.effect("__tests__/template.marko_0_count", ($scope, {
9+
count
10+
}) => _$.on($scope["#button/1"], "click", function () {
11+
$count($scope, count + 1), count;
12+
}));
13+
const $count = /* @__PURE__ */_$.state("count/3", ($scope, count) => {
14+
_$.data($scope["#text/2"], count);
15+
$count$for$content($scope);
16+
$count_effect($scope);
17+
});
18+
const $for = /* @__PURE__ */_$.loopTo("#text/0", $for_content);
19+
export function $setup($scope) {
20+
$count($scope, 0);
21+
$for($scope, [3, 0, 1]);
22+
}
23+
export default /* @__PURE__ */_$.createTemplate("__tests__/template.marko", $template, $walks, $setup);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import * as _$ from "@marko/runtime-tags/debug/html";
2+
export default _$.createTemplate("__tests__/template.marko", input => {
3+
const $scope0_id = _$.nextScopeId();
4+
let count = 0;
5+
_$.resumeForTo(3, 0, 1, index => {
6+
const $scope1_id = _$.nextScopeId();
7+
_$.write(`${_$.escapeXML(index)}-<!>${_$.escapeXML(count)}${_$.markResumeNode($scope1_id, "#text/1")}`);
8+
_$.writeScope($scope1_id, {
9+
_: _$.ensureScopeWithId($scope0_id)
10+
}, "__tests__/template.marko", "3:2");
11+
}, 0, $scope0_id, "#text/0", /* state: count */1, 0);
12+
_$.write(`<button>${_$.escapeXML(count)}${_$.markResumeNode($scope0_id, "#text/2")}</button>${_$.markResumeNode($scope0_id, "#button/1")}`);
13+
_$.writeEffect($scope0_id, "__tests__/template.marko_0_count");
14+
_$.writeScope($scope0_id, {
15+
count
16+
}, "__tests__/template.marko", 0, {
17+
count: "1:6"
18+
});
19+
_$.resumeClosestBranch($scope0_id);
20+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Render
2+
```html
3+
0-01-02-03-0
4+
<button>
5+
0
6+
</button>
7+
```
8+
9+
10+
# Render
11+
```js
12+
container.querySelector("button").click();
13+
```
14+
```html
15+
0-11-12-13-1
16+
<button>
17+
1
18+
</button>
19+
```
20+
21+
22+
# Render
23+
```js
24+
container.querySelector("button").click();
25+
```
26+
```html
27+
0-21-22-23-2
28+
<button>
29+
2
30+
</button>
31+
```
32+
33+
34+
# Render
35+
```js
36+
container.querySelector("button").click();
37+
```
38+
```html
39+
0-31-32-33-3
40+
<button>
41+
3
42+
</button>
43+
```

0 commit comments

Comments
 (0)