Skip to content

Commit 1e75400

Browse files
authored
fix: ensure serizlie reason is set before child call (#2864)
1 parent e16cc81 commit 1e75400

File tree

19 files changed

+499
-13
lines changed

19 files changed

+499
-13
lines changed

.changeset/fluffy-cars-grow.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+
Ensure serialize reason is set before child call in server compilation

packages/runtime-tags/src/__tests__/fixtures/at-tag-inside-if-tag/__snapshots__/html.expected/template.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ export default _._template("__tests__/template.marko", input => {
77
x
88
} = input;
99
const $childScope = _._peek_scope_id();
10+
_._set_serialize_reason({
11+
/* input.thing.x, input.thing.content */0: _._serialize_guard($serialize, /* x */0),
12+
/* input.thing.x */1: _._serialize_guard($serialize, /* x */0),
13+
/* input.thing.content */2: _._serialize_guard($serialize, /* x */0)
14+
});
1015
let $thing;
1116
if (x) {
1217
$thing = _.attrTag({
@@ -25,11 +30,6 @@ export default _._template("__tests__/template.marko", input => {
2530
})
2631
});
2732
}
28-
_._set_serialize_reason({
29-
/* input.thing.x, input.thing.content */0: _._serialize_guard($serialize, /* x */0),
30-
/* input.thing.x */1: _._serialize_guard($serialize, /* x */0),
31-
/* input.thing.content */2: _._serialize_guard($serialize, /* x */0)
32-
});
3333
_customTag({
3434
thing: $thing
3535
});

packages/runtime-tags/src/__tests__/fixtures/at-tags-dynamic-with-params/__snapshots__/html.expected/template.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default _._template("__tests__/template.marko", input => {
44
const $scope0_id = _._scope_id();
55
let x = true;
66
const $childScope = _._peek_scope_id();
7+
_._set_serialize_reason(/* state: x */1);
78
let $item;
89
if (x) {
910
$item = _.attrTag({
@@ -15,7 +16,6 @@ export default _._template("__tests__/template.marko", input => {
1516
})
1617
});
1718
}
18-
_._set_serialize_reason(/* state: x */1);
1919
_hello({
2020
item: $item
2121
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"vars": {
3+
"props": {
4+
"$_": "m",
5+
"$init": "o",
6+
"$$count__script": "r",
7+
"$$count": "t",
8+
"$$if_content": "n",
9+
"$$if": "_",
10+
"$$input_value": "a"
11+
}
12+
}
13+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Render
2+
```html
3+
<button>
4+
1
5+
</button>
6+
<span />
7+
```
8+
9+
10+
# Render
11+
```js
12+
container.querySelector("button").click();
13+
```
14+
```html
15+
<button>
16+
2
17+
</button>
18+
<span />
19+
```
20+
21+
22+
# Render
23+
```js
24+
container.querySelector("button").click();
25+
```
26+
```html
27+
<button>
28+
3
29+
</button>
30+
<span />
31+
```
32+
33+
34+
# Render
35+
```js
36+
container.querySelector("button").click();
37+
```
38+
```html
39+
<button>
40+
4
41+
</button>
42+
<span />
43+
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Render
2+
```html
3+
<button>
4+
1
5+
</button>
6+
<!---->
7+
<span />
8+
<!---->
9+
<!---->
10+
```
11+
12+
# Mutations
13+
```
14+
INSERT button, #comment0, span, #comment1, #comment2
15+
```
16+
17+
# Render
18+
```js
19+
container.querySelector("button").click();
20+
```
21+
```html
22+
<button>
23+
2
24+
</button>
25+
<!---->
26+
<span />
27+
<!---->
28+
<!---->
29+
```
30+
31+
# Mutations
32+
```
33+
UPDATE button/#text "1" => "2"
34+
```
35+
36+
# Render
37+
```js
38+
container.querySelector("button").click();
39+
```
40+
```html
41+
<button>
42+
3
43+
</button>
44+
<!---->
45+
<span />
46+
<!---->
47+
<!---->
48+
```
49+
50+
# Mutations
51+
```
52+
UPDATE button/#text "2" => "3"
53+
```
54+
55+
# Render
56+
```js
57+
container.querySelector("button").click();
58+
```
59+
```html
60+
<button>
61+
4
62+
</button>
63+
<!---->
64+
<span />
65+
<!---->
66+
<!---->
67+
```
68+
69+
# Mutations
70+
```
71+
UPDATE button/#text "3" => "4"
72+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export const $template = "<!><!><!>";
2+
export const $walks = /* over(1), replace, over(2) */"b%c";
3+
import * as _ from "@marko/runtime-tags/debug/dom";
4+
const $if_content = /* @__PURE__ */_._content_branch("<span></span>", /* over(1) */"b");
5+
const $if = /* @__PURE__ */_._if("#text/0", $if_content);
6+
export const $input_value = /* @__PURE__ */_._const("input_value", ($scope, input_value) => $if($scope, input_value ? 0 : 1));
7+
export function $setup($scope) {
8+
_._return($scope, 1);
9+
}
10+
export const $input = /* @__PURE__ */_._const("input", ($scope, input) => $input_value($scope, input.value));
11+
export default /* @__PURE__ */_._template("__tests__/tags/child.marko", $template, $walks, $setup, $input);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// size: 244 (min) 173 (brotli)
2+
const $if_content = _._content_branch("<span></span>", "b"),
3+
$if = _._if(0, $if_content),
4+
$input_value = _._const(3, ($scope, input_value) =>
5+
$if($scope, input_value ? 0 : 1),
6+
),
7+
$count__script = _._script("b0", ($scope, { 4: count }) =>
8+
_._on($scope[0], "click", function () {
9+
$count($scope, ++count);
10+
}),
11+
),
12+
$count = _._let(4, ($scope, count) => {
13+
(_._text($scope[1], count),
14+
$input_value($scope[2], count),
15+
$count__script($scope));
16+
});
17+
(_._var_resume("b1", ($scope) => {}), init());
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export const $template = `<button> </button>${_child_template}<!>`;
2+
export const $walks = /* get, next(1), get, out(1), beginChildWithVar, _child_walks, endChild, over(1) */` D l0${_child_walks}&b`;
3+
import * as _ from "@marko/runtime-tags/debug/dom";
4+
import { $setup as _child, $input_value as _child_input_value, $template as _child_template, $walks as _child_walks } from "./tags/child.marko";
5+
const $count__script = _._script("__tests__/template.marko_0_count", ($scope, {
6+
count
7+
}) => _._on($scope["#button/0"], "click", function () {
8+
$count($scope, ++count);
9+
}));
10+
const $count = /* @__PURE__ */_._let("count/4", ($scope, count) => {
11+
_._text($scope["#text/1"], count);
12+
_child_input_value($scope["#childScope/2"], count);
13+
$count__script($scope);
14+
});
15+
export function $setup($scope) {
16+
_._var($scope, "#childScope/2", $x);
17+
_child($scope["#childScope/2"]);
18+
$count($scope, 1);
19+
}
20+
const $x = _._var_resume("__tests__/template.marko_0_x/var", $scope => {});
21+
export default /* @__PURE__ */_._template("__tests__/template.marko", $template, $walks, $setup);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as _ from "@marko/runtime-tags/debug/html";
2+
export default _._template("__tests__/tags/child.marko", input => {
3+
const $serialize = _._get_serialize_reason();
4+
const $scope0_id = _._scope_id();
5+
_._if(() => {
6+
if (input.value) {
7+
const $scope1_id = _._scope_id();
8+
_._html("<span></span>");
9+
_._serialize_guard($serialize, /* input.value */0) && _._scope($scope1_id, {}, "__tests__/tags/child.marko", "1:2");
10+
return 0;
11+
}
12+
}, $scope0_id, "#text/0", _._serialize_guard($serialize, /* input.value */0), _._serialize_guard($serialize, /* input.value */0), _._serialize_guard($serialize, /* input.value */0), 0, 1);
13+
const $return = 1;
14+
_._serialize_guard($serialize, /* input.value */0) && _._scope($scope0_id, {}, "__tests__/tags/child.marko", 0);
15+
return $return;
16+
});

0 commit comments

Comments
 (0)