marko 6.0.0-next.3.62 → 6.0.0-next.3.64

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.
@@ -10,6 +10,7 @@ export interface BranchScope extends Scope {
10
10
  ___branchScopes: Set<BranchScope> | undefined;
11
11
  ___renderer: ClientRenderer | string;
12
12
  ___pendingAsyncCount: number | undefined;
13
+ ___effects: unknown[] | undefined;
13
14
  }
14
15
  export interface Scope {
15
16
  $global: Record<string, unknown> & {
@@ -18,7 +19,7 @@ export interface Scope {
18
19
  _: Scope | undefined;
19
20
  ___id: number;
20
21
  ___args: unknown;
21
- ___pending: 1 | 0 | undefined;
22
+ ___creating: 1 | 0 | undefined;
22
23
  ___abortControllers: Record<string | number, AbortController | void> | undefined;
23
24
  ___closestBranch: BranchScope | undefined;
24
25
  [x: string | number]: any;
package/dist/debug/dom.js CHANGED
@@ -990,7 +990,7 @@ var pendingScopes = [];
990
990
  function createScope($global, closestBranch) {
991
991
  const scope = {
992
992
  ___id: $global.___nextScopeId++,
993
- ___pending: 1,
993
+ ___creating: 1,
994
994
  ___closestBranch: closestBranch,
995
995
  $global
996
996
  };
@@ -1002,10 +1002,17 @@ function skipScope(scope) {
1002
1002
  }
1003
1003
  function finishPendingScopes() {
1004
1004
  for (const scope of pendingScopes) {
1005
- scope.___pending = 0;
1005
+ scope.___creating = 0;
1006
1006
  }
1007
1007
  pendingScopes = [];
1008
1008
  }
1009
+ function findBranchWithKey(scope, key) {
1010
+ let branch = scope.___closestBranch;
1011
+ while (branch && !branch[key]) {
1012
+ branch = branch.___parentBranch;
1013
+ }
1014
+ return branch;
1015
+ }
1009
1016
  function destroyBranch(branch) {
1010
1017
  branch.___parentBranch?.___branchScopes?.delete(branch);
1011
1018
  destroyNestedBranches(branch);
@@ -1475,7 +1482,7 @@ function value(valueAccessor, fn = () => {
1475
1482
  }
1476
1483
  function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "___id") {
1477
1484
  return (scope) => {
1478
- if (scope.___pending) {
1485
+ if (scope.___creating) {
1479
1486
  if (scope[id] === void 0) {
1480
1487
  scope[id] = defaultPending;
1481
1488
  } else if (!--scope[id]) {
@@ -1498,7 +1505,7 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
1498
1505
  ownerScope,
1499
1506
  () => {
1500
1507
  for (const scope of scopes) {
1501
- if (!scope.___pending && !scope.___destroyed) {
1508
+ if (!scope.___creating && !scope.___destroyed) {
1502
1509
  childSignal(scope);
1503
1510
  }
1504
1511
  }
@@ -1518,7 +1525,7 @@ function conditionalClosure(valueAccessor, ownerConditionalNodeAccessor, branch,
1518
1525
  const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
1519
1526
  const ownerSignal = (scope) => {
1520
1527
  const ifScope = scope[scopeAccessor];
1521
- if (ifScope && !ifScope.___pending && scope[branchAccessor] === branch) {
1528
+ if (ifScope && !ifScope.___creating && scope[branchAccessor] === branch) {
1522
1529
  queueRender(ifScope, childSignal, -1);
1523
1530
  }
1524
1531
  };
@@ -1543,7 +1550,7 @@ function dynamicClosure(...closureSignals) {
1543
1550
  return (scope) => {
1544
1551
  if (scope[___scopeInstancesAccessor]) {
1545
1552
  for (const childScope of scope[___scopeInstancesAccessor]) {
1546
- if (!childScope.___pending) {
1553
+ if (!childScope.___creating) {
1547
1554
  queueRender(
1548
1555
  childScope,
1549
1556
  closureSignals[childScope[___signalIndexAccessor]],
@@ -1620,98 +1627,88 @@ function awaitTag(nodeAccessor, renderer) {
1620
1627
  const promiseAccessor = "Promise:" /* Promise */ + nodeAccessor;
1621
1628
  const branchAccessor = "ConditionalScope:" /* ConditionalScope */ + nodeAccessor;
1622
1629
  return (scope, promise) => {
1623
- let tryBranch = scope.___closestBranch;
1630
+ const tryWithPlaceholder = findBranchWithKey(
1631
+ scope,
1632
+ "#PlaceholderContent" /* PlaceholderContent */
1633
+ );
1624
1634
  let awaitBranch = scope[branchAccessor];
1625
1635
  const referenceNode = scope[nodeAccessor];
1626
1636
  const namespaceNode = (awaitBranch?.___startNode ?? referenceNode).parentNode;
1627
- while (tryBranch && !tryBranch["#PlaceholderContent" /* PlaceholderContent */]) {
1628
- tryBranch = tryBranch.___parentBranch;
1629
- }
1630
1637
  const thisPromise = scope[promiseAccessor] = promise.then((data2) => {
1631
1638
  if (scope.___closestBranch?.___destroyed || scope[promiseAccessor] !== thisPromise) {
1632
1639
  return;
1633
1640
  }
1634
1641
  scope[promiseAccessor] = void 0;
1635
- const effects = prepareEffects(() => {
1636
- if (!awaitBranch || !tryBranch) {
1637
- insertBranchBefore(
1638
- awaitBranch ??= scope[branchAccessor] = createAndSetupBranch(
1639
- scope.$global,
1640
- renderer,
1641
- scope,
1642
- namespaceNode
1643
- ),
1644
- referenceNode.parentNode,
1645
- referenceNode
1646
- );
1647
- referenceNode.remove();
1648
- }
1649
- renderer.___params?.(awaitBranch, [data2]);
1650
- });
1651
- if (tryBranch) {
1652
- if (!--tryBranch.___pendingAsyncCount) {
1653
- const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */];
1642
+ runEffects(
1643
+ prepareEffects(() => {
1644
+ if (tryWithPlaceholder) {
1645
+ placeholderShown.add(pendingEffects);
1646
+ }
1647
+ if (!awaitBranch || !tryWithPlaceholder) {
1648
+ insertBranchBefore(
1649
+ awaitBranch ??= scope[branchAccessor] = createAndSetupBranch(
1650
+ scope.$global,
1651
+ renderer,
1652
+ scope,
1653
+ namespaceNode
1654
+ ),
1655
+ referenceNode.parentNode,
1656
+ referenceNode
1657
+ );
1658
+ referenceNode.remove();
1659
+ }
1660
+ renderer.___params?.(awaitBranch, [data2]);
1661
+ })
1662
+ );
1663
+ if (tryWithPlaceholder) {
1664
+ tryWithPlaceholder;
1665
+ if (!--tryWithPlaceholder.___pendingAsyncCount) {
1666
+ const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1667
+ tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = void 0;
1654
1668
  if (placeholderBranch) {
1655
1669
  insertBranchBefore(
1656
- tryBranch,
1670
+ tryWithPlaceholder,
1657
1671
  placeholderBranch.___startNode.parentNode,
1658
1672
  placeholderBranch.___startNode
1659
1673
  );
1660
1674
  removeAndDestroyBranch(placeholderBranch);
1661
1675
  } else {
1662
1676
  insertBranchBefore(
1663
- tryBranch,
1677
+ tryWithPlaceholder,
1664
1678
  referenceNode.parentNode,
1665
1679
  referenceNode
1666
1680
  );
1667
1681
  }
1682
+ if (tryWithPlaceholder.___effects) {
1683
+ runEffects(tryWithPlaceholder.___effects, true);
1684
+ }
1668
1685
  }
1669
- } else {
1670
- runEffects(effects);
1671
1686
  }
1672
1687
  }).catch((error) => {
1673
- let tryBranch2 = scope.___closestBranch;
1674
- while (tryBranch2 && !tryBranch2["#CatchContent" /* CatchContent */]) {
1675
- tryBranch2 = tryBranch2.___parentBranch;
1676
- }
1677
- if (!tryBranch2) {
1678
- setTimeout(() => {
1679
- throw error;
1680
- });
1681
- } else {
1682
- setConditionalRenderer(
1683
- tryBranch2._,
1684
- tryBranch2["#BranchAccessor" /* BranchAccessor */],
1685
- tryBranch2["#CatchContent" /* CatchContent */],
1686
- createAndSetupBranch
1687
- );
1688
- tryBranch2["#CatchContent" /* CatchContent */].___params?.(
1689
- tryBranch2._["ConditionalScope:" /* ConditionalScope */ + tryBranch2["#BranchAccessor" /* BranchAccessor */]],
1690
- [error]
1691
- );
1692
- }
1688
+ renderCatch(scope, error, true);
1693
1689
  });
1694
- if (tryBranch) {
1695
- if (!tryBranch.___pendingAsyncCount) {
1696
- tryBranch.___pendingAsyncCount = 0;
1690
+ if (tryWithPlaceholder) {
1691
+ placeholderShown.add(pendingEffects);
1692
+ if (!tryWithPlaceholder.___pendingAsyncCount) {
1693
+ tryWithPlaceholder.___pendingAsyncCount = 0;
1697
1694
  requestAnimationFrame(() => {
1698
- if (tryBranch.___pendingAsyncCount && !tryBranch.___destroyed) {
1699
- const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1695
+ if (tryWithPlaceholder.___pendingAsyncCount && !tryWithPlaceholder.___destroyed) {
1696
+ const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1700
1697
  scope.$global,
1701
- tryBranch["#PlaceholderContent" /* PlaceholderContent */],
1702
- tryBranch._,
1703
- tryBranch.___startNode.parentNode
1698
+ tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1699
+ tryWithPlaceholder._,
1700
+ tryWithPlaceholder.___startNode.parentNode
1704
1701
  );
1705
1702
  insertBranchBefore(
1706
1703
  placeholderBranch,
1707
- tryBranch.___startNode.parentNode,
1708
- tryBranch.___startNode
1704
+ tryWithPlaceholder.___startNode.parentNode,
1705
+ tryWithPlaceholder.___startNode
1709
1706
  );
1710
- tempDetatchBranch(tryBranch);
1707
+ tempDetatchBranch(tryWithPlaceholder);
1711
1708
  }
1712
1709
  });
1713
1710
  }
1714
- tryBranch.___pendingAsyncCount++;
1711
+ tryWithPlaceholder.___pendingAsyncCount++;
1715
1712
  } else if (awaitBranch) {
1716
1713
  awaitBranch.___startNode.parentNode.insertBefore(
1717
1714
  referenceNode,
@@ -1742,6 +1739,35 @@ function createTry(nodeAccessor, tryContent) {
1742
1739
  }
1743
1740
  };
1744
1741
  }
1742
+ function renderCatch(scope, error, async) {
1743
+ const tryWithCatch = findBranchWithKey(scope, "#CatchContent" /* CatchContent */);
1744
+ if (!tryWithCatch) {
1745
+ if (async) {
1746
+ setTimeout(() => {
1747
+ throw error;
1748
+ });
1749
+ } else {
1750
+ throw error;
1751
+ }
1752
+ } else {
1753
+ const placeholderBranch = tryWithCatch["#PlaceholderBranch" /* PlaceholderBranch */];
1754
+ if (placeholderBranch) {
1755
+ tryWithCatch._["ConditionalScope:" /* ConditionalScope */ + tryWithCatch["#BranchAccessor" /* BranchAccessor */]] = placeholderBranch;
1756
+ destroyBranch(tryWithCatch);
1757
+ }
1758
+ caughtError.add(pendingEffects);
1759
+ setConditionalRenderer(
1760
+ tryWithCatch._,
1761
+ tryWithCatch["#BranchAccessor" /* BranchAccessor */],
1762
+ tryWithCatch["#CatchContent" /* CatchContent */],
1763
+ createAndSetupBranch
1764
+ );
1765
+ tryWithCatch["#CatchContent" /* CatchContent */].___params?.(
1766
+ tryWithCatch._["ConditionalScope:" /* ConditionalScope */ + tryWithCatch["#BranchAccessor" /* BranchAccessor */]],
1767
+ [error]
1768
+ );
1769
+ }
1770
+ }
1745
1771
  function conditional(nodeAccessor, ...branches) {
1746
1772
  const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor;
1747
1773
  return (scope, newBranch) => {
@@ -1940,6 +1966,8 @@ function byFirstArg(name) {
1940
1966
  // src/dom/queue.ts
1941
1967
  var pendingRenders = [];
1942
1968
  var pendingRendersLookup = /* @__PURE__ */ new Map();
1969
+ var caughtError = /* @__PURE__ */ new WeakSet();
1970
+ var placeholderShown = /* @__PURE__ */ new WeakSet();
1943
1971
  var pendingEffects = [];
1944
1972
  var rendering = false;
1945
1973
  var scopeKeyOffset = 1e3;
@@ -2002,14 +2030,14 @@ function prepareEffects(fn) {
2002
2030
  }
2003
2031
  return preparedEffects;
2004
2032
  }
2005
- function runEffects(effects) {
2033
+ var runEffects = (effects) => {
2006
2034
  for (let i = 0, scope; i < effects.length; ) {
2007
2035
  effects[i++](
2008
2036
  scope = effects[i++],
2009
2037
  scope
2010
2038
  );
2011
2039
  }
2012
- }
2040
+ };
2013
2041
  function runRenders() {
2014
2042
  while (pendingRenders.length) {
2015
2043
  const render = pendingRenders[0];
@@ -2043,27 +2071,37 @@ var runRender = (render) => render.___signal(render.___scope, render.___value);
2043
2071
  var enableCatch = () => {
2044
2072
  enableCatch = () => {
2045
2073
  };
2074
+ const handlePendingTry = (fn, scope, branch) => {
2075
+ while (branch) {
2076
+ if (branch.___pendingAsyncCount) {
2077
+ return (branch.___effects ||= []).push(fn, scope);
2078
+ }
2079
+ branch = branch.___parentBranch;
2080
+ }
2081
+ };
2082
+ runEffects = /* @__PURE__ */ ((runEffects2) => (effects, checkPending = placeholderShown.has(effects)) => {
2083
+ if (checkPending || caughtError.has(effects)) {
2084
+ let i = 0;
2085
+ let fn;
2086
+ let scope;
2087
+ let branch;
2088
+ for (; i < effects.length; ) {
2089
+ fn = effects[i++];
2090
+ scope = effects[i++];
2091
+ branch = scope.___closestBranch;
2092
+ if (!branch?.___destroyed && !(checkPending && handlePendingTry(fn, scope, branch))) {
2093
+ fn(scope, scope);
2094
+ }
2095
+ }
2096
+ } else {
2097
+ runEffects2(effects);
2098
+ }
2099
+ })(runEffects);
2046
2100
  runRender = /* @__PURE__ */ ((runRender2) => (render) => {
2047
2101
  try {
2048
2102
  runRender2(render);
2049
2103
  } catch (error) {
2050
- let branch = render.___scope.___closestBranch;
2051
- while (branch && !branch["#CatchContent" /* CatchContent */])
2052
- branch = branch.___parentBranch;
2053
- if (!branch) {
2054
- throw error;
2055
- } else {
2056
- setConditionalRenderer(
2057
- branch._,
2058
- branch["#BranchAccessor" /* BranchAccessor */],
2059
- branch["#CatchContent" /* CatchContent */],
2060
- createAndSetupBranch
2061
- );
2062
- branch["#CatchContent" /* CatchContent */].___params?.(
2063
- branch._["ConditionalScope:" /* ConditionalScope */ + branch["#BranchAccessor" /* BranchAccessor */]],
2064
- [error]
2065
- );
2066
- }
2104
+ renderCatch(render.___scope, error);
2067
2105
  }
2068
2106
  })(runRender);
2069
2107
  };
@@ -902,7 +902,7 @@ var pendingScopes = [];
902
902
  function createScope($global, closestBranch) {
903
903
  const scope = {
904
904
  ___id: $global.___nextScopeId++,
905
- ___pending: 1,
905
+ ___creating: 1,
906
906
  ___closestBranch: closestBranch,
907
907
  $global
908
908
  };
@@ -914,10 +914,17 @@ function skipScope(scope) {
914
914
  }
915
915
  function finishPendingScopes() {
916
916
  for (const scope of pendingScopes) {
917
- scope.___pending = 0;
917
+ scope.___creating = 0;
918
918
  }
919
919
  pendingScopes = [];
920
920
  }
921
+ function findBranchWithKey(scope, key) {
922
+ let branch = scope.___closestBranch;
923
+ while (branch && !branch[key]) {
924
+ branch = branch.___parentBranch;
925
+ }
926
+ return branch;
927
+ }
921
928
  function destroyBranch(branch) {
922
929
  branch.___parentBranch?.___branchScopes?.delete(branch);
923
930
  destroyNestedBranches(branch);
@@ -1387,7 +1394,7 @@ function value(valueAccessor, fn = () => {
1387
1394
  }
1388
1395
  function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "___id") {
1389
1396
  return (scope) => {
1390
- if (scope.___pending) {
1397
+ if (scope.___creating) {
1391
1398
  if (scope[id] === void 0) {
1392
1399
  scope[id] = defaultPending;
1393
1400
  } else if (!--scope[id]) {
@@ -1410,7 +1417,7 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
1410
1417
  ownerScope,
1411
1418
  () => {
1412
1419
  for (const scope of scopes) {
1413
- if (!scope.___pending && !scope.___destroyed) {
1420
+ if (!scope.___creating && !scope.___destroyed) {
1414
1421
  childSignal(scope);
1415
1422
  }
1416
1423
  }
@@ -1430,7 +1437,7 @@ function conditionalClosure(valueAccessor, ownerConditionalNodeAccessor, branch,
1430
1437
  const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
1431
1438
  const ownerSignal = (scope) => {
1432
1439
  const ifScope = scope[scopeAccessor];
1433
- if (ifScope && !ifScope.___pending && scope[branchAccessor] === branch) {
1440
+ if (ifScope && !ifScope.___creating && scope[branchAccessor] === branch) {
1434
1441
  queueRender(ifScope, childSignal, -1);
1435
1442
  }
1436
1443
  };
@@ -1455,7 +1462,7 @@ function dynamicClosure(...closureSignals) {
1455
1462
  return (scope) => {
1456
1463
  if (scope[___scopeInstancesAccessor]) {
1457
1464
  for (const childScope of scope[___scopeInstancesAccessor]) {
1458
- if (!childScope.___pending) {
1465
+ if (!childScope.___creating) {
1459
1466
  queueRender(
1460
1467
  childScope,
1461
1468
  closureSignals[childScope[___signalIndexAccessor]],
@@ -1532,98 +1539,88 @@ function awaitTag(nodeAccessor, renderer) {
1532
1539
  const promiseAccessor = "Promise:" /* Promise */ + nodeAccessor;
1533
1540
  const branchAccessor = "ConditionalScope:" /* ConditionalScope */ + nodeAccessor;
1534
1541
  return (scope, promise) => {
1535
- let tryBranch = scope.___closestBranch;
1542
+ const tryWithPlaceholder = findBranchWithKey(
1543
+ scope,
1544
+ "#PlaceholderContent" /* PlaceholderContent */
1545
+ );
1536
1546
  let awaitBranch = scope[branchAccessor];
1537
1547
  const referenceNode = scope[nodeAccessor];
1538
1548
  const namespaceNode = (awaitBranch?.___startNode ?? referenceNode).parentNode;
1539
- while (tryBranch && !tryBranch["#PlaceholderContent" /* PlaceholderContent */]) {
1540
- tryBranch = tryBranch.___parentBranch;
1541
- }
1542
1549
  const thisPromise = scope[promiseAccessor] = promise.then((data2) => {
1543
1550
  if (scope.___closestBranch?.___destroyed || scope[promiseAccessor] !== thisPromise) {
1544
1551
  return;
1545
1552
  }
1546
1553
  scope[promiseAccessor] = void 0;
1547
- const effects = prepareEffects(() => {
1548
- if (!awaitBranch || !tryBranch) {
1549
- insertBranchBefore(
1550
- awaitBranch ??= scope[branchAccessor] = createAndSetupBranch(
1551
- scope.$global,
1552
- renderer,
1553
- scope,
1554
- namespaceNode
1555
- ),
1556
- referenceNode.parentNode,
1557
- referenceNode
1558
- );
1559
- referenceNode.remove();
1560
- }
1561
- renderer.___params?.(awaitBranch, [data2]);
1562
- });
1563
- if (tryBranch) {
1564
- if (!--tryBranch.___pendingAsyncCount) {
1565
- const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */];
1554
+ runEffects(
1555
+ prepareEffects(() => {
1556
+ if (tryWithPlaceholder) {
1557
+ placeholderShown.add(pendingEffects);
1558
+ }
1559
+ if (!awaitBranch || !tryWithPlaceholder) {
1560
+ insertBranchBefore(
1561
+ awaitBranch ??= scope[branchAccessor] = createAndSetupBranch(
1562
+ scope.$global,
1563
+ renderer,
1564
+ scope,
1565
+ namespaceNode
1566
+ ),
1567
+ referenceNode.parentNode,
1568
+ referenceNode
1569
+ );
1570
+ referenceNode.remove();
1571
+ }
1572
+ renderer.___params?.(awaitBranch, [data2]);
1573
+ })
1574
+ );
1575
+ if (tryWithPlaceholder) {
1576
+ tryWithPlaceholder;
1577
+ if (!--tryWithPlaceholder.___pendingAsyncCount) {
1578
+ const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1579
+ tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = void 0;
1566
1580
  if (placeholderBranch) {
1567
1581
  insertBranchBefore(
1568
- tryBranch,
1582
+ tryWithPlaceholder,
1569
1583
  placeholderBranch.___startNode.parentNode,
1570
1584
  placeholderBranch.___startNode
1571
1585
  );
1572
1586
  removeAndDestroyBranch(placeholderBranch);
1573
1587
  } else {
1574
1588
  insertBranchBefore(
1575
- tryBranch,
1589
+ tryWithPlaceholder,
1576
1590
  referenceNode.parentNode,
1577
1591
  referenceNode
1578
1592
  );
1579
1593
  }
1594
+ if (tryWithPlaceholder.___effects) {
1595
+ runEffects(tryWithPlaceholder.___effects, true);
1596
+ }
1580
1597
  }
1581
- } else {
1582
- runEffects(effects);
1583
1598
  }
1584
1599
  }).catch((error) => {
1585
- let tryBranch2 = scope.___closestBranch;
1586
- while (tryBranch2 && !tryBranch2["#CatchContent" /* CatchContent */]) {
1587
- tryBranch2 = tryBranch2.___parentBranch;
1588
- }
1589
- if (!tryBranch2) {
1590
- setTimeout(() => {
1591
- throw error;
1592
- });
1593
- } else {
1594
- setConditionalRenderer(
1595
- tryBranch2._,
1596
- tryBranch2["#BranchAccessor" /* BranchAccessor */],
1597
- tryBranch2["#CatchContent" /* CatchContent */],
1598
- createAndSetupBranch
1599
- );
1600
- tryBranch2["#CatchContent" /* CatchContent */].___params?.(
1601
- tryBranch2._["ConditionalScope:" /* ConditionalScope */ + tryBranch2["#BranchAccessor" /* BranchAccessor */]],
1602
- [error]
1603
- );
1604
- }
1600
+ renderCatch(scope, error, true);
1605
1601
  });
1606
- if (tryBranch) {
1607
- if (!tryBranch.___pendingAsyncCount) {
1608
- tryBranch.___pendingAsyncCount = 0;
1602
+ if (tryWithPlaceholder) {
1603
+ placeholderShown.add(pendingEffects);
1604
+ if (!tryWithPlaceholder.___pendingAsyncCount) {
1605
+ tryWithPlaceholder.___pendingAsyncCount = 0;
1609
1606
  requestAnimationFrame(() => {
1610
- if (tryBranch.___pendingAsyncCount && !tryBranch.___destroyed) {
1611
- const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1607
+ if (tryWithPlaceholder.___pendingAsyncCount && !tryWithPlaceholder.___destroyed) {
1608
+ const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1612
1609
  scope.$global,
1613
- tryBranch["#PlaceholderContent" /* PlaceholderContent */],
1614
- tryBranch._,
1615
- tryBranch.___startNode.parentNode
1610
+ tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1611
+ tryWithPlaceholder._,
1612
+ tryWithPlaceholder.___startNode.parentNode
1616
1613
  );
1617
1614
  insertBranchBefore(
1618
1615
  placeholderBranch,
1619
- tryBranch.___startNode.parentNode,
1620
- tryBranch.___startNode
1616
+ tryWithPlaceholder.___startNode.parentNode,
1617
+ tryWithPlaceholder.___startNode
1621
1618
  );
1622
- tempDetatchBranch(tryBranch);
1619
+ tempDetatchBranch(tryWithPlaceholder);
1623
1620
  }
1624
1621
  });
1625
1622
  }
1626
- tryBranch.___pendingAsyncCount++;
1623
+ tryWithPlaceholder.___pendingAsyncCount++;
1627
1624
  } else if (awaitBranch) {
1628
1625
  awaitBranch.___startNode.parentNode.insertBefore(
1629
1626
  referenceNode,
@@ -1654,6 +1651,35 @@ function createTry(nodeAccessor, tryContent) {
1654
1651
  }
1655
1652
  };
1656
1653
  }
1654
+ function renderCatch(scope, error, async) {
1655
+ const tryWithCatch = findBranchWithKey(scope, "#CatchContent" /* CatchContent */);
1656
+ if (!tryWithCatch) {
1657
+ if (async) {
1658
+ setTimeout(() => {
1659
+ throw error;
1660
+ });
1661
+ } else {
1662
+ throw error;
1663
+ }
1664
+ } else {
1665
+ const placeholderBranch = tryWithCatch["#PlaceholderBranch" /* PlaceholderBranch */];
1666
+ if (placeholderBranch) {
1667
+ tryWithCatch._["ConditionalScope:" /* ConditionalScope */ + tryWithCatch["#BranchAccessor" /* BranchAccessor */]] = placeholderBranch;
1668
+ destroyBranch(tryWithCatch);
1669
+ }
1670
+ caughtError.add(pendingEffects);
1671
+ setConditionalRenderer(
1672
+ tryWithCatch._,
1673
+ tryWithCatch["#BranchAccessor" /* BranchAccessor */],
1674
+ tryWithCatch["#CatchContent" /* CatchContent */],
1675
+ createAndSetupBranch
1676
+ );
1677
+ tryWithCatch["#CatchContent" /* CatchContent */].___params?.(
1678
+ tryWithCatch._["ConditionalScope:" /* ConditionalScope */ + tryWithCatch["#BranchAccessor" /* BranchAccessor */]],
1679
+ [error]
1680
+ );
1681
+ }
1682
+ }
1657
1683
  function conditional(nodeAccessor, ...branches) {
1658
1684
  const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor;
1659
1685
  return (scope, newBranch) => {
@@ -1852,6 +1878,8 @@ function byFirstArg(name) {
1852
1878
  // src/dom/queue.ts
1853
1879
  var pendingRenders = [];
1854
1880
  var pendingRendersLookup = /* @__PURE__ */ new Map();
1881
+ var caughtError = /* @__PURE__ */ new WeakSet();
1882
+ var placeholderShown = /* @__PURE__ */ new WeakSet();
1855
1883
  var pendingEffects = [];
1856
1884
  var rendering = false;
1857
1885
  var scopeKeyOffset = 1e3;
@@ -1914,14 +1942,14 @@ function prepareEffects(fn) {
1914
1942
  }
1915
1943
  return preparedEffects;
1916
1944
  }
1917
- function runEffects(effects) {
1945
+ var runEffects = (effects) => {
1918
1946
  for (let i = 0, scope; i < effects.length; ) {
1919
1947
  effects[i++](
1920
1948
  scope = effects[i++],
1921
1949
  scope
1922
1950
  );
1923
1951
  }
1924
- }
1952
+ };
1925
1953
  function runRenders() {
1926
1954
  while (pendingRenders.length) {
1927
1955
  const render = pendingRenders[0];
@@ -1955,27 +1983,37 @@ var runRender = (render) => render.___signal(render.___scope, render.___value);
1955
1983
  var enableCatch = () => {
1956
1984
  enableCatch = () => {
1957
1985
  };
1986
+ const handlePendingTry = (fn, scope, branch) => {
1987
+ while (branch) {
1988
+ if (branch.___pendingAsyncCount) {
1989
+ return (branch.___effects ||= []).push(fn, scope);
1990
+ }
1991
+ branch = branch.___parentBranch;
1992
+ }
1993
+ };
1994
+ runEffects = /* @__PURE__ */ ((runEffects2) => (effects, checkPending = placeholderShown.has(effects)) => {
1995
+ if (checkPending || caughtError.has(effects)) {
1996
+ let i = 0;
1997
+ let fn;
1998
+ let scope;
1999
+ let branch;
2000
+ for (; i < effects.length; ) {
2001
+ fn = effects[i++];
2002
+ scope = effects[i++];
2003
+ branch = scope.___closestBranch;
2004
+ if (!branch?.___destroyed && !(checkPending && handlePendingTry(fn, scope, branch))) {
2005
+ fn(scope, scope);
2006
+ }
2007
+ }
2008
+ } else {
2009
+ runEffects2(effects);
2010
+ }
2011
+ })(runEffects);
1958
2012
  runRender = /* @__PURE__ */ ((runRender2) => (render) => {
1959
2013
  try {
1960
2014
  runRender2(render);
1961
2015
  } catch (error) {
1962
- let branch = render.___scope.___closestBranch;
1963
- while (branch && !branch["#CatchContent" /* CatchContent */])
1964
- branch = branch.___parentBranch;
1965
- if (!branch) {
1966
- throw error;
1967
- } else {
1968
- setConditionalRenderer(
1969
- branch._,
1970
- branch["#BranchAccessor" /* BranchAccessor */],
1971
- branch["#CatchContent" /* CatchContent */],
1972
- createAndSetupBranch
1973
- );
1974
- branch["#CatchContent" /* CatchContent */].___params?.(
1975
- branch._["ConditionalScope:" /* ConditionalScope */ + branch["#BranchAccessor" /* BranchAccessor */]],
1976
- [error]
1977
- );
1978
- }
2016
+ renderCatch(render.___scope, error);
1979
2017
  }
1980
2018
  })(runRender);
1981
2019
  };