marko 6.4.0 → 6.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/cheatsheet.md +1 -1
  2. package/dist/common/constants/accessor-prefix.d.ts +1 -0
  3. package/dist/common/constants/accessor-prefix.debug.d.ts +1 -0
  4. package/dist/common/constants/reserved-id.d.ts +5 -0
  5. package/dist/common/errors.d.ts +1 -1
  6. package/dist/common/types.d.ts +3 -0
  7. package/dist/debug/dom/catch.feat.js +1 -1
  8. package/dist/debug/dom/catch.feat.mjs +1 -1
  9. package/dist/debug/dom/controllable-input.feat.js +1 -1
  10. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  11. package/dist/debug/dom/controllable-open.feat.js +1 -1
  12. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  13. package/dist/debug/dom/controllable-select.feat.js +1 -1
  14. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  15. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  16. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  17. package/dist/debug/dom/controllable.feat.js +1 -1
  18. package/dist/debug/dom/controllable.feat.mjs +1 -1
  19. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  20. package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
  21. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  22. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  23. package/dist/debug/dom/lazy.feat.js +1 -1
  24. package/dist/debug/dom/lazy.feat.mjs +1 -1
  25. package/dist/debug/dom/placeholder.feat.js +1 -1
  26. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  27. package/dist/debug/{dom-BRO5aArp.js → dom-ClV4kVOO.js} +32 -16
  28. package/dist/debug/{dom-Btj2QJhk.mjs → dom-LFrKxOk5.mjs} +32 -16
  29. package/dist/debug/dom.js +1 -1
  30. package/dist/debug/dom.mjs +1 -1
  31. package/dist/debug/html.js +277 -222
  32. package/dist/debug/html.mjs +275 -220
  33. package/dist/dom/catch.feat.js +1 -1
  34. package/dist/dom/catch.feat.mjs +1 -1
  35. package/dist/dom/controllable-input.feat.js +1 -1
  36. package/dist/dom/controllable-input.feat.mjs +1 -1
  37. package/dist/dom/controllable-open.feat.js +1 -1
  38. package/dist/dom/controllable-open.feat.mjs +1 -1
  39. package/dist/dom/controllable-select.feat.js +1 -1
  40. package/dist/dom/controllable-select.feat.mjs +1 -1
  41. package/dist/dom/controllable-textarea.feat.js +1 -1
  42. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  43. package/dist/dom/controllable.feat.js +1 -1
  44. package/dist/dom/controllable.feat.mjs +1 -1
  45. package/dist/dom/dynamic-tag-script.feat.js +1 -1
  46. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  47. package/dist/dom/dynamic-tag-var.feat.js +1 -1
  48. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  49. package/dist/dom/lazy.feat.js +1 -1
  50. package/dist/dom/lazy.feat.mjs +1 -1
  51. package/dist/dom/placeholder.feat.js +1 -1
  52. package/dist/dom/placeholder.feat.mjs +1 -1
  53. package/dist/dom/signals.d.ts +3 -2
  54. package/dist/{dom-BSsI9OPC.js → dom-CNglVi8P.js} +13 -4
  55. package/dist/{dom-B-v8Gw6T.mjs → dom-DfP3MCo0.mjs} +13 -4
  56. package/dist/dom.js +1 -1
  57. package/dist/dom.mjs +1 -1
  58. package/dist/html/attrs.d.ts +2 -2
  59. package/dist/html/dynamic-tag.d.ts +1 -1
  60. package/dist/html/inlined-runtimes.d.ts +1 -1
  61. package/dist/html/inlined-runtimes.debug.d.ts +1 -1
  62. package/dist/html/serializer.d.ts +1 -1
  63. package/dist/html/writer.d.ts +34 -22
  64. package/dist/html.d.ts +1 -1
  65. package/dist/html.js +224 -167
  66. package/dist/html.mjs +224 -167
  67. package/dist/translator/core/html-comment.d.ts +0 -7
  68. package/dist/translator/core/let.d.ts +0 -5
  69. package/dist/translator/core/show.d.ts +2 -5
  70. package/dist/translator/core/style.d.ts +6 -8
  71. package/dist/translator/index.d.ts +9 -0
  72. package/dist/translator/index.js +8573 -8458
  73. package/dist/translator/util/binding-has-prop.d.ts +1 -1
  74. package/dist/translator/util/binding-prop-tree.d.ts +4 -4
  75. package/dist/translator/util/bindings.d.ts +127 -0
  76. package/dist/translator/util/body-to-text-literal.d.ts +1 -2
  77. package/dist/translator/util/branch-tag.d.ts +7 -7
  78. package/dist/translator/util/constants/binding-type.d.ts +5 -6
  79. package/dist/translator/util/constants/slot-kind.d.ts +14 -0
  80. package/dist/translator/util/constants/structure-kind.d.ts +1 -1
  81. package/dist/translator/util/evaluate.d.ts +11 -10
  82. package/dist/translator/util/finalize-references.d.ts +4 -0
  83. package/dist/translator/util/for-selector.d.ts +1 -1
  84. package/dist/translator/util/generate-uid.d.ts +3 -1
  85. package/dist/translator/util/get-declared-binding-expression.d.ts +2 -2
  86. package/dist/translator/util/is-core-tag.d.ts +0 -3
  87. package/dist/translator/util/is-only-child-in-parent.d.ts +2 -7
  88. package/dist/translator/util/known-tag.d.ts +8 -7
  89. package/dist/translator/util/read-replacement.d.ts +3 -0
  90. package/dist/translator/util/reasons.d.ts +32 -0
  91. package/dist/translator/util/references.d.ts +67 -166
  92. package/dist/translator/util/scope-accessor.d.ts +14 -0
  93. package/dist/translator/util/scope-read.d.ts +1 -1
  94. package/dist/translator/util/sections.d.ts +48 -48
  95. package/dist/translator/util/set-tag-derived-from.d.ts +7 -0
  96. package/dist/translator/util/setup-work.d.ts +1 -2
  97. package/dist/translator/util/signals.d.ts +3 -5
  98. package/dist/translator/util/slots.d.ts +50 -0
  99. package/dist/translator/util/solve-reasons.d.ts +10 -0
  100. package/dist/translator/util/sources.d.ts +21 -0
  101. package/dist/translator/util/structure.d.ts +5 -2
  102. package/dist/translator/util/tag-facts.d.ts +21 -0
  103. package/dist/translator/util/tag-name-type.d.ts +4 -1
  104. package/dist/translator/util/translate-attrs.d.ts +2 -0
  105. package/dist/translator/util/translate-var.d.ts +3 -0
  106. package/dist/translator/util/write-guard.d.ts +12 -0
  107. package/dist/translator/util/writer.d.ts +3 -3
  108. package/dist/translator/visitors/export-declaration.d.ts +9 -0
  109. package/dist/translator/visitors/function.d.ts +5 -4
  110. package/dist/translator/visitors/import-declaration.d.ts +2 -2
  111. package/dist/translator/visitors/placeholder.d.ts +0 -3
  112. package/dist/translator/visitors/program/index.d.ts +13 -3
  113. package/dist/translator/visitors/referenced-identifier.d.ts +2 -1
  114. package/dist/translator/visitors/tag/custom-tag.d.ts +1 -1
  115. package/dist/translator/visitors/tag/dynamic-tag.d.ts +0 -3
  116. package/dist/translator/visitors/tag/index.d.ts +2 -1
  117. package/dist/translator/visitors/tag/native-tag.d.ts +26 -12
  118. package/package.json +2 -2
  119. package/dist/translator/util/insertion-context.d.ts +0 -1
  120. package/dist/translator/util/is-non-html-text.d.ts +0 -3
  121. package/dist/translator/util/serialize-guard.d.ts +0 -11
  122. package/dist/translator/util/serialize-reasons.d.ts +0 -37
  123. package/dist/translator/util/set-tag-sections-downstream.d.ts +0 -6
@@ -218,18 +218,18 @@ function _hoist_read_error() {
218
218
  function _assert_hoist(value) {
219
219
  if (value !== void 0 && typeof value !== "function") throw new Error(`Hoisted values must be functions, received type "${typeof value}".`);
220
220
  }
221
- function assertExclusiveAttrs(attrs, onError = throwErr) {
221
+ function assertExclusiveAttrs(attrs, onError = throwErr, isSet = isTruthy) {
222
222
  if (attrs) {
223
223
  let exclusiveAttrs;
224
- if (attrs.checkedChange) (exclusiveAttrs ||= []).push("checkedChange");
224
+ if (isSet(attrs.checkedChange)) (exclusiveAttrs ||= []).push("checkedChange");
225
225
  if ("checkedValue" in attrs) {
226
226
  (exclusiveAttrs ||= []).push("checkedValue");
227
227
  if ("checked" in attrs) exclusiveAttrs.push("checked");
228
- } else if (attrs.checkedValueChange) {
228
+ } else if (isSet(attrs.checkedValueChange)) {
229
229
  (exclusiveAttrs ||= []).push("checkedValueChange");
230
230
  if ("checked" in attrs) exclusiveAttrs.push("checked");
231
231
  }
232
- if (attrs.valueChange) {
232
+ if (isSet(attrs.valueChange)) {
233
233
  (exclusiveAttrs ||= []).push("valueChange");
234
234
  if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
235
235
  }
@@ -245,6 +245,9 @@ function assertHandlerIsFunction(name, value) {
245
245
  function assertValidTagName(tagName) {
246
246
  if (!/^[a-z][a-z0-9._-]*$/i.test(tagName)) throw new Error(`Invalid tag name: "${tagName}". Tag names must start with a letter and contain only letters, numbers, periods, hyphens, and underscores.`);
247
247
  }
248
+ function isTruthy(value) {
249
+ return value;
250
+ }
248
251
  function throwErr(msg) {
249
252
  throw new Error(msg);
250
253
  }
@@ -291,12 +294,6 @@ function forUntil(until, from, step, cb) {
291
294
  }
292
295
  //#endregion
293
296
  //#region src/common/opt.ts
294
- function forEach(opt, cb) {
295
- if (opt) {
296
- if (Array.isArray(opt)) for (const item of opt) cb(item);
297
- else cb(opt);
298
- }
299
- }
300
297
  function push(opt, item) {
301
298
  return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
302
299
  }
@@ -738,7 +735,7 @@ function writeAssigned(state) {
738
735
  if (writeProp(state, mutation.object, null, "")) {
739
736
  const objectRef = state.refs.get(mutation.object);
740
737
  if (objectRef && objectRef.scopeId === void 0) {
741
- if (!objectRef.id) {
738
+ if (!objectRef.id && !isAncestorChannelRef(state, objectRef)) {
742
739
  objectRef.id = nextRefAccess(state);
743
740
  state.buf[objectStartIndex] = "(" + objectRef.id + "=" + state.buf[objectStartIndex];
744
741
  state.buf.push(")");
@@ -751,7 +748,7 @@ function writeAssigned(state) {
751
748
  const valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
752
749
  if (mutation.value === void 0) {} else if (writeProp(state, mutation.value, null, "")) {
753
750
  const valueRef = typeof mutation.value === "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
754
- if (valueRef && !valueRef.id && valueRef.scopeId === void 0) {
751
+ if (valueRef && !valueRef.id && valueRef.scopeId === void 0 && !isAncestorChannelRef(state, valueRef)) {
755
752
  valueRef.id = mutation.valueId || nextRefAccess(state);
756
753
  state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex];
757
754
  }
@@ -768,7 +765,7 @@ function writeCallArg(state, val) {
768
765
  state.buf.push("$");
769
766
  } else if (writeProp(state, val, null, "")) {
770
767
  const ref = state.refs.get(val) || state.strs.get(val);
771
- if (ref && ref.id === null) assignId(state, ref);
768
+ if (ref) ensureId(state, ref);
772
769
  } else state.buf.push("void 0");
773
770
  }
774
771
  function hasChannelMutations(state) {
@@ -850,8 +847,7 @@ function writeRegistered(state, val, parent, accessor, registered) {
850
847
  state.buf.push(registered.access + "(_(" + scopeId + ")");
851
848
  for (const local of locals) {
852
849
  state.buf.push(",");
853
- if (local) writePlainObject(state, local, new Reference(ref, null, state.flushId, state.buf.length));
854
- else state.buf.push("0");
850
+ writePlainObject(state, local, newArgReference(state, ref, local));
855
851
  }
856
852
  } else state.buf.push("_(" + scopeId + "," + quoteRegisterId(registered.id));
857
853
  state.buf.push(")");
@@ -1160,6 +1156,17 @@ function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
1160
1156
  }
1161
1157
  state.buf.push(")");
1162
1158
  }
1159
+ function newArgReference(state, parent, val) {
1160
+ for (const key in val) {
1161
+ const member = val[key];
1162
+ if (isDedupedMember(member) && !(typeof member === "string" ? state.strs.has(member) : state.refs.has(member))) {
1163
+ const ref = new Reference(parent, null, state.flushId, null, nextRefAccess(state));
1164
+ state.buf.push(ref.id + "=");
1165
+ return ref;
1166
+ }
1167
+ }
1168
+ return new Reference(parent, null, state.flushId, state.buf.length);
1169
+ }
1163
1170
  function isDedupedMember(val) {
1164
1171
  switch (typeof val) {
1165
1172
  case "object": return val !== null && val[K_SCOPE_ID] === void 0;
@@ -1356,20 +1363,9 @@ function writeResponse(state, val, ref) {
1356
1363
  }
1357
1364
  function writeIntl(state, val, name, ref) {
1358
1365
  const { locale, ...options } = val.resolvedOptions();
1359
- let needsId = false;
1360
- for (const key in options) if (isDedupedMember(options[key])) {
1361
- needsId = true;
1362
- break;
1363
- }
1364
1366
  state.buf.push("new Intl." + name + "(" + quote(locale, 0) + ",");
1365
- let optionsRef;
1366
- if (needsId) {
1367
- optionsRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1368
- state.buf.push(optionsRef.id + "={");
1369
- } else {
1370
- optionsRef = new Reference(ref, null, state.flushId, state.buf.length);
1371
- state.buf.push("{");
1372
- }
1367
+ const optionsRef = newArgReference(state, ref, options);
1368
+ state.buf.push("{");
1373
1369
  writeObjectProps(state, options, optionsRef);
1374
1370
  state.buf.push("})");
1375
1371
  return true;
@@ -1393,7 +1389,7 @@ function writeReadableStream(state, val, ref) {
1393
1389
  const handle = newAsyncHandle(state, ref, iterId);
1394
1390
  const onFulfilled = ({ value, done }) => {
1395
1391
  if (done) writeAsyncCall(state, boundary, handle, "r", value, channel);
1396
- else if (!boundary.signal.aborted) {
1392
+ else if (!boundary.aborted) {
1397
1393
  reader.read().then(onFulfilled, onRejected);
1398
1394
  boundary.startAsync();
1399
1395
  writeAsyncCall(state, boundary, handle, "f", value, channel);
@@ -1440,13 +1436,10 @@ function writeGenerator(state, iter, ref) {
1440
1436
  state.buf.push("," + holder.id + "={}");
1441
1437
  writeProp(state, returnValue, holder, "v");
1442
1438
  } else if (returnValue !== void 0) {
1443
- const sepIndex = state.buf.push(",") - 1;
1439
+ state.buf.push(",");
1444
1440
  if (writeProp(state, returnValue, ref, "") && isDedupedMember(returnValue)) {
1445
1441
  const retRef = typeof returnValue === "string" ? state.strs.get(returnValue) : state.refs.get(returnValue);
1446
- if (retRef && !retRef.id && retRef.scopeId === void 0) {
1447
- retRef.id = nextRefAccess(state);
1448
- state.buf[sepIndex] = "," + retRef.id + "=";
1449
- }
1442
+ if (retRef) ensureId(state, retRef);
1450
1443
  }
1451
1444
  }
1452
1445
  state.buf.push(")");
@@ -1462,7 +1455,7 @@ function writeAsyncGenerator(state, iter, ref) {
1462
1455
  const handle = newAsyncHandle(state, ref, iterId);
1463
1456
  const onFulfilled = ({ value, done }) => {
1464
1457
  if (done) writeAsyncCall(state, boundary, handle, "r", value, channel);
1465
- else if (!boundary.signal.aborted) {
1458
+ else if (!boundary.aborted) {
1466
1459
  iter.next().then(onFulfilled, onRejected);
1467
1460
  boundary.startAsync();
1468
1461
  writeAsyncCall(state, boundary, handle, "f", value, channel);
@@ -1509,7 +1502,7 @@ function writeMaybeIterableProps(state, val, ref) {
1509
1502
  return sep;
1510
1503
  }
1511
1504
  function writeAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
1512
- if (boundary.signal.aborted) return;
1505
+ if (boundary.aborted) return;
1513
1506
  state.mutated.push({
1514
1507
  value,
1515
1508
  object: handle,
@@ -1567,6 +1560,7 @@ const accessorPrefixDescriptions = {
1567
1560
  ControlledType: "the controlled type",
1568
1561
  ControlledValue: "the controlled value",
1569
1562
  DynamicHTMLLastChild: "the dynamic html",
1563
+ DynamicHTMLValue: "the dynamic html value",
1570
1564
  EventAttributes: "the event handlers",
1571
1565
  IdFallback: "the generated id",
1572
1566
  KeyedScopes: "the keyed scopes",
@@ -1605,6 +1599,9 @@ function trackChannel(state, ref) {
1605
1599
  }
1606
1600
  return false;
1607
1601
  }
1602
+ function isAncestorChannelRef(state, ref) {
1603
+ return ref.channel?.readyId !== state.channel?.readyId;
1604
+ }
1608
1605
  function abortUnreachableChannel(state, val) {
1609
1606
  const err = new TypeError("Unable to serialize a value shared between independently lazy loaded content. Values shared this way must also be serialized by content that is not lazily loaded, or by a common parent.", { cause: val });
1610
1607
  err.stack = void 0;
@@ -1698,11 +1695,10 @@ function quote(str, startPos) {
1698
1695
  return "\"" + (lastPos === startPos ? str : result + str.slice(lastPos)) + "\"";
1699
1696
  }
1700
1697
  function writeRef(state, ref) {
1701
- if (ref.id === null && ref.scopeId === void 0 && ref.path === null && (ref.pos === null || ref.flushId !== state.flushId)) {
1698
+ if (ref.id === null && ref.scopeId === void 0 && ref.path === null && (ref.pos === null || ref.flushId !== state.flushId) && !isAncestorChannelRef(state, ref)) {
1702
1699
  ref.path = accessPath(state, ref);
1703
1700
  ref.pos = state.buf.length;
1704
1701
  ref.flushId = state.flushId;
1705
- ref.channel = state.channel;
1706
1702
  state.buf.push(ref.path);
1707
1703
  } else state.buf.push(ensureId(state, ref));
1708
1704
  }
@@ -1723,23 +1719,26 @@ function accessId(state, ref) {
1723
1719
  }
1724
1720
  function assignId(state, ref) {
1725
1721
  const { pos } = ref;
1726
- ref.id = nextRefAccess(state);
1727
1722
  if (pos !== null && ref.flushId === state.flushId) {
1723
+ ref.id = nextRefAccess(state);
1728
1724
  if (pos === 0) state.buf[0] = ref.id + "=" + state.buf[0];
1729
1725
  else state.buf[pos - 1] += ref.id + "=";
1730
1726
  return ref.id;
1731
1727
  }
1732
- ref.channel = state.channel;
1728
+ if (isAncestorChannelRef(state, ref)) return ref.path || accessPath(state, ref);
1729
+ ref.id = nextRefAccess(state);
1733
1730
  return ref.id + "=" + (ref.path || accessPath(state, ref));
1734
1731
  }
1735
1732
  function accessPath(state, ref) {
1736
1733
  let cur = ref;
1737
1734
  let accessPrevValue = "";
1738
1735
  do {
1736
+ if (cur.accessor === null) throw new Error("Unable to serialize a reused value: no access path reaches where it was first written, and it has no id.");
1739
1737
  accessPrevValue = toAccess(cur.accessor) + accessPrevValue;
1740
1738
  const parent = cur.parent;
1741
1739
  if (parent.id) {
1742
- if (trackChannel(state, parent) || !parent.parent) return parent.id + accessPrevValue;
1740
+ trackChannel(state, parent);
1741
+ return parent.id + accessPrevValue;
1743
1742
  }
1744
1743
  if (parent.flushId === state.flushId || parent.scopeId !== void 0) return accessId(state, parent) + accessPrevValue;
1745
1744
  cur = parent;
@@ -1967,9 +1966,9 @@ function _attrs(data, nodeAccessor, scopeId, tagName) {
1967
1966
  }
1968
1967
  return result;
1969
1968
  }
1970
- function _attrs_content(data, nodeAccessor, scopeId, tagName, serializeReason) {
1969
+ function _attrs_content(data, nodeAccessor, scopeId, tagName, markerGuard) {
1971
1970
  _html(`${_attrs(data, nodeAccessor, scopeId, tagName)}>`);
1972
- _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
1971
+ _attr_content(nodeAccessor, scopeId, data?.content, markerGuard);
1973
1972
  }
1974
1973
  function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
1975
1974
  const partial = {};
@@ -1983,9 +1982,9 @@ function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
1983
1982
  });
1984
1983
  return _attrs(partial, nodeAccessor, scopeId, tagName);
1985
1984
  }
1986
- function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, serializeReason) {
1985
+ function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, markerGuard) {
1987
1986
  _html(`${_attrs_partial(data, skip, nodeAccessor, scopeId, tagName)}>`);
1988
- _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
1987
+ _attr_content(nodeAccessor, scopeId, data?.content, markerGuard);
1989
1988
  }
1990
1989
  function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, serializeType) {
1991
1990
  var handlerName = [
@@ -2114,11 +2113,6 @@ const REORDER_RUNTIME_CODE = `((runtime) => {
2114
2113
 
2115
2114
  if (op == "#") {
2116
2115
  (placeholders[id] = placeholder).i++;
2117
- } else if (op == "!") {
2118
- if (runtime.l[id] && placeholders[id]) {
2119
- nextSibling = node.nextSibling;
2120
- onNextSibling = () => placeholders[id].c();
2121
- }
2122
2116
  } else if (node.tagName == "T" && (id = node.getAttribute(runtime.i))) {
2123
2117
  nextSibling = node.nextSibling;
2124
2118
  onNextSibling = () => {
@@ -2130,7 +2124,8 @@ const REORDER_RUNTIME_CODE = `((runtime) => {
2130
2124
  placeholders[id] ||
2131
2125
  (placeholderRoot = placeholders[id] =
2132
2126
  {
2133
- i: runtime.l[id] ? 1 : 2,
2127
+ // The writer streams a reorder only after its markers.
2128
+ i: 1,
2134
2129
  r: id,
2135
2130
  // Resume may still walk markers inside the dropped placeholder, so
2136
2131
  // park it in any detached parent (a bare <t> clone is the cheapest).
@@ -2238,8 +2233,8 @@ function _html(html) {
2238
2233
  function writeScript(script) {
2239
2234
  $chunk.writeScript(script);
2240
2235
  }
2241
- function _script(scopeId, registryId, serializeMarker) {
2242
- if (serializeMarker === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync])) _resume_branch(scopeId);
2236
+ function _script(scopeId, registryId, markerGuard) {
2237
+ if (markerGuard === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync])) _resume_branch(scopeId);
2243
2238
  $chunk.boundary.state.needsMainRuntime = true;
2244
2239
  $chunk.writeEffect(scopeId, registryId);
2245
2240
  }
@@ -2287,8 +2282,8 @@ function _resume_branch(scopeId) {
2287
2282
  const branchId = $chunk.context?.[kBranchId];
2288
2283
  if (branchId !== void 0 && branchId !== scopeId) writeScope(scopeId, { [ClosestBranchId]: branchId });
2289
2284
  }
2290
- function _attr_content(nodeAccessor, scopeId, content, serializeReason) {
2291
- const shouldResume = serializeReason !== 0;
2285
+ function _attr_content(nodeAccessor, scopeId, content, markerGuard) {
2286
+ const shouldResume = markerGuard !== 0;
2292
2287
  const render = normalizeServerRender(content);
2293
2288
  const branchId = _peek_scope_id();
2294
2289
  if (render) {
@@ -2322,47 +2317,47 @@ function writeScopePassive(scopeId, partialScope) {
2322
2317
  passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
2323
2318
  return scope;
2324
2319
  }
2325
- function _show_start(display, mark) {
2320
+ function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
2326
2321
  if (display) {
2327
- if (mark) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
2322
+ if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
2328
2323
  } else $chunk.writeHTML("<t hidden>");
2329
2324
  }
2330
- function _show_end(scopeId, accessor, display, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2325
+ function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2331
2326
  const branchId = _scope_id();
2332
2327
  const wrap = !display;
2333
2328
  if (wrap) $chunk.writeHTML("</t>");
2334
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
2329
+ writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
2335
2330
  }
2336
- function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2331
+ function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2337
2332
  forBranches(by, (each) => each ? forOf(list, (item, index) => {
2338
2333
  const itemKey = forOfBy(by, item, index);
2339
2334
  each(itemKey, itemKey === index, () => cb(item, index));
2340
- }) : forOf(list, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
2335
+ }) : forOf(list, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2341
2336
  }
2342
- function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2337
+ function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2343
2338
  forBranches(by, (each) => each ? forIn(obj, (key, value) => {
2344
2339
  each(forInBy(by, key, value), false, () => cb(key, value));
2345
- }) : forIn(obj, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
2340
+ }) : forIn(obj, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2346
2341
  }
2347
- function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2342
+ function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2348
2343
  forBranches(by, (each) => {
2349
2344
  let index = 0;
2350
2345
  return each ? forTo(to, from, step, (value) => {
2351
2346
  const itemKey = forStepBy(by, value);
2352
2347
  each(itemKey, itemKey === index++, () => cb(value));
2353
2348
  }) : forTo(to, from, step, cb);
2354
- }, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
2349
+ }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2355
2350
  }
2356
- function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2351
+ function _for_until(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2357
2352
  forBranches(by, (each) => {
2358
2353
  let index = 0;
2359
2354
  return each ? forUntil(to, from, step, (value) => {
2360
2355
  const itemKey = forStepBy(by, value);
2361
2356
  each(itemKey, itemKey === index++, () => cb(value));
2362
2357
  }) : forUntil(to, from, step, cb);
2363
- }, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
2358
+ }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2364
2359
  }
2365
- function forBranches(by, iterate, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2360
+ function forBranches(by, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2366
2361
  if (by) {
2367
2362
  const run = iterate;
2368
2363
  const seenKeys = /* @__PURE__ */ new Set();
@@ -2372,14 +2367,14 @@ function forBranches(by, iterate, scopeId, accessor, serializeBranch, serializeM
2372
2367
  else render();
2373
2368
  });
2374
2369
  }
2375
- if (serializeBranch === 0) {
2370
+ if (branchGuard === 0) {
2376
2371
  iterate(0);
2377
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, "");
2372
+ writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
2378
2373
  return;
2379
2374
  }
2380
2375
  const { state } = $chunk.boundary;
2381
- const resumeKeys = serializeMarker !== 0;
2382
- const resumeMarker = resumeKeys && (!parentEndTag || serializeStateful !== 0);
2376
+ const resumeKeys = markerGuard !== 0;
2377
+ const resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag);
2383
2378
  let flushBranchIds = "";
2384
2379
  let loopScopes;
2385
2380
  iterate((itemKey, sameAsIndex, render) => {
@@ -2398,11 +2393,11 @@ function forBranches(by, iterate, scopeId, accessor, serializeBranch, serializeM
2398
2393
  });
2399
2394
  });
2400
2395
  if (loopScopes) writeScope(scopeId, { [BranchScopes + accessor]: loopScopes });
2401
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
2396
+ writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
2402
2397
  }
2403
- function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
2404
- const resumeBranch = serializeBranch !== 0;
2405
- const resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0);
2398
+ function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2399
+ const resumeBranch = branchGuard !== 0;
2400
+ const resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag);
2406
2401
  const branchId = _peek_scope_id();
2407
2402
  const chunk = $chunk;
2408
2403
  const beforeBranch = resumeMarker && resumeBranch && !singleNode ? deferBranchStart(chunk) : void 0;
@@ -2413,7 +2408,7 @@ function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeS
2413
2408
  [ConditionalRenderer + accessor]: branchIndex || void 0,
2414
2409
  [BranchScopes + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
2415
2410
  });
2416
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
2411
+ writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
2417
2412
  }
2418
2413
  function deferBranchStart(chunk) {
2419
2414
  const beforeBranch = chunk.html;
@@ -2423,15 +2418,17 @@ function deferBranchStart(chunk) {
2423
2418
  function applyBranchStart(chunk, beforeBranch, rendered) {
2424
2419
  chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
2425
2420
  }
2426
- function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, branchIds) {
2421
+ function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
2422
+ return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
2423
+ }
2424
+ function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
2427
2425
  const endTag = parentEndTag || "";
2428
- if (serializeMarker !== 0) {
2429
- if (!parentEndTag || serializeStateful !== 0) {
2430
- const { state } = $chunk.boundary;
2431
- const mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
2432
- $chunk.writeHTML(mark + endTag);
2433
- } else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
2434
- } else $chunk.writeHTML(endTag);
2426
+ if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) {
2427
+ const { state } = $chunk.boundary;
2428
+ const mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
2429
+ $chunk.writeHTML(mark + endTag);
2430
+ } else if (markerGuard !== 0) $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
2431
+ else $chunk.writeHTML(endTag);
2435
2432
  }
2436
2433
  let writeScope = (scopeId, partialScope) => {
2437
2434
  const { state } = $chunk.boundary;
@@ -2463,11 +2460,11 @@ function scopeWithId(state, scopeId) {
2463
2460
  if (!scope) scopes.set(scopeId, scope = { [K_SCOPE_ID]: scopeId });
2464
2461
  return scope;
2465
2462
  }
2466
- function _subscribe(subscribers, scope, resumeId, serializeMarker) {
2463
+ function _subscribe(subscribers, scope, resumeId, markerGuard) {
2467
2464
  if (subscribers) {
2468
2465
  const { serializer } = $chunk.boundary.state;
2469
2466
  if (!$chunk.serializeState.readyId && !serializer.written(subscribers)) subscribers.add(scope);
2470
- else if (resumeId) _script(scope[K_SCOPE_ID], resumeId, serializeMarker);
2467
+ else if (resumeId) _script(scope[K_SCOPE_ID], resumeId, markerGuard);
2471
2468
  else serializer.writeCall(scope, subscribers, "add", $chunk.serializeState);
2472
2469
  }
2473
2470
  return scope;
@@ -2476,19 +2473,19 @@ const CLIENT_ALL = 715827883;
2476
2473
  function maskGroup(mask, group) {
2477
2474
  return mask === 715827883 ? 1 : typeof mask === "number" ? group < 15 ? mask >>> 1 + 2 * group & 3 : 0 : mask[group] ?? 0;
2478
2475
  }
2479
- function _set_serialize_reason(reason) {
2480
- $chunk.boundary.state.serializeReason = reason;
2476
+ function _set_scope_reason(reason) {
2477
+ $chunk.boundary.state.scopeReason = reason;
2481
2478
  }
2482
2479
  function _scope_reason() {
2483
- const reason = $chunk.boundary.state.serializeReason;
2484
- $chunk.boundary.state.serializeReason = void 0;
2480
+ const reason = $chunk.boundary.state.scopeReason;
2481
+ $chunk.boundary.state.scopeReason = void 0;
2485
2482
  return reason;
2486
2483
  }
2487
- function _serialize_if(condition, key) {
2484
+ function _write_if(condition, key) {
2488
2485
  return condition && maskGroup(condition, key) ? 1 : void 0;
2489
2486
  }
2490
- function _serialize_guard(condition, key) {
2491
- return _serialize_if(condition, key) || 0;
2487
+ function _write_guard(condition, key) {
2488
+ return _write_if(condition, key) || 0;
2492
2489
  }
2493
2490
  function writeWaitReady(readyId, renderer, input) {
2494
2491
  const chunk = $chunk;
@@ -2501,6 +2498,7 @@ function writeWaitReady(readyId, renderer, input) {
2501
2498
  flushScopes: false
2502
2499
  });
2503
2500
  const bodyEnd = body.render(renderer, input);
2501
+ if (boundary.aborted) throw boundary.reason;
2504
2502
  if (body === bodyEnd) {
2505
2503
  chunk.writeHTML(body.html);
2506
2504
  body.deferOwnReady();
@@ -2510,8 +2508,8 @@ function writeWaitReady(readyId, renderer, input) {
2510
2508
  chunk.next = body;
2511
2509
  }
2512
2510
  }
2513
- function _await(scopeId, accessor, promise, content, serializeMarker) {
2514
- const resumeMarker = serializeMarker !== 0;
2511
+ function _await(scopeId, accessor, promise, content, markerGuard) {
2512
+ const resumeMarker = markerGuard !== 0;
2515
2513
  if (!isPromise(promise)) {
2516
2514
  if (resumeMarker) {
2517
2515
  const branchId = _peek_scope_id();
@@ -2531,7 +2529,8 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
2531
2529
  promise.then((value) => {
2532
2530
  if (chunk.async) {
2533
2531
  chunk.async = false;
2534
- if (!boundary.signal.aborted) {
2532
+ if (!boundary.aborted) {
2533
+ const { state } = boundary;
2535
2534
  chunk.render(() => {
2536
2535
  if (resumeMarker) {
2537
2536
  const branchId = _peek_scope_id();
@@ -2547,6 +2546,7 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
2547
2546
  async.end = $chunk;
2548
2547
  }
2549
2548
  });
2549
+ if (!chunk.async && boundary.pendingReorders?.delete(chunk)) state.reorder(chunk);
2550
2550
  boundary.endAsync();
2551
2551
  }
2552
2552
  }
@@ -2593,12 +2593,12 @@ function tryBoundary(content, catchContent, branchId, renderers) {
2593
2593
  const chunk = $chunk;
2594
2594
  const { boundary } = chunk;
2595
2595
  const { state } = boundary;
2596
- const catchBoundary = new Boundary(state, boundary.signal, boundary);
2596
+ const catchBoundary = new Boundary(state, void 0, boundary);
2597
2597
  const body = chunk.fork(catchBoundary, null);
2598
2598
  const bodyEnd = body.render(() => withBranchId(branchId, content));
2599
- if (catchBoundary.signal.aborted) {
2600
- if (catchContent) catchContent(catchBoundary.signal.reason);
2601
- else boundary.abort(catchBoundary.signal.reason);
2599
+ if (catchBoundary.aborted) {
2600
+ if (!catchContent) throw catchBoundary.reason;
2601
+ catchContent(catchBoundary.reason);
2602
2602
  return true;
2603
2603
  }
2604
2604
  if (body === bodyEnd) {
@@ -2610,44 +2610,48 @@ function tryBoundary(content, catchContent, branchId, renderers) {
2610
2610
  chunk.next = body;
2611
2611
  boundary.startAsync();
2612
2612
  const reorderId = catchContent ? state.nextReorderId() : "";
2613
- const endMarker = reorderId && state.mark("!", reorderId);
2614
2613
  if (reorderId) {
2615
- chunk.writeHTML(state.mark("!^", reorderId));
2616
- bodyEnd.writeHTML(endMarker);
2614
+ chunk.catchRange = {
2615
+ id: reorderId,
2616
+ end: bodyEnd
2617
+ };
2617
2618
  captureContext(chunk);
2618
2619
  }
2619
2620
  catchBoundary.onNext = () => {
2620
- if (boundary.signal.aborted) return;
2621
- if (catchBoundary.signal.aborted) {
2621
+ if (boundary.aborted) return;
2622
+ if (catchBoundary.aborted) {
2622
2623
  if (!reorderId) {
2623
- boundary.abort(catchBoundary.signal.reason);
2624
+ boundary.abort(catchBoundary.reason);
2624
2625
  return;
2625
2626
  }
2626
- if (!bodyEnd.consumed) {
2627
- let cur = body;
2628
- let writeMarker = true;
2629
- do {
2630
- const next = cur.next;
2631
- if (cur.boundary !== catchBoundary) cur.boundary.abort(catchBoundary.signal.reason);
2632
- if (writeMarker && !cur.consumed) {
2633
- writeMarker = false;
2634
- cur.async = false;
2635
- cur.next = bodyNext;
2636
- cur.needsWalk = true;
2637
- cur.html = endMarker;
2638
- cur.scripts = cur.effects = cur.lastEffect = "";
2639
- cur.placeholder = cur.reorderId = cur.deferredReady = null;
2640
- }
2641
- cur = next;
2642
- } while (cur !== bodyNext);
2643
- }
2627
+ const streamed = !chunk.catchRange;
2644
2628
  const catchChunk = chunk.fork(boundary, null);
2645
- catchChunk.reorderId = reorderId;
2646
- catchChunk.render(catchContent, catchBoundary.signal.reason);
2647
- state.reorder(catchChunk);
2629
+ chunk.catchRange = null;
2630
+ const inOrder = catchChunk === catchChunk.render(catchContent, catchBoundary.reason);
2631
+ if (boundary.aborted) return;
2632
+ if (bodyEnd.consumed) {
2633
+ catchChunk.reorderId = reorderId;
2634
+ state.reorder(catchChunk);
2635
+ } else {
2636
+ let reorder = null;
2637
+ if (!inOrder) reorder = catchChunk;
2638
+ else if (streamed) reorder = chunk.fork(boundary, null);
2639
+ if (reorder) reorder.reorderId = reorderId;
2640
+ const endMarker = state.mark("!", reorderId);
2641
+ let cut = body;
2642
+ while (cut.consumed) cut = cut.next;
2643
+ cut.async = false;
2644
+ cut.next = inOrder ? catchChunk : bodyNext;
2645
+ cut.html = streamed ? endMarker : inOrder ? "" : state.mark("!^", reorderId) + endMarker;
2646
+ cut.scripts = cut.effects = cut.lastEffect = "";
2647
+ cut.placeholder = cut.reorderId = cut.catchRange = null;
2648
+ cut.deferredReorder = reorder;
2649
+ if (inOrder) catchChunk.next = bodyNext;
2650
+ }
2648
2651
  boundary.endAsync();
2649
2652
  } else if (!catchBoundary.count) {
2650
2653
  if (renderersAtSettle && catchBoundary.resumeWrites) bodyEnd.render(renderers);
2654
+ chunk.catchRange = null;
2651
2655
  boundary.endAsync();
2652
2656
  } else boundary.onNext();
2653
2657
  };
@@ -2692,7 +2696,7 @@ var State = class {
2692
2696
  flushScopes = false;
2693
2697
  writeScopes = {};
2694
2698
  readyIds = null;
2695
- serializeReason;
2699
+ scopeReason;
2696
2700
  $global;
2697
2701
  constructor($global) {
2698
2702
  this.$global = $global;
@@ -2753,38 +2757,53 @@ var State = class {
2753
2757
  return "<!--" + this.commentPrefix + code + str + "-->";
2754
2758
  }
2755
2759
  };
2756
- var Boundary = class extends AbortController {
2760
+ var Boundary = class {
2757
2761
  onNext = NOOP$2;
2758
2762
  count = 0;
2759
2763
  resumeWrites = 0;
2760
2764
  state;
2761
2765
  parent;
2766
+ aborted = false;
2767
+ reason;
2768
+ pendingReorders;
2769
+ children;
2762
2770
  constructor(state, signal, parent) {
2763
- super();
2764
2771
  this.state = state;
2765
2772
  this.parent = parent;
2766
- this.signal.addEventListener("abort", () => {
2767
- this.count = 0;
2768
- this.state = new State(this.state.$global);
2769
- this.onNext();
2770
- });
2771
- if (signal) {
2773
+ if (parent) {
2774
+ if (parent.aborted) this.abort(parent.reason);
2775
+ else (parent.children ||= []).push(this);
2776
+ } else if (signal) {
2772
2777
  if (signal.aborted) this.abort(signal.reason);
2773
2778
  else signal.addEventListener("abort", this);
2774
2779
  }
2775
2780
  }
2781
+ abort(reason) {
2782
+ if (this.aborted) return;
2783
+ const { state } = this;
2784
+ this.aborted = true;
2785
+ this.reason = reason;
2786
+ if (this.pendingReorders) {
2787
+ for (const reorder of this.pendingReorders) state.reorder(reorder);
2788
+ this.pendingReorders = void 0;
2789
+ }
2790
+ this.count = 0;
2791
+ this.state = new State(state.$global);
2792
+ if (this.children) for (const child of this.children) child.abort(reason);
2793
+ this.onNext();
2794
+ }
2776
2795
  handleEvent(event) {
2777
2796
  this.abort(event.target.reason);
2778
2797
  }
2779
2798
  flush() {
2780
- if (!this.signal.aborted) flushSerializer(this, this.state);
2781
- return this.count ? 1 : this.signal.aborted ? 2 : 0;
2799
+ if (!this.aborted) flushSerializer(this, this.state);
2800
+ return this.count ? 1 : this.aborted ? 2 : 0;
2782
2801
  }
2783
2802
  startAsync() {
2784
- if (!this.signal.aborted) this.count++;
2803
+ if (!this.aborted) this.count++;
2785
2804
  }
2786
2805
  endAsync() {
2787
- if (!this.signal.aborted) {
2806
+ if (!this.aborted) {
2788
2807
  if (!this.count) throw new Error("A boundary ended more async work than it started.");
2789
2808
  this.count--;
2790
2809
  this.onNext();
@@ -2798,9 +2817,10 @@ var Chunk = class Chunk {
2798
2817
  lastEffect = "";
2799
2818
  async = false;
2800
2819
  consumed = false;
2801
- needsWalk = false;
2802
2820
  reorderId = null;
2803
2821
  deferredReady = null;
2822
+ deferredReorder = null;
2823
+ catchRange = null;
2804
2824
  placeholder = null;
2805
2825
  boundary;
2806
2826
  next;
@@ -2831,7 +2851,6 @@ var Chunk = class Chunk {
2831
2851
  }
2832
2852
  append(chunk) {
2833
2853
  this.html += chunk.html;
2834
- this.needsWalk ||= chunk.needsWalk;
2835
2854
  this.effects = concatEffects(this.effects, chunk.effects);
2836
2855
  this.scripts = concatScripts(this.scripts, chunk.scripts);
2837
2856
  this.lastEffect = chunk.lastEffect || this.lastEffect;
@@ -2851,46 +2870,88 @@ var Chunk = class Chunk {
2851
2870
  this.deferredReady = concat(deferred, this.deferredReady);
2852
2871
  }
2853
2872
  }
2854
- flushPlaceholder() {
2855
- const { placeholder } = this;
2856
- if (placeholder) {
2857
- this.placeholder = null;
2858
- const body = placeholder.body.consume();
2859
- if (body.async) {
2860
- const { state } = this.boundary;
2861
- const { branchId, scopeId, placeholderBranchId } = placeholder;
2862
- const reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
2863
- this.writeHTML(state.mark("!^", reorderId));
2864
- const { effects } = this;
2865
- const beforeBranch = deferBranchStart(this);
2866
- if (this.render(() => withBranchId(placeholderBranchId, placeholder.render)) !== this) this.boundary.abort(/* @__PURE__ */ new Error("An @placeholder cannot contain async content."));
2867
- if (this.boundary.signal.aborted) return;
2868
- const stateful = this.effects !== effects;
2869
- applyBranchStart(this, beforeBranch, stateful);
2870
- if (stateful) {
2871
- this.render(() => writeScope(branchId, { [PlaceholderBranch]: scopeWithId(state, placeholderBranchId) }));
2872
- this.writeHTML(state.mark("]", scopeId + " " + (PlaceholderBranch + branchId) + " " + placeholderBranchId));
2873
- body.writeEffect(branchId, PLACEHOLDER_DISMISS_REGISTER_ID);
2873
+ renderPlaceholders(boundary) {
2874
+ const { state } = boundary;
2875
+ restart: for (;;) {
2876
+ let reorders = null;
2877
+ for (let cur = this; cur.next && !cur.async; cur = cur.next) {
2878
+ if (cur.renderPlaceholder(state)) {
2879
+ if (boundary.aborted) return;
2880
+ continue restart;
2881
+ }
2882
+ if (cur.deferredReorder) (reorders ||= []).push(cur.deferredReorder);
2883
+ }
2884
+ if (state.writeReorders) {
2885
+ for (const reorder of state.writeReorders) if ((reorders = renderReorderPlaceholders(reorder, reorders)) === false) {
2886
+ if (boundary.aborted) return;
2887
+ continue restart;
2874
2888
  }
2875
- this.writeHTML(state.mark("!", reorderId));
2876
- state.reorder(body);
2877
- } else {
2878
- body.next = this.next;
2879
- this.next = body;
2880
2889
  }
2890
+ for (let i = 0; reorders && i < reorders.length; i++) if ((reorders = renderReorderPlaceholders(reorders[i], reorders)) === false) {
2891
+ if (boundary.aborted) return;
2892
+ continue restart;
2893
+ }
2894
+ return;
2881
2895
  }
2882
2896
  }
2883
- consume() {
2897
+ renderPlaceholder(state) {
2898
+ const { placeholder } = this;
2899
+ if (!placeholder) return false;
2900
+ this.placeholder = null;
2901
+ if (this.boundary.aborted) return false;
2902
+ const { body } = placeholder;
2903
+ let end = body;
2904
+ while (end.next && !end.async) end = end.next;
2905
+ if (!end.async) {
2906
+ end.next = this.next;
2907
+ this.next = body;
2908
+ return false;
2909
+ }
2910
+ const { branchId, scopeId, placeholderBranchId } = placeholder;
2911
+ const reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
2912
+ this.writeHTML(state.mark("!^", reorderId));
2913
+ const { effects } = this;
2914
+ const beforeBranch = deferBranchStart(this);
2915
+ if (this.render(() => withBranchId(placeholderBranchId, placeholder.render)) !== this) this.boundary.abort(/* @__PURE__ */ new Error("An @placeholder cannot contain async content."));
2916
+ if (this.boundary.aborted) return true;
2917
+ const stateful = this.effects !== effects;
2918
+ applyBranchStart(this, beforeBranch, stateful);
2919
+ if (stateful) {
2920
+ this.render(() => writeScope(branchId, { [PlaceholderBranch]: scopeWithId(state, placeholderBranchId) }));
2921
+ this.writeHTML(state.mark("]", scopeId + " " + (PlaceholderBranch + branchId) + " " + placeholderBranchId));
2922
+ end.writeEffect(branchId, PLACEHOLDER_DISMISS_REGISTER_ID);
2923
+ }
2924
+ this.writeHTML(state.mark("!", reorderId));
2925
+ this.deferredReorder = body;
2926
+ return false;
2927
+ }
2928
+ markCatchRange() {
2929
+ const { catchRange } = this;
2930
+ if (catchRange) {
2931
+ const { state } = this.boundary;
2932
+ this.catchRange = null;
2933
+ this.writeHTML(state.mark("!^", catchRange.id));
2934
+ catchRange.end.writeHTML(state.mark("!", catchRange.id));
2935
+ }
2936
+ }
2937
+ queueDeferredReorder() {
2938
+ const { deferredReorder } = this;
2939
+ if (deferredReorder) {
2940
+ this.deferredReorder = null;
2941
+ deferredReorder.boundary.state.reorder(deferredReorder);
2942
+ }
2943
+ }
2944
+ consume(boundary) {
2945
+ this.renderPlaceholders(boundary);
2884
2946
  let cur = this;
2885
2947
  let html = "";
2886
2948
  let effects = "";
2887
2949
  let scripts = "";
2888
2950
  let lastEffect = "";
2889
- let needsWalk = false;
2890
2951
  let deferredReady;
2891
2952
  while (cur.next && !cur.async) {
2892
- cur.flushPlaceholder();
2893
- needsWalk ||= cur.needsWalk;
2953
+ cur.markCatchRange();
2954
+ cur.queueDeferredReorder();
2894
2955
  html += cur.html;
2895
2956
  if (cur.serializeState.readyId) deferredReady = push(deferredReady, cur);
2896
2957
  else {
@@ -2904,7 +2965,6 @@ var Chunk = class Chunk {
2904
2965
  }
2905
2966
  cur.deferOwnReady();
2906
2967
  cur.deferredReady = concat(deferredReady, cur.deferredReady);
2907
- cur.needsWalk ||= needsWalk;
2908
2968
  cur.html = html + cur.html;
2909
2969
  cur.effects = concatEffects(effects, cur.effects);
2910
2970
  cur.scripts = concatScripts(scripts, cur.scripts);
@@ -2928,10 +2988,12 @@ var Chunk = class Chunk {
2928
2988
  const { serializeState } = this;
2929
2989
  const { readyId } = serializeState;
2930
2990
  let scripts = "";
2931
- forEach(this.takeDeferredReady(), (chunk) => {
2991
+ const held = this.takeDeferredReady();
2992
+ if (held) for (const chunk of Array.isArray(held) ? held : [held]) {
2993
+ if (chunk.boundary.aborted) continue;
2932
2994
  scripts = concatScripts(scripts, chunk.flushReadyScripts(boundary, reservations, holdEffects));
2933
2995
  if (chunk.effects || chunk.deferredReady) this.deferredReady = push(this.deferredReady, chunk);
2934
- });
2996
+ }
2935
2997
  if (readyId && !this.async) {
2936
2998
  const { state } = boundary;
2937
2999
  flushSerializer(boundary, serializeState);
@@ -2960,7 +3022,7 @@ var Chunk = class Chunk {
2960
3022
  let needsWalk = state.walkOnNextFlush;
2961
3023
  if (needsWalk) state.walkOnNextFlush = false;
2962
3024
  let readyResumeScripts = this.flushReadyScripts(boundary, void 0, this.async);
2963
- for (let channel; !boundary.signal.aborted && (channel = state.serializer.pendingReadyChannel());) {
3025
+ for (let channel; !boundary.aborted && (channel = state.serializer.pendingReadyChannel());) {
2964
3026
  const resumes = state.serializer.stringifyScopes([], boundary, channel);
2965
3027
  const deps = state.serializer.takeChannelDeps();
2966
3028
  state.needsMainRuntime = true;
@@ -2981,17 +3043,7 @@ var Chunk = class Chunk {
2981
3043
  let reordered = "";
2982
3044
  let needsResumeArray = false;
2983
3045
  if (state.writeReorders) {
2984
- let carried = null;
2985
3046
  for (const reorderedChunk of state.writeReorders) {
2986
- if (reorderedChunk.async && reorderedChunk.consumed) {
2987
- let aborted = reorderedChunk.boundary;
2988
- while (aborted && !aborted.signal.aborted) aborted = aborted.parent;
2989
- if (!aborted) {
2990
- (carried ||= []).push(reorderedChunk);
2991
- continue;
2992
- }
2993
- reorderedChunk.async = false;
2994
- }
2995
3047
  needsWalk = true;
2996
3048
  if (!state.hasReorderRuntime) {
2997
3049
  state.hasReorderRuntime = true;
@@ -3002,10 +3054,11 @@ var Chunk = class Chunk {
3002
3054
  let reorderHTML = "";
3003
3055
  let reorderEffects = "";
3004
3056
  let reorderScripts = "";
3005
- let cur = reorderedChunk;
3057
+ let cur = reorderedChunk.boundary.aborted ? null : reorderedChunk;
3006
3058
  reorderedChunk.reorderId = null;
3007
- for (;;) {
3008
- cur.flushPlaceholder();
3059
+ while (cur) {
3060
+ cur.markCatchRange();
3061
+ cur.queueDeferredReorder();
3009
3062
  cur.deferOwnReady();
3010
3063
  const { next } = cur;
3011
3064
  const readyResumeScripts = cur.flushReadyScripts(boundary, readyReservations, this.async);
@@ -3016,12 +3069,11 @@ var Chunk = class Chunk {
3016
3069
  reorderScripts = concatScripts(reorderScripts, concatScripts(readyResumeScripts, cur.scripts));
3017
3070
  if (cur.async) {
3018
3071
  reorderHTML += state.mark("#", cur.reorderId = state.nextReorderId());
3019
- state.reorder(cur);
3072
+ (cur.boundary.pendingReorders ||= /* @__PURE__ */ new Set()).add(cur);
3020
3073
  cur.html = cur.effects = cur.scripts = cur.lastEffect = "";
3021
3074
  cur.next = null;
3022
3075
  }
3023
- if (next) cur = next;
3024
- else break;
3076
+ cur = next;
3025
3077
  }
3026
3078
  if (reorderEffects) {
3027
3079
  if (this.async) {
@@ -3036,7 +3088,7 @@ var Chunk = class Chunk {
3036
3088
  reordered = concatScripts(reordered, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}");
3037
3089
  html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
3038
3090
  }
3039
- state.writeReorders = carried;
3091
+ state.writeReorders = null;
3040
3092
  }
3041
3093
  flushSerializer(boundary, state);
3042
3094
  if (state.resumes || needsResumeArray && !state.hasWrittenResume) scripts = concatScripts(scripts, state.resumeScript(state.resumes));
@@ -3050,16 +3102,19 @@ var Chunk = class Chunk {
3050
3102
  }
3051
3103
  flushHTML(boundary) {
3052
3104
  const { state } = boundary;
3053
- if (this.needsWalk) {
3054
- this.needsWalk = false;
3055
- state.walkOnNextFlush = true;
3056
- }
3057
3105
  this.flushScript(boundary);
3058
3106
  const { html, scripts } = this;
3059
3107
  this.html = this.scripts = "";
3060
3108
  return state.flushChunk(html, scripts, boundary.count);
3061
3109
  }
3062
3110
  };
3111
+ function renderReorderPlaceholders(reorder, reorders) {
3112
+ if (!reorder.boundary.aborted) for (let cur = reorder; cur; cur = cur.next) {
3113
+ if (cur.renderPlaceholder(reorder.boundary.state)) return false;
3114
+ if (cur.deferredReorder) (reorders ||= []).push(cur.deferredReorder);
3115
+ }
3116
+ return reorders;
3117
+ }
3063
3118
  function flushSerializer(boundary, serializeState) {
3064
3119
  const { state } = boundary;
3065
3120
  const { serializer } = state;
@@ -3221,8 +3276,8 @@ function _escape_comment(val) {
3221
3276
  //#endregion
3222
3277
  //#region src/html/dynamic-tag.ts
3223
3278
  const voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/;
3224
- let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, serializeReason) => {
3225
- const shouldResume = serializeReason !== 0;
3279
+ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, markerGuard) => {
3280
+ const shouldResume = markerGuard !== 0;
3226
3281
  const renderer = normalizeDynamicRenderer(tag);
3227
3282
  const state = getState();
3228
3283
  const branchId = _peek_scope_id();
@@ -3242,8 +3297,8 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
3242
3297
  _html(_attrs_textarea_value(branchId, `#${renderer.toLowerCase()}/0`, input));
3243
3298
  } else {
3244
3299
  if (renderContent && typeof renderContent !== "function") throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
3245
- if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, `#${renderer.toLowerCase()}/0`, input.value, input.valueChange, renderContent ? () => _dynamic_tag(branchId, `#${renderer.toLowerCase()}/0`, renderContent, void 0, 0, void 0, serializeReason) : void 0, 1);
3246
- else if (renderContent) _dynamic_tag(branchId, `#${renderer.toLowerCase()}/0`, renderContent, void 0, 0, void 0, serializeReason);
3300
+ if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, `#${renderer.toLowerCase()}/0`, input.value, input.valueChange, renderContent ? () => _dynamic_tag(branchId, `#${renderer.toLowerCase()}/0`, renderContent, void 0, 0, void 0, markerGuard) : void 0, 1);
3301
+ else if (renderContent) _dynamic_tag(branchId, `#${renderer.toLowerCase()}/0`, renderContent, void 0, 0, void 0, markerGuard);
3247
3302
  }
3248
3303
  _html(`</${renderer}>`);
3249
3304
  } else if (content) throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
@@ -3262,13 +3317,13 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
3262
3317
  const beforeBranch = shouldResume ? deferBranchStart(chunk) : void 0;
3263
3318
  const render = () => {
3264
3319
  if (renderer) try {
3265
- _set_serialize_reason(shouldResume && inputOrArgs !== void 0 ? CLIENT_ALL : 0);
3320
+ _set_scope_reason(shouldResume && inputOrArgs !== void 0 ? CLIENT_ALL : 0);
3266
3321
  return inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
3267
3322
  ...inputOrArgs,
3268
3323
  content
3269
3324
  } : inputOrArgs);
3270
3325
  } finally {
3271
- _set_serialize_reason(void 0);
3326
+ _set_scope_reason(void 0);
3272
3327
  }
3273
3328
  else if (content) return content();
3274
3329
  };
@@ -3484,13 +3539,13 @@ var ServerRendered = class {
3484
3539
  switch (!boundary.count && boundary.flush()) {
3485
3540
  case 2:
3486
3541
  settle(boundary);
3487
- reject(boundary.signal.reason);
3542
+ reject(boundary.reason);
3488
3543
  break;
3489
3544
  case 0:
3490
- head = head.consume();
3491
- if (boundary.signal.aborted) break;
3545
+ head = head.consume(boundary);
3546
+ if (boundary.aborted) break;
3492
3547
  html += head.flushHTML(boundary);
3493
- if (!(boundary.count || boundary.signal.aborted)) {
3548
+ if (!(boundary.count || boundary.aborted)) {
3494
3549
  settle(boundary);
3495
3550
  resolve(html);
3496
3551
  }
@@ -3521,14 +3576,14 @@ var ServerRendered = class {
3521
3576
  if (status === 2) {
3522
3577
  if (!tick) offTick(onNext);
3523
3578
  settle(boundary);
3524
- onAbort(boundary.signal.reason);
3579
+ onAbort(boundary.reason);
3525
3580
  return;
3526
3581
  }
3527
3582
  if (write || status === 0) {
3528
- head = head.consume();
3529
- if (boundary.signal.aborted) continue;
3583
+ head = head.consume(boundary);
3584
+ if (boundary.aborted) continue;
3530
3585
  const html = head.flushHTML(boundary);
3531
- if (boundary.signal.aborted) continue;
3586
+ if (boundary.aborted) continue;
3532
3587
  if (html) onWrite(html);
3533
3588
  if (!boundary.count) {
3534
3589
  if (!tick) offTick(onNext);
@@ -3552,10 +3607,10 @@ var ServerRendered = class {
3552
3607
  this.#head = null;
3553
3608
  if (!head) throw new Error(CONSUMED_RESULT_MESSAGE);
3554
3609
  const { boundary } = head;
3555
- const html = boundary.flush() === 0 ? head.consume().flushHTML(boundary) : "";
3610
+ const html = boundary.flush() === 0 ? head.consume(boundary).flushHTML(boundary) : "";
3556
3611
  if (boundary.count) boundary.abort(/* @__PURE__ */ new Error("Cannot consume asynchronous render with 'toString'"));
3557
3612
  settle(boundary);
3558
- if (boundary.signal.aborted) throw boundary.signal.reason;
3613
+ if (boundary.aborted) throw boundary.reason;
3559
3614
  return html;
3560
3615
  }
3561
3616
  };
@@ -3729,7 +3784,7 @@ const compat = {
3729
3784
  chunk ||= this.createChunk($global);
3730
3785
  const { boundary } = chunk;
3731
3786
  const scripts = boundary.flush() === 0 ? chunk.flushScript(boundary).scripts : "";
3732
- if (boundary.signal.aborted) throw boundary.signal.reason;
3787
+ if (boundary.aborted) throw boundary.reason;
3733
3788
  if (boundary.count) throw new Error("Cannot serialize promise across tags/class compat layer.");
3734
3789
  return scripts;
3735
3790
  },
@@ -3758,11 +3813,11 @@ const compat = {
3758
3813
  writeScope(scopeId, { m5c: component.id });
3759
3814
  _script(scopeId, SET_SCOPE_REGISTER_ID);
3760
3815
  }
3761
- _set_serialize_reason(willRerender ? CLIENT_ALL : 0);
3816
+ _set_scope_reason(willRerender ? CLIENT_ALL : 0);
3762
3817
  try {
3763
3818
  renderer(normalizedInput);
3764
3819
  } finally {
3765
- _set_serialize_reason(void 0);
3820
+ _set_scope_reason(void 0);
3766
3821
  }
3767
3822
  const asyncOut = classAPIOut.beginAsync({
3768
3823
  last: true,
@@ -3770,12 +3825,12 @@ const compat = {
3770
3825
  });
3771
3826
  classAPIOut.onLast((next) => {
3772
3827
  (boundary.onNext = () => {
3773
- if (boundary.signal.aborted) {
3774
- asyncOut.error(boundary.signal.reason);
3828
+ if (boundary.aborted) {
3829
+ asyncOut.error(boundary.reason);
3775
3830
  boundary.onNext = NOOP;
3776
3831
  } else if (!boundary.count) {
3777
3832
  boundary.onNext = NOOP;
3778
- head = head.consume();
3833
+ head = head.consume(boundary);
3779
3834
  asyncOut.write(head.html);
3780
3835
  asyncOut.script(head.scripts);
3781
3836
  asyncOut.end();
@@ -3820,4 +3875,4 @@ function drainClassFunctions($global, writeScope) {
3820
3875
  }
3821
3876
  function NOOP() {}
3822
3877
  //#endregion
3823
- export { $global, _assert_hoist, _attr, _attr_and, _attr_class, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_input_checked, _attr_input_checkedValue, _attr_input_value, _attr_nonce, _attr_nullish, _attr_option_value, _attr_or, _attr_select_value, _attr_style, _attr_textarea_value, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_select_value, _attrs_textarea_value, _await, _content, _content_resume, _dynamic_tag, _el, _el_read_error, _el_resume, _escape, _escape_comment, _escape_script, _escape_style, _escape_style_value, _existing_scope, _flush_head, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_read_error, _html, _html_resume, _id, _if, _peek_scope_id, _resume, _resume_branch, _resume_locals, writeScope as _scope, _scope_id, _scope_reason, _scope_with_id, _script, _serialize_guard, _serialize_if, _set_serialize_reason, _show_end, _show_start, _style_html, _subscribe, _template, _text_resume, _textarea_value, _to_text, _trailers, _try, _unescaped, _var, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, withLoadAssets, withPageAssets };
3878
+ export { $global, _assert_hoist, _attr, _attr_and, _attr_class, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_input_checked, _attr_input_checkedValue, _attr_input_value, _attr_nonce, _attr_nullish, _attr_option_value, _attr_or, _attr_select_value, _attr_style, _attr_textarea_value, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_select_value, _attrs_textarea_value, _await, _content, _content_resume, _dynamic_tag, _el, _el_read_error, _el_resume, _escape, _escape_comment, _escape_script, _escape_style, _escape_style_value, _existing_scope, _flush_head, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_read_error, _html, _html_resume, _id, _if, _peek_scope_id, _resume, _resume_branch, _resume_locals, writeScope as _scope, _scope_id, _scope_reason, _scope_with_id, _script, _set_scope_reason, _show_end, _show_start, _style_html, _subscribe, _template, _text_resume, _textarea_value, _to_text, _trailers, _try, _unescaped, _var, _write_guard, _write_if, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, withLoadAssets, withPageAssets };