marko 6.0.0-next.3.69 → 6.0.0-next.3.71

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.
package/dist/debug/dom.js CHANGED
@@ -1628,12 +1628,9 @@ function awaitTag(nodeAccessor, renderer) {
1628
1628
  const referenceNode = scope[nodeAccessor];
1629
1629
  const namespaceNode = (awaitBranch?.___startNode ?? referenceNode).parentNode;
1630
1630
  const thisPromise = scope[promiseAccessor] = promise.then((data2) => {
1631
- if (scope.___closestBranch?.___destroyed || scope[promiseAccessor] !== thisPromise) {
1632
- return;
1633
- }
1634
- scope[promiseAccessor] = void 0;
1635
- runEffects(
1636
- prepareEffects(() => {
1631
+ if (thisPromise === scope[promiseAccessor] && !scope.___closestBranch?.___destroyed) {
1632
+ scope[promiseAccessor] = 0;
1633
+ renderImmediate(() => {
1637
1634
  if (tryWithPlaceholder) {
1638
1635
  placeholderShown.add(pendingEffects);
1639
1636
  }
@@ -1651,12 +1648,10 @@ function awaitTag(nodeAccessor, renderer) {
1651
1648
  referenceNode.remove();
1652
1649
  }
1653
1650
  renderer.___params?.(awaitBranch, [data2]);
1654
- })
1655
- );
1656
- if (tryWithPlaceholder) {
1657
- if (!--tryWithPlaceholder.___pendingAsyncCount) {
1651
+ });
1652
+ if (tryWithPlaceholder && !--tryWithPlaceholder.___pendingAsyncCount) {
1658
1653
  const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1659
- tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = void 0;
1654
+ tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = 0;
1660
1655
  if (placeholderBranch) {
1661
1656
  insertBranchBefore(
1662
1657
  tryWithPlaceholder,
@@ -1670,29 +1665,31 @@ function awaitTag(nodeAccessor, renderer) {
1670
1665
  }
1671
1666
  }
1672
1667
  }
1673
- }).catch((error) => {
1674
- renderCatch(scope, error, true);
1675
- });
1668
+ }).catch(
1669
+ (error) => renderImmediate(() => renderCatch(scope, error, true))
1670
+ );
1676
1671
  if (tryWithPlaceholder) {
1677
1672
  placeholderShown.add(pendingEffects);
1678
1673
  if (!tryWithPlaceholder.___pendingAsyncCount) {
1679
1674
  tryWithPlaceholder.___pendingAsyncCount = 0;
1680
- requestAnimationFrame(() => {
1681
- if (tryWithPlaceholder.___pendingAsyncCount && !tryWithPlaceholder.___destroyed) {
1682
- const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1683
- scope.$global,
1684
- tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1685
- tryWithPlaceholder._,
1686
- tryWithPlaceholder.___startNode.parentNode
1687
- );
1688
- insertBranchBefore(
1689
- placeholderBranch,
1690
- tryWithPlaceholder.___startNode.parentNode,
1691
- tryWithPlaceholder.___startNode
1692
- );
1693
- tempDetatchBranch(tryWithPlaceholder);
1694
- }
1695
- });
1675
+ requestAnimationFrame(
1676
+ () => renderImmediate(() => {
1677
+ if (tryWithPlaceholder.___pendingAsyncCount && !tryWithPlaceholder.___destroyed) {
1678
+ const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1679
+ scope.$global,
1680
+ tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1681
+ tryWithPlaceholder._,
1682
+ tryWithPlaceholder.___startNode.parentNode
1683
+ );
1684
+ insertBranchBefore(
1685
+ placeholderBranch,
1686
+ tryWithPlaceholder.___startNode.parentNode,
1687
+ tryWithPlaceholder.___startNode
1688
+ );
1689
+ tempDetatchBranch(tryWithPlaceholder);
1690
+ }
1691
+ })
1692
+ );
1696
1693
  }
1697
1694
  tryWithPlaceholder.___pendingAsyncCount++;
1698
1695
  } else if (awaitBranch) {
@@ -1704,6 +1701,9 @@ function awaitTag(nodeAccessor, renderer) {
1704
1701
  }
1705
1702
  };
1706
1703
  }
1704
+ function renderImmediate(cb) {
1705
+ return runEffects(prepareEffects(cb));
1706
+ }
1707
1707
  function createTry(nodeAccessor, tryContent) {
1708
1708
  const branchAccessor = "ConditionalScope:" /* ConditionalScope */ + nodeAccessor;
1709
1709
  return (scope, input) => {
@@ -1825,10 +1825,7 @@ var dynamicTag = function dynamicTag2(nodeAccessor, getContent, getTagVar, input
1825
1825
  normalizedRenderer._ ? args[0] : args
1826
1826
  );
1827
1827
  } else {
1828
- const inputWithContent = getContent ? {
1829
- ...args,
1830
- content: getContent(scope)
1831
- } : args || {};
1828
+ const inputWithContent = getContent ? { ...args, content: getContent(scope) } : args || {};
1832
1829
  normalizedRenderer.___params(
1833
1830
  scope[childScopeAccessor],
1834
1831
  normalizedRenderer._ ? inputWithContent : [inputWithContent]
@@ -1540,12 +1540,9 @@ function awaitTag(nodeAccessor, renderer) {
1540
1540
  const referenceNode = scope[nodeAccessor];
1541
1541
  const namespaceNode = (awaitBranch?.___startNode ?? referenceNode).parentNode;
1542
1542
  const thisPromise = scope[promiseAccessor] = promise.then((data2) => {
1543
- if (scope.___closestBranch?.___destroyed || scope[promiseAccessor] !== thisPromise) {
1544
- return;
1545
- }
1546
- scope[promiseAccessor] = void 0;
1547
- runEffects(
1548
- prepareEffects(() => {
1543
+ if (thisPromise === scope[promiseAccessor] && !scope.___closestBranch?.___destroyed) {
1544
+ scope[promiseAccessor] = 0;
1545
+ renderImmediate(() => {
1549
1546
  if (tryWithPlaceholder) {
1550
1547
  placeholderShown.add(pendingEffects);
1551
1548
  }
@@ -1563,12 +1560,10 @@ function awaitTag(nodeAccessor, renderer) {
1563
1560
  referenceNode.remove();
1564
1561
  }
1565
1562
  renderer.___params?.(awaitBranch, [data2]);
1566
- })
1567
- );
1568
- if (tryWithPlaceholder) {
1569
- if (!--tryWithPlaceholder.___pendingAsyncCount) {
1563
+ });
1564
+ if (tryWithPlaceholder && !--tryWithPlaceholder.___pendingAsyncCount) {
1570
1565
  const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1571
- tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = void 0;
1566
+ tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = 0;
1572
1567
  if (placeholderBranch) {
1573
1568
  insertBranchBefore(
1574
1569
  tryWithPlaceholder,
@@ -1582,29 +1577,31 @@ function awaitTag(nodeAccessor, renderer) {
1582
1577
  }
1583
1578
  }
1584
1579
  }
1585
- }).catch((error) => {
1586
- renderCatch(scope, error, true);
1587
- });
1580
+ }).catch(
1581
+ (error) => renderImmediate(() => renderCatch(scope, error, true))
1582
+ );
1588
1583
  if (tryWithPlaceholder) {
1589
1584
  placeholderShown.add(pendingEffects);
1590
1585
  if (!tryWithPlaceholder.___pendingAsyncCount) {
1591
1586
  tryWithPlaceholder.___pendingAsyncCount = 0;
1592
- requestAnimationFrame(() => {
1593
- if (tryWithPlaceholder.___pendingAsyncCount && !tryWithPlaceholder.___destroyed) {
1594
- const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1595
- scope.$global,
1596
- tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1597
- tryWithPlaceholder._,
1598
- tryWithPlaceholder.___startNode.parentNode
1599
- );
1600
- insertBranchBefore(
1601
- placeholderBranch,
1602
- tryWithPlaceholder.___startNode.parentNode,
1603
- tryWithPlaceholder.___startNode
1604
- );
1605
- tempDetatchBranch(tryWithPlaceholder);
1606
- }
1607
- });
1587
+ requestAnimationFrame(
1588
+ () => renderImmediate(() => {
1589
+ if (tryWithPlaceholder.___pendingAsyncCount && !tryWithPlaceholder.___destroyed) {
1590
+ const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1591
+ scope.$global,
1592
+ tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1593
+ tryWithPlaceholder._,
1594
+ tryWithPlaceholder.___startNode.parentNode
1595
+ );
1596
+ insertBranchBefore(
1597
+ placeholderBranch,
1598
+ tryWithPlaceholder.___startNode.parentNode,
1599
+ tryWithPlaceholder.___startNode
1600
+ );
1601
+ tempDetatchBranch(tryWithPlaceholder);
1602
+ }
1603
+ })
1604
+ );
1608
1605
  }
1609
1606
  tryWithPlaceholder.___pendingAsyncCount++;
1610
1607
  } else if (awaitBranch) {
@@ -1616,6 +1613,9 @@ function awaitTag(nodeAccessor, renderer) {
1616
1613
  }
1617
1614
  };
1618
1615
  }
1616
+ function renderImmediate(cb) {
1617
+ return runEffects(prepareEffects(cb));
1618
+ }
1619
1619
  function createTry(nodeAccessor, tryContent) {
1620
1620
  const branchAccessor = "ConditionalScope:" /* ConditionalScope */ + nodeAccessor;
1621
1621
  return (scope, input) => {
@@ -1737,10 +1737,7 @@ var dynamicTag = function dynamicTag2(nodeAccessor, getContent, getTagVar, input
1737
1737
  normalizedRenderer._ ? args[0] : args
1738
1738
  );
1739
1739
  } else {
1740
- const inputWithContent = getContent ? {
1741
- ...args,
1742
- content: getContent(scope)
1743
- } : args || {};
1740
+ const inputWithContent = getContent ? { ...args, content: getContent(scope) } : args || {};
1744
1741
  normalizedRenderer.___params(
1745
1742
  scope[childScopeAccessor],
1746
1743
  normalizedRenderer._ ? inputWithContent : [inputWithContent]
@@ -2149,7 +2149,7 @@ function tryCatch(content, catchContent) {
2149
2149
  catchChunk.render(catchContent, catchBoundary.signal.reason);
2150
2150
  state.reorder(catchChunk);
2151
2151
  boundary.endAsync();
2152
- } else if (catchBoundary.done) {
2152
+ } else if (!catchBoundary.count) {
2153
2153
  boundary.endAsync();
2154
2154
  } else {
2155
2155
  boundary.onNext();
@@ -2174,6 +2174,7 @@ var State2 = class {
2174
2174
  hasReorderRuntime = false;
2175
2175
  hasWrittenResume = false;
2176
2176
  trailerHTML = "";
2177
+ resumes = "";
2177
2178
  nonceAttr = "";
2178
2179
  serializer = new Serializer();
2179
2180
  writeReorders = null;
@@ -2237,7 +2238,8 @@ var Boundary = class extends AbortController {
2237
2238
  onNext = NOOP;
2238
2239
  count = 0;
2239
2240
  get done() {
2240
- return this.count === 0;
2241
+ flushSerializer(this);
2242
+ return !this.count;
2241
2243
  }
2242
2244
  startAsync() {
2243
2245
  if (!this.signal.aborted) {
@@ -2343,145 +2345,152 @@ var Chunk = class {
2343
2345
  $chunk = prev;
2344
2346
  }
2345
2347
  }
2346
- };
2347
- function prepareChunk(chunk) {
2348
- const head = chunk.consume();
2349
- const { boundary, effects } = head;
2350
- const { state } = boundary;
2351
- const { $global: $global2, runtimePrefix, serializer, nonceAttr } = state;
2352
- let { html, scripts } = head;
2353
- let hasWalk = false;
2354
- head.effects = "";
2355
- if (state.needsMainRuntime && !state.hasMainRuntime) {
2356
- state.hasMainRuntime = true;
2357
- scripts = concatScripts(
2358
- scripts,
2359
- WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
2360
- );
2361
- }
2362
- let resumes = "";
2363
- if (state.writeScopes || serializer.flushed) {
2364
- let { lastSerializedScopeId } = state;
2365
- const serializeData = [];
2366
- if (!state.hasGlobals) {
2367
- state.hasGlobals = true;
2368
- serializeData.push(getFilteredGlobals(state.$global));
2369
- }
2370
- for (const key in state.writeScopes) {
2371
- const scope = state.writeScopes[key];
2372
- const scopeId = getScopeId(scope);
2373
- const scopeIdDelta = scopeId - lastSerializedScopeId;
2374
- lastSerializedScopeId = scopeId + 1;
2375
- if (scopeIdDelta) serializeData.push(scopeIdDelta);
2376
- serializeData.push(scope);
2377
- }
2378
- resumes = state.serializer.stringify(serializeData, boundary);
2379
- state.writeScopes = null;
2380
- state.lastSerializedScopeId = lastSerializedScopeId;
2381
- }
2382
- if (effects) {
2383
- hasWalk = true;
2384
- resumes = resumes ? resumes + "," + effects : effects;
2385
- }
2386
- if (resumes) {
2387
- if (state.hasWrittenResume) {
2348
+ flushScript() {
2349
+ flushSerializer(this.boundary);
2350
+ const { boundary, effects } = this;
2351
+ const { state } = boundary;
2352
+ const { $global: $global2, runtimePrefix, nonceAttr } = state;
2353
+ let { resumes } = state;
2354
+ let { html, scripts } = this;
2355
+ let hasWalk = false;
2356
+ if (state.needsMainRuntime && !state.hasMainRuntime) {
2357
+ state.hasMainRuntime = true;
2388
2358
  scripts = concatScripts(
2389
2359
  scripts,
2390
- runtimePrefix + ".r.push(" + resumes + ")"
2391
- );
2392
- } else {
2393
- state.hasWrittenResume = true;
2394
- scripts = concatScripts(
2395
- scripts,
2396
- runtimePrefix + ".r=[" + resumes + "]"
2360
+ WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
2397
2361
  );
2398
2362
  }
2399
- }
2400
- if (state.writeReorders) {
2401
- hasWalk = true;
2402
- if (!state.hasReorderRuntime) {
2403
- state.hasReorderRuntime = true;
2404
- html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>";
2405
- scripts = concatScripts(
2406
- scripts,
2407
- REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")"
2408
- );
2363
+ if (effects) {
2364
+ hasWalk = true;
2365
+ resumes = resumes ? resumes + "," + effects : effects;
2409
2366
  }
2410
- for (const reorderedChunk of state.writeReorders) {
2411
- const { reorderId } = reorderedChunk;
2412
- let reorderHTML = "";
2413
- let reorderEffects = "";
2414
- let reorderScripts = "";
2415
- let cur = reorderedChunk;
2416
- reorderedChunk.reorderId = null;
2417
- for (; ; ) {
2418
- cur.flushPlaceholder();
2419
- const { next } = cur;
2420
- cur.consumed = true;
2421
- reorderHTML += cur.html;
2422
- reorderEffects = concatEffects(reorderEffects, cur.effects);
2423
- reorderScripts = concatScripts(reorderScripts, cur.scripts);
2424
- if (cur.async) {
2425
- reorderHTML += state.mark(
2426
- "#" /* ReorderMarker */,
2427
- cur.reorderId = state.nextReorderId()
2428
- );
2429
- cur.html = cur.effects = cur.scripts = "";
2430
- cur.next = null;
2431
- }
2432
- if (next) {
2433
- cur = next;
2434
- } else {
2435
- break;
2436
- }
2367
+ if (resumes) {
2368
+ if (state.hasWrittenResume) {
2369
+ scripts = concatScripts(
2370
+ scripts,
2371
+ runtimePrefix + ".r.push(" + resumes + ")"
2372
+ );
2373
+ } else {
2374
+ state.hasWrittenResume = true;
2375
+ scripts = concatScripts(
2376
+ scripts,
2377
+ runtimePrefix + ".r=[" + resumes + "]"
2378
+ );
2437
2379
  }
2438
- if (reorderEffects) {
2439
- if (!state.hasWrittenResume) {
2440
- state.hasWrittenResume = true;
2441
- scripts = concatScripts(
2442
- scripts,
2443
- runtimePrefix + ".r=[]"
2380
+ }
2381
+ if (state.writeReorders) {
2382
+ hasWalk = true;
2383
+ if (!state.hasReorderRuntime) {
2384
+ state.hasReorderRuntime = true;
2385
+ html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>";
2386
+ scripts = concatScripts(
2387
+ scripts,
2388
+ REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")"
2389
+ );
2390
+ }
2391
+ for (const reorderedChunk of state.writeReorders) {
2392
+ const { reorderId } = reorderedChunk;
2393
+ let reorderHTML = "";
2394
+ let reorderEffects = "";
2395
+ let reorderScripts = "";
2396
+ let cur = reorderedChunk;
2397
+ reorderedChunk.reorderId = null;
2398
+ for (; ; ) {
2399
+ cur.flushPlaceholder();
2400
+ const { next } = cur;
2401
+ cur.consumed = true;
2402
+ reorderHTML += cur.html;
2403
+ reorderEffects = concatEffects(reorderEffects, cur.effects);
2404
+ reorderScripts = concatScripts(reorderScripts, cur.scripts);
2405
+ if (cur.async) {
2406
+ reorderHTML += state.mark(
2407
+ "#" /* ReorderMarker */,
2408
+ cur.reorderId = state.nextReorderId()
2409
+ );
2410
+ cur.html = cur.effects = cur.scripts = "";
2411
+ cur.next = null;
2412
+ }
2413
+ if (next) {
2414
+ cur = next;
2415
+ } else {
2416
+ break;
2417
+ }
2418
+ }
2419
+ if (reorderEffects) {
2420
+ if (!state.hasWrittenResume) {
2421
+ state.hasWrittenResume = true;
2422
+ scripts = concatScripts(
2423
+ scripts,
2424
+ runtimePrefix + ".r=[]"
2425
+ );
2426
+ }
2427
+ reorderScripts = concatScripts(
2428
+ reorderScripts,
2429
+ "_.push(" + reorderEffects + ")"
2444
2430
  );
2445
2431
  }
2446
- reorderScripts = concatScripts(
2447
- reorderScripts,
2448
- "_.push(" + reorderEffects + ")"
2432
+ scripts = concatScripts(
2433
+ scripts,
2434
+ reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
2449
2435
  );
2436
+ html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2450
2437
  }
2451
- scripts = concatScripts(
2452
- scripts,
2453
- reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
2454
- );
2455
- html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2438
+ state.writeReorders = null;
2456
2439
  }
2457
- state.writeReorders = null;
2440
+ if (hasWalk) {
2441
+ scripts = concatScripts(scripts, runtimePrefix + ".w()");
2442
+ }
2443
+ this.effects = state.resumes = "";
2444
+ this.html = html;
2445
+ this.scripts = scripts;
2446
+ return this;
2458
2447
  }
2459
- if (hasWalk) {
2460
- scripts = concatScripts(scripts, runtimePrefix + ".w()");
2448
+ flushHTML() {
2449
+ this.flushScript();
2450
+ const { boundary, scripts } = this;
2451
+ const { state } = boundary;
2452
+ const { $global: $global2, nonceAttr } = state;
2453
+ const { __flush__ } = $global2;
2454
+ let { html } = this;
2455
+ this.html = this.scripts = "";
2456
+ if (scripts) {
2457
+ html += "<script" + nonceAttr + ">" + scripts + "</script>";
2458
+ }
2459
+ if (__flush__) {
2460
+ $global2.__flush__ = void 0;
2461
+ html = __flush__($global2, html);
2462
+ }
2463
+ if (!boundary.count) {
2464
+ html += state.trailerHTML;
2465
+ }
2466
+ return html;
2461
2467
  }
2462
- head.html = html;
2463
- head.scripts = scripts;
2464
- return head;
2465
- }
2466
- function flushChunk(head, last) {
2467
- const { boundary } = head;
2468
+ };
2469
+ function flushSerializer(boundary) {
2468
2470
  const { state } = boundary;
2469
- const { html, scripts } = head;
2470
- const { $global: $global2 } = state;
2471
- const { __flush__ } = $global2;
2472
- let result = html;
2473
- head.html = head.scripts = "";
2474
- if (scripts) {
2475
- result += "<script" + state.nonceAttr + ">" + scripts + "</script>";
2476
- }
2477
- if (__flush__) {
2478
- $global2.__flush__ = void 0;
2479
- result = __flush__($global2, result);
2480
- }
2481
- if (last && state.trailerHTML) {
2482
- result += state.trailerHTML;
2471
+ const { writeScopes, serializer } = state;
2472
+ if (writeScopes || serializer.flushed) {
2473
+ const serializeData = [];
2474
+ let { lastSerializedScopeId } = state;
2475
+ if (!state.hasGlobals) {
2476
+ state.hasGlobals = true;
2477
+ serializeData.push(getFilteredGlobals(state.$global));
2478
+ }
2479
+ for (const key in writeScopes) {
2480
+ const scope = writeScopes[key];
2481
+ const scopeId = getScopeId(scope);
2482
+ const scopeIdDelta = scopeId - lastSerializedScopeId;
2483
+ lastSerializedScopeId = scopeId + 1;
2484
+ if (scopeIdDelta) serializeData.push(scopeIdDelta);
2485
+ serializeData.push(scope);
2486
+ }
2487
+ state.resumes = concatEffects(
2488
+ state.resumes,
2489
+ serializer.stringify(serializeData, boundary)
2490
+ );
2491
+ state.lastSerializedScopeId = lastSerializedScopeId;
2492
+ state.writeScopes = null;
2483
2493
  }
2484
- return result;
2485
2494
  }
2486
2495
  function writeTrailers(html) {
2487
2496
  $chunk.boundary.state.trailerHTML += html;
@@ -2961,7 +2970,7 @@ var compat = {
2961
2970
  $global2[K_TAGS_API_STATE] = state = new State2($global2);
2962
2971
  }
2963
2972
  const boundary = new Boundary(state);
2964
- let head = new Chunk(
2973
+ const head = new Chunk(
2965
2974
  boundary,
2966
2975
  null,
2967
2976
  null
@@ -2982,24 +2991,18 @@ var compat = {
2982
2991
  renderer(normalizedInput);
2983
2992
  });
2984
2993
  const asyncOut = classAPIOut.beginAsync();
2985
- (boundary.onNext = () => {
2986
- if (boundary.done) {
2994
+ queueMicrotask(
2995
+ boundary.onNext = () => {
2987
2996
  if (boundary.signal.aborted) {
2988
2997
  asyncOut.error(boundary.signal.reason);
2989
- } else {
2990
- queueMicrotask(() => {
2991
- head = prepareChunk(head);
2992
- if (boundary.done) {
2993
- const { scripts, html } = head;
2994
- asyncOut.script(scripts);
2995
- asyncOut.write(html);
2996
- asyncOut.end();
2997
- head.html = head.scripts = "";
2998
- }
2999
- });
2998
+ } else if (boundary.done) {
2999
+ const { scripts, html } = head.consume().flushScript();
3000
+ asyncOut.script(scripts);
3001
+ asyncOut.write(html);
3002
+ asyncOut.end();
3000
3003
  }
3001
3004
  }
3002
- })();
3005
+ );
3003
3006
  },
3004
3007
  registerRenderer(renderer, id) {
3005
3008
  return register(
@@ -3060,10 +3063,7 @@ function render(input = {}) {
3060
3063
  ...$global2
3061
3064
  };
3062
3065
  } else {
3063
- $global2 = {
3064
- runtimeId: DEFAULT_RUNTIME_ID,
3065
- renderId: DEFAULT_RENDER_ID
3066
- };
3066
+ $global2 = { runtimeId: DEFAULT_RUNTIME_ID, renderId: DEFAULT_RENDER_ID };
3067
3067
  }
3068
3068
  const head = new Chunk(
3069
3069
  new Boundary(new State2($global2), $global2.signal),
@@ -3127,19 +3127,13 @@ var ServerRenderResult = class {
3127
3127
  if (!(done || aborted)) {
3128
3128
  boundary?.abort(error);
3129
3129
  }
3130
- return Promise.resolve({
3131
- value: "",
3132
- done: true
3133
- });
3130
+ return Promise.resolve({ value: "", done: true });
3134
3131
  },
3135
3132
  return(value2) {
3136
3133
  if (!(done || aborted)) {
3137
3134
  boundary?.abort(new Error("Iterator returned before consumed."));
3138
3135
  }
3139
- return Promise.resolve({
3140
- value: value2,
3141
- done: true
3142
- });
3136
+ return Promise.resolve({ value: value2, done: true });
3143
3137
  }
3144
3138
  };
3145
3139
  function exec(_resolve, _reject) {
@@ -3194,7 +3188,7 @@ var ServerRenderResult = class {
3194
3188
  }
3195
3189
  #promise() {
3196
3190
  return this.#cachedPromise ||= new Promise((resolve, reject) => {
3197
- let head = this.#head;
3191
+ const head = this.#head;
3198
3192
  this.#head = null;
3199
3193
  if (!head) {
3200
3194
  return reject(new Error("Cannot read from a consumed render result"));
@@ -3205,10 +3199,7 @@ var ServerRenderResult = class {
3205
3199
  boundary.onNext = NOOP2;
3206
3200
  reject(boundary.signal.reason);
3207
3201
  } else if (boundary.done) {
3208
- head = prepareChunk(head);
3209
- if (boundary.done) {
3210
- resolve(flushChunk(head, true));
3211
- }
3202
+ resolve(head.consume().flushHTML());
3212
3203
  }
3213
3204
  })();
3214
3205
  });
@@ -3228,13 +3219,11 @@ var ServerRenderResult = class {
3228
3219
  boundary.onNext = NOOP2;
3229
3220
  onAbort(boundary.signal.reason);
3230
3221
  } else {
3231
- if (write2 || boundary.done) {
3232
- head = prepareChunk(head);
3233
- }
3234
- if (write2 || boundary.done) {
3235
- const html = flushChunk(head, boundary.done);
3222
+ const { done } = boundary;
3223
+ if (done || write2) {
3224
+ const html = (head = head.consume()).flushHTML();
3236
3225
  if (html) onWrite(html);
3237
- if (boundary.done) {
3226
+ if (done) {
3238
3227
  if (!tick2) offTick(onNext);
3239
3228
  onClose();
3240
3229
  } else {
@@ -3251,10 +3240,10 @@ var ServerRenderResult = class {
3251
3240
  }
3252
3241
  toString() {
3253
3242
  const head = this.#head;
3254
- if (!head) throw new Error("Cannot read from a consumed render result");
3255
- if (head.next) throw new Error("Cannot fork in sync mode");
3256
3243
  this.#head = null;
3257
- return flushChunk(prepareChunk(head), true);
3244
+ if (!head) throw new Error("Cannot read from a consumed render result");
3245
+ if (!head.boundary.done) throw new Error("Cannot fork in sync mode");
3246
+ return head.consume().flushHTML();
3258
3247
  }
3259
3248
  };
3260
3249
  function NOOP2() {