Skip to content

Commit fa8bcca

Browse files
committed
fix: make binding default values first class
Default values in tag params and destructured tag variables are modeled directly in the binding graph: a source binding holds the value applied at the pattern's position, and the declared binding is derived from it. The DOM output registers the derivation as a signal value, collapsing it to a native parameter default when the fallback needs no state; the HTML output materializes the source variable so it stays serializable for resume. The alias root of a shared property always holds the raw value, so aliased destructures agree regardless of which side has a default.
1 parent b631eb5 commit fa8bcca

59 files changed

Lines changed: 1555 additions & 131 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
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 default values on top level tag parameters (eg `<my-tag|a, b = a|>`) being dropped in the DOM output, which caused a crash or stale content client side. Default values in tag parameters and destructured tag variables are now represented uniformly in the compiler and defaulted values are consistently resumable. Defaults whose fallback needs no state compile to native parameter defaults in the DOM output, and defaults on unused bindings are pruned from it entirely.

packages/runtime-tags/src/__tests__/fixtures/const-array-pattern/__snapshots__/dom.bundle.debug.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// template.marko
22
const $template = "<button>inc <!></button><div><!>|<!>|<!></div>";
33
const $walks = " Db%lD%c%c%l";
4+
const $second2 = ($scope, second = "dflt") => _text($scope["#text/3"], second);
5+
const $second3 = $second2;
46
const $pattern2 = ($scope, $pattern) => {
57
(([, , ...others]) => $others($scope, others))($pattern);
68
$first($scope, $pattern[0]);
7-
$second2($scope, $pattern[1]);
9+
$second3($scope, $pattern[1]);
810
};
911
const $others = ($scope, others) => _text($scope["#text/4"], others.join(","));
1012
const $first = ($scope, first) => _text($scope["#text/2"], first);
11-
const $second3 = ($scope, second) => _text($scope["#text/3"], second);
12-
const $second2 = ($scope, $second) => $second3($scope, void 0 !== $second ? $second : "dflt");
1313
const $input_list = $pattern2;
1414
const $n = /*@__PURE__*/ _let("n/13", ($scope) => _text($scope["#text/1"], $scope.n));
1515
const $setup__script = _script("__tests__/template.marko_0", ($scope) => _on($scope["#button/0"], "click", function() {

packages/runtime-tags/src/__tests__/fixtures/content-params-array-defaults/__snapshots__/dom.bundle.debug.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
const $Wrap_content__walks = "D%c%l", $Wrap_content__template = "<div><!>|<!></div>";
33
const $template = /*@__PURE__*/ ((_w0, _w1) => `<button>inc</button>${_w0}${_w1}<!>`)($Wrap_content__template, $Wrap_content__template);
44
const $walks = /*@__PURE__*/ ((_w0, _w1) => ` b/${_w0}&/${_w1}&b`)($Wrap_content__walks, $Wrap_content__walks);
5-
const $Wrap_content__a = ($scope, a) => _text($scope["#text/0"], a);
6-
const $Wrap_content__$a = ($scope, $a) => $Wrap_content__a($scope, void 0 !== $a ? $a : 1);
5+
const $Wrap_content__a = ($scope, a = 1) => _text($scope["#text/0"], a);
6+
const $Wrap_content__$a = $Wrap_content__a;
77
const $Wrap_content__b = ($scope, b) => _text($scope["#text/1"], b);
88
const $Wrap_content__tag_param_ = ($scope, $temp) => {
99
$Wrap_content__$a($scope, $temp[0]);

packages/runtime-tags/src/__tests__/fixtures/content-params-array-defaults/__snapshots__/dom.bundle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// template.marko
2-
const $Wrap_content__a = ($scope, a) => _text($scope.a, a);
3-
const $Wrap_content__$a = ($scope, $a) => $Wrap_content__a($scope, void 0 !== $a ? $a : 1);
2+
const $Wrap_content__a = ($scope, a = 1) => _text($scope.a, a);
3+
const $Wrap_content__$a = $Wrap_content__a;
44
const $Wrap_content__b = ($scope, b) => _text($scope.b, b);
55
const $Wrap_content__tag_param_ = ($scope, $temp) => {
66
$Wrap_content__$a($scope, $temp[0]);

packages/runtime-tags/src/__tests__/fixtures/content-params-array-defaults/sizes.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"dom": {
33
"template.marko.page.mjs": {
4-
"min": 2727,
5-
"brotli": 1367
4+
"min": 2700,
5+
"brotli": 1362
66
}
77
},
88
"html": {

packages/runtime-tags/src/__tests__/fixtures/custom-tag-var-destructured/__snapshots__/dom.bundle.debug.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ var child_default = /*@__PURE__*/ _template("__tests__/tags/child.marko", $templ
2929
// template.marko
3030
const $template = /*@__PURE__*/ ((_w0) => `${_w0}<button class=inc>inc</button><button class=assign>assign</button><div><!>:<!></div>`)($template$1);
3131
const $walks = /*@__PURE__*/ ((_w0) => `0${_w0}& b bD%c%l`)($walks$1);
32+
const $missing2 = ($scope, missing = "fallback") => _text($scope["#text/5"], missing);
33+
const $missing3 = $missing2;
3234
const $pattern2 = _var_resume("__tests__/template.marko_0_$pattern/var", ($scope, $pattern) => {
3335
$count($scope, $pattern.count);
3436
$countChange2($scope, $pattern.countChange);
3537
$inc($scope, $pattern.inc);
36-
$missing2($scope, $pattern.missing);
38+
$missing3($scope, $pattern.missing);
3739
});
3840
const $count__OR__$countChange__script = _script("__tests__/template.marko_0_count_$countChange", ($scope) => _on($scope["#button/3"], "click", function() {
3941
$scope.$countChange($scope.count + 10);
@@ -48,8 +50,6 @@ const $inc__script = _script("__tests__/template.marko_0_inc", ($scope) => _on($
4850
$scope.inc();
4951
}));
5052
const $inc = /*@__PURE__*/ _const("inc", $inc__script);
51-
const $missing3 = ($scope, missing) => _text($scope["#text/5"], missing);
52-
const $missing2 = ($scope, $missing) => $missing3($scope, void 0 !== $missing ? $missing : "fallback");
5353
function $setup($scope) {
5454
_var($scope, "#childScope/0", $pattern2);
5555
$setup$1($scope["#childScope/0"]);

packages/runtime-tags/src/__tests__/fixtures/custom-tag-var-destructured/__snapshots__/dom.bundle.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ _resume("b1", $_return2);
2121
_resume("b0", $_return);
2222

2323
// template.marko
24+
const $missing2 = ($scope, missing = "fallback") => _text($scope.f, missing);
25+
const $missing3 = $missing2;
2426
const $pattern2 = _var_resume("a0", ($scope, $pattern) => {
2527
$count($scope, $pattern.count);
2628
$countChange2($scope, $pattern.countChange);
2729
$inc($scope, $pattern.inc);
28-
$missing2($scope, $pattern.missing);
30+
$missing3($scope, $pattern.missing);
2931
});
3032
const $count__OR__$countChange = /*@__PURE__*/ _or(9, _script("a1", ($scope) => _on($scope.d, "click", function() {
3133
$scope.i($scope.h + 10);
@@ -38,5 +40,3 @@ const $countChange2 = /*@__PURE__*/ _const(8, $count__OR__$countChange);
3840
const $inc = /*@__PURE__*/ _const(10, _script("a2", ($scope) => _on($scope.c, "click", function() {
3941
$scope.k();
4042
})));
41-
const $missing3 = ($scope, missing) => _text($scope.f, missing);
42-
const $missing2 = ($scope, $missing) => $missing3($scope, void 0 !== $missing ? $missing : "fallback");

packages/runtime-tags/src/__tests__/fixtures/custom-tag-var-destructured/__snapshots__/html.bundle.debug.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var template_default = _template("__tests__/template.marko", (input) => {
2424
const $scope0_id = _scope_id();
2525
const $childScope = _peek_scope_id();
2626
let { countChange: $countChange, count, inc, missing: $missing } = child_default({});
27-
_var($scope0_id, "#scopeOffset/1", $childScope, "__tests__/template.marko_0_$pattern/var");
2827
const missing = void 0 !== $missing ? $missing : "fallback";
28+
_var($scope0_id, "#scopeOffset/1", $childScope, "__tests__/template.marko_0_$pattern/var");
2929
_html(`<button class=inc>inc</button>${_el_resume($scope0_id, "#button/2")}<button class=assign>assign</button>${_el_resume($scope0_id, "#button/3")}<div>${_escape(count)}${_el_resume($scope0_id, "#text/4")}:<!>${_escape(missing)}${_el_resume($scope0_id, "#text/5")}</div>`);
3030
_script($scope0_id, "__tests__/template.marko_0_count_$countChange");
3131
_script($scope0_id, "__tests__/template.marko_0_inc");

packages/runtime-tags/src/__tests__/fixtures/custom-tag-var-destructured/__snapshots__/html.bundle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var template_default = _template("a", (input) => {
2424
const $scope0_id = _scope_id();
2525
const $childScope = _peek_scope_id();
2626
let { countChange: $countChange, count, inc, missing: $missing } = child_default({});
27-
_var($scope0_id, "b", $childScope, "a0");
2827
const missing = void 0 !== $missing ? $missing : "fallback";
28+
_var($scope0_id, "b", $childScope, "a0");
2929
_html(`<button class=inc>inc</button>${_el_resume($scope0_id, "c")}<button class=assign>assign</button>${_el_resume($scope0_id, "d")}<div>${_escape(count)}${_el_resume($scope0_id, "e")}:<!>${_escape(missing)}${_el_resume($scope0_id, "f")}</div>`);
3030
_script($scope0_id, "a1");
3131
_script($scope0_id, "a2");

packages/runtime-tags/src/__tests__/fixtures/custom-tag-var-destructured/sizes.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
"dom": {
33
"template.marko.page.mjs": {
44
"total": {
5-
"min": 3249,
6-
"brotli": 1580
5+
"min": 3228,
6+
"brotli": 1573
77
},
88
"files": {
99
"tags/child.marko": 454,
10-
"template.marko": 883
10+
"template.marko": 821
1111
}
1212
}
1313
},

0 commit comments

Comments
 (0)