@estjs/template 0.0.17-beta.1 → 0.0.17-beta.3

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.
@@ -1,4 +1,4 @@
1
- import { getActiveScope, runWithScope, onCleanup, __objRest, createScope, disposeScope, __async } from './chunk-R6JICOKI.dev.js';
1
+ import { getActiveScope, runWithScope, onCleanup, __objRest, createScope, disposeScope, __async } from './chunk-PYFF2HI3.dev.js';
2
2
  import { normalizeClassName, SPREAD_NAME, isObject, warn, startsWith, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isString, isArray, kebabCase, camelCase, capitalize, HYDRATION_ANCHOR_ATTR, isBrowser, error, isPromise, isFunction, isOn, coerceArray } from '@estjs/shared';
3
3
  import { effect, shallowReactive, isSignal, isComputed, isReactive, signal } from '@estjs/signals';
4
4
 
@@ -13,6 +13,14 @@ var SUSPENSE_COMPONENT = /* @__PURE__ */ Symbol("Suspense Component" );
13
13
  var FOR_COMPONENT = /* @__PURE__ */ Symbol("For Component" );
14
14
  var TRANSITION_COMPONENT = /* @__PURE__ */ Symbol("Transition Component" );
15
15
  var TRANSITION_GROUP_COMPONENT = /* @__PURE__ */ Symbol("TransitionGroup Component" );
16
+ var DANGEROUS_DATA_MIME_RE = /^data:\s*(?:text\/html|text\/xml|application\/xhtml\+xml|image\/svg\+xml|application\/xml)/;
17
+ function isUnsafeUrl(value) {
18
+ const v = value.replaceAll(/[\u0000-\u0020]+/g, "").toLowerCase();
19
+ if (startsWith(v, "javascript:") || startsWith(v, "vbscript:")) {
20
+ return true;
21
+ }
22
+ return DANGEROUS_DATA_MIME_RE.test(v);
23
+ }
16
24
  function patchAttr(el, key, prev, next2) {
17
25
  if (key === KEY_PROP) {
18
26
  if (next2 == null) {
@@ -94,11 +102,8 @@ function patchAttr(el, key, prev, next2) {
94
102
  }
95
103
  const attrValue = isSymbol(next2) ? String(next2) : next2;
96
104
  const isUrlAttr = lowerKey === "href" || lowerKey === "src" || lowerKey === "xlink:href" || lowerKey === "action" || lowerKey === "formaction" || lowerKey === "poster";
97
- if (isUrlAttr && isString(attrValue)) {
98
- const v = attrValue.trim().toLowerCase();
99
- if (startsWith(v, "javascript:") || startsWith(v, "data:")) {
100
- return;
101
- }
105
+ if (isUrlAttr && isString(attrValue) && isUnsafeUrl(attrValue)) {
106
+ return;
102
107
  }
103
108
  if (isXlink) {
104
109
  el.setAttributeNS(XLINK_NAMESPACE, key, String(attrValue));
@@ -925,6 +930,7 @@ var Component = class {
925
930
  for (const key of Object.getOwnPropertyNames(this.reactiveProps)) {
926
931
  delete this.reactiveProps[key];
927
932
  }
933
+ this.state = 0 /* INITIAL */;
928
934
  }
929
935
  /**
930
936
  * Apply props that bind to the root DOM element rather than flowing into
@@ -1035,7 +1041,13 @@ function createApp(component, target) {
1035
1041
  const existingContent = container.innerHTML;
1036
1042
  if (existingContent) {
1037
1043
  {
1038
- warn(`Target element is not empty, it will be cleared: ${target}`);
1044
+ if (container.querySelector("[data-hk]")) {
1045
+ warn(
1046
+ `Target element contains server-rendered markup ([data-hk]); createApp() will discard it and render from scratch. Did you mean to call hydrate()?`
1047
+ );
1048
+ } else {
1049
+ warn(`Target element is not empty, it will be cleared: ${target}`);
1050
+ }
1039
1051
  }
1040
1052
  container.innerHTML = "";
1041
1053
  }
@@ -1056,8 +1068,8 @@ function createApp(component, target) {
1056
1068
  return {
1057
1069
  root: rootNode,
1058
1070
  unmount: () => {
1059
- disposeScope(scope);
1060
1071
  rootNode == null ? void 0 : rootNode.destroy();
1072
+ disposeScope(scope);
1061
1073
  }
1062
1074
  };
1063
1075
  }
@@ -1089,8 +1101,8 @@ function hydrate(component, target) {
1089
1101
  return {
1090
1102
  root: rootNode,
1091
1103
  unmount: () => {
1092
- disposeScope(scope);
1093
1104
  rootNode == null ? void 0 : rootNode.destroy();
1105
+ disposeScope(scope);
1094
1106
  }
1095
1107
  };
1096
1108
  }
@@ -1540,11 +1552,6 @@ function tryHydratePortal(props) {
1540
1552
  function isPortal(node) {
1541
1553
  return !!node && !!node[PORTAL_COMPONENT];
1542
1554
  }
1543
- function clearContainer(el) {
1544
- while (el.firstChild) {
1545
- el.removeChild(el.firstChild);
1546
- }
1547
- }
1548
1555
  function resolveNodeValue(value) {
1549
1556
  let current = value;
1550
1557
  while (isFunction(current)) {
@@ -1553,6 +1560,9 @@ function resolveNodeValue(value) {
1553
1560
  if (isSignal(current) || isComputed(current)) {
1554
1561
  return resolveNodeValue(current.value);
1555
1562
  }
1563
+ if (Array.isArray(current)) {
1564
+ return current.map((item) => resolveNodeValue(item));
1565
+ }
1556
1566
  return current;
1557
1567
  }
1558
1568
  var SuspenseContext = /* @__PURE__ */ Symbol("SuspenseContext");
@@ -1561,129 +1571,127 @@ function Suspense(props) {
1561
1571
  if (!isBrowser()) {
1562
1572
  return (_a2 = props.fallback) != null ? _a2 : "";
1563
1573
  }
1564
- const container = document.createElement("div");
1565
- container.style.display = "contents";
1566
- let isMounted = true;
1567
- let pendingCount = 0;
1568
- let isShowingFallback = false;
1569
- let resolvedChildren = null;
1570
- const materializeChild = (value) => {
1571
- const current = resolveNodeValue(value);
1572
- if (isArray(current)) {
1573
- const nodes = [];
1574
- for (const item of current) {
1575
- const materialized = materializeChild(item);
1576
- if (isArray(materialized)) {
1577
- nodes.push(...materialized);
1578
- } else {
1579
- nodes.push(materialized);
1580
- }
1581
- }
1582
- return nodes;
1583
- }
1584
- return normalizeNode(current);
1574
+ const owner = getActiveScope();
1575
+ const start = document.createComment("suspense");
1576
+ const end = document.createComment("/suspense");
1577
+ const frag = document.createDocumentFragment();
1578
+ frag.append(start, end);
1579
+ let mounted = true;
1580
+ let pending = 0;
1581
+ let mounting = false;
1582
+ let contentScope = null;
1583
+ let parked = null;
1584
+ let fallbackScope = null;
1585
+ let resolved = null;
1586
+ const parkContent = () => {
1587
+ const off = document.createDocumentFragment();
1588
+ while (end.previousSibling && end.previousSibling !== start) {
1589
+ off.prepend(end.previousSibling);
1590
+ }
1591
+ parked = off;
1585
1592
  };
1586
- const insertMaterializedChild = (value) => {
1587
- const normalized = materializeChild(value);
1588
- const nodes = isArray(normalized) ? normalized : [normalized];
1589
- for (const node of nodes) {
1590
- if (node != null) {
1591
- insertNode(container, node);
1592
- }
1593
- }
1593
+ const restoreContent = () => {
1594
+ var _a3;
1595
+ if (!parked) return;
1596
+ const parent = (_a3 = end.parentNode) != null ? _a3 : frag;
1597
+ while (parked.firstChild) {
1598
+ parent.insertBefore(parked.firstChild, end);
1599
+ }
1600
+ parked = null;
1594
1601
  };
1595
- const renderFallbackContent = () => {
1596
- clearContainer(container);
1597
- if (props.fallback != null) {
1598
- insertMaterializedChild(props.fallback);
1599
- }
1602
+ const mountFallback = () => {
1603
+ if (props.fallback == null || fallbackScope) return;
1604
+ fallbackScope = createScope(owner);
1605
+ runWithScope(fallbackScope, () => {
1606
+ var _a3;
1607
+ insert((_a3 = end.parentNode) != null ? _a3 : frag, () => resolveNodeValue(props.fallback), end);
1608
+ });
1600
1609
  };
1601
- const showFallback = () => {
1602
- if (isShowingFallback) return;
1603
- isShowingFallback = true;
1604
- renderFallbackContent();
1610
+ const disposeFallback = () => {
1611
+ if (!fallbackScope) return;
1612
+ disposeScope(fallbackScope);
1613
+ fallbackScope = null;
1605
1614
  };
1606
- const showChildren = () => {
1607
- if (!isShowingFallback) return;
1608
- const hasContent = resolvedChildren || props.children != null && !isPromise(props.children);
1609
- if (!hasContent) {
1610
- return;
1611
- }
1612
- isShowingFallback = false;
1613
- clearContainer(container);
1614
- if (resolvedChildren) {
1615
- renderChildren(resolvedChildren);
1616
- } else if (props.children != null && !isPromise(props.children)) {
1617
- renderChildren(props.children);
1615
+ const mountContent = (children2) => {
1616
+ mounting = true;
1617
+ contentScope = createScope(owner);
1618
+ runWithScope(contentScope, () => {
1619
+ var _a3;
1620
+ insert((_a3 = end.parentNode) != null ? _a3 : frag, () => resolveNodeValue(children2), end);
1621
+ });
1622
+ mounting = false;
1623
+ if (pending && !parked) {
1624
+ parkContent();
1625
+ mountFallback();
1618
1626
  }
1619
1627
  };
1620
- const renderChildren = (children2) => {
1621
- if (isShowingFallback) return;
1622
- clearContainer(container);
1623
- if (children2 == null) return;
1624
- const childArray = isArray(children2) ? children2 : [children2];
1625
- for (const child2 of childArray) {
1626
- if (child2 != null) {
1627
- insertMaterializedChild(child2);
1628
+ const showFallback = () => {
1629
+ if (parked) return;
1630
+ if (mounting) return;
1631
+ parkContent();
1632
+ mountFallback();
1633
+ };
1634
+ const showContent = () => {
1635
+ if (!parked) return;
1636
+ const hasSyncChildren = props.children != null && !isPromise(props.children);
1637
+ if (contentScope == null && resolved == null && !hasSyncChildren) return;
1638
+ disposeFallback();
1639
+ restoreContent();
1640
+ if (!contentScope) {
1641
+ if (resolved) {
1642
+ mountContent(resolved);
1643
+ } else if (hasSyncChildren) {
1644
+ mountContent(props.children);
1628
1645
  }
1629
1646
  }
1630
- if (isShowingFallback) {
1631
- renderFallbackContent();
1632
- }
1633
1647
  };
1634
- const suspenseContext = {
1648
+ const settle = () => {
1649
+ if (!mounted) return;
1650
+ if (--pending === 0) showContent();
1651
+ };
1652
+ const ctx = {
1635
1653
  register: (promise) => {
1636
- pendingCount++;
1654
+ pending++;
1637
1655
  showFallback();
1638
- promise.then(() => {
1639
- if (!isMounted) return;
1640
- pendingCount--;
1641
- if (pendingCount === 0) {
1642
- showChildren();
1643
- }
1644
- }).catch((error4) => {
1645
- {
1646
- warn("[Suspense] Resource failed:", error4);
1647
- }
1648
- if (!isMounted) return;
1649
- pendingCount--;
1650
- if (pendingCount === 0) {
1651
- showChildren();
1652
- }
1656
+ promise.then(settle).catch((error4) => {
1657
+ warn("[Suspense] Resource failed:", error4);
1658
+ settle();
1653
1659
  });
1654
1660
  },
1655
1661
  increment: () => {
1656
- pendingCount++;
1662
+ pending++;
1657
1663
  showFallback();
1658
1664
  },
1659
1665
  decrement: () => {
1660
- pendingCount = Math.max(0, pendingCount - 1);
1661
- if (pendingCount === 0) {
1662
- showChildren();
1663
- }
1666
+ pending = Math.max(0, pending - 1);
1667
+ if (pending === 0) showContent();
1664
1668
  }
1665
1669
  };
1666
- provide(SuspenseContext, suspenseContext);
1670
+ provide(SuspenseContext, ctx);
1667
1671
  const children = props.children;
1668
1672
  if (isPromise(children)) {
1669
- children.then((resolved) => {
1670
- resolvedChildren = resolved;
1673
+ children.then((value) => {
1674
+ resolved = value;
1671
1675
  }).catch(() => {
1672
1676
  });
1673
- suspenseContext.register(children);
1677
+ ctx.register(children);
1674
1678
  } else if (children != null) {
1675
- renderChildren(children);
1676
- } else {
1679
+ mountContent(children);
1680
+ } else if (props.fallback != null) {
1677
1681
  showFallback();
1678
1682
  }
1679
- onDestroy(() => {
1680
- isMounted = false;
1681
- pendingCount = 0;
1682
- resolvedChildren = null;
1683
- clearContainer(container);
1684
- container.remove();
1683
+ onCleanup(() => {
1684
+ mounted = false;
1685
+ pending = 0;
1686
+ resolved = null;
1687
+ if (contentScope) disposeScope(contentScope);
1688
+ if (fallbackScope) disposeScope(fallbackScope);
1689
+ contentScope = fallbackScope = null;
1690
+ parked = null;
1691
+ start.remove();
1692
+ end.remove();
1685
1693
  });
1686
- return container;
1694
+ return frag;
1687
1695
  }
1688
1696
  Suspense[SUSPENSE_COMPONENT] = true;
1689
1697
  function isSuspense(node) {
@@ -1757,185 +1765,131 @@ function createResource(fetcher, options) {
1757
1765
  function resolveModule(mod) {
1758
1766
  return isFunction(mod) ? mod : mod.default;
1759
1767
  }
1760
- function renderInto(el, fn, props) {
1761
- const comp = new Component(fn, props);
1762
- comp.mount(el);
1763
- return comp;
1768
+ function defineServerAsyncComponent(loader, ssr) {
1769
+ if (ssr === "client-only") {
1770
+ const placeholder = () => "";
1771
+ placeholder.__asyncLoader = loader;
1772
+ placeholder.__asyncResolved = () => null;
1773
+ return placeholder;
1774
+ }
1775
+ let resolved = null;
1776
+ let promise = null;
1777
+ const load = () => promise != null ? promise : promise = loader().then((mod) => {
1778
+ resolved = resolveModule(mod);
1779
+ }).catch(() => {
1780
+ });
1781
+ load();
1782
+ const wrapper = (props) => resolved ? resolved(props) : "";
1783
+ wrapper.__asyncLoader = load;
1784
+ wrapper.__asyncResolved = () => resolved;
1785
+ return wrapper;
1764
1786
  }
1765
- function defineAsyncComponent(loader, options = {}) {
1766
- const { delay = 200, timeout, ssr = "blocking", onError } = options;
1767
- if (typeof window === "undefined") {
1768
- if (ssr === "client-only") {
1769
- const placeholder = () => "";
1770
- placeholder.__asyncLoader = loader;
1771
- placeholder.__asyncResolved = () => null;
1772
- return placeholder;
1773
- }
1774
- let ssrResolved = null;
1775
- let ssrPromise = null;
1776
- const ssrLoad = () => {
1777
- if (ssrPromise) return ssrPromise;
1778
- ssrPromise = loader().then((mod) => {
1779
- ssrResolved = resolveModule(mod);
1780
- }).catch(() => {
1781
- });
1782
- return ssrPromise;
1783
- };
1784
- ssrLoad();
1785
- const ssrWrapper = (props) => {
1786
- if (ssrResolved) {
1787
- return ssrResolved(props);
1788
- }
1789
- return "";
1790
- };
1791
- ssrWrapper.__asyncLoader = ssrLoad;
1792
- ssrWrapper.__asyncResolved = () => ssrResolved;
1793
- return ssrWrapper;
1794
- }
1795
- let cachedComponent = null;
1796
- let cachedError = null;
1797
- let cachedStatus = "pending";
1787
+ function defineClientAsyncComponent(loader, options) {
1788
+ const { loading, error: errorComp, delay = 200, timeout, onError } = options;
1789
+ let component = null;
1790
+ let error4 = null;
1791
+ let status = "pending";
1798
1792
  let loadPromise = null;
1799
- function load() {
1800
- if (loadPromise) return loadPromise;
1801
- loadPromise = loader().then((mod) => {
1802
- cachedComponent = resolveModule(mod);
1803
- cachedStatus = "resolved";
1804
- }).catch((error4) => {
1805
- cachedError = error4 instanceof Error ? error4 : new Error(String(error4));
1806
- cachedStatus = "errored";
1807
- loadPromise = null;
1808
- });
1809
- return loadPromise;
1810
- }
1793
+ const load = () => loadPromise != null ? loadPromise : loadPromise = loader().then((mod) => {
1794
+ component = resolveModule(mod);
1795
+ status = "resolved";
1796
+ }).catch((error_) => {
1797
+ error4 = error_ instanceof Error ? error_ : new Error(String(error_));
1798
+ status = "errored";
1799
+ loadPromise = null;
1800
+ });
1811
1801
  load();
1812
1802
  function AsyncWrapper(props) {
1813
1803
  var _a2;
1814
- if (cachedStatus === "resolved" && cachedComponent) {
1815
- const el = document.createElement("div");
1816
- el.style.display = "contents";
1817
- const comp = renderInto(el, cachedComponent, props);
1818
- onCleanup(() => comp.destroy());
1819
- return el;
1820
- }
1821
- if (cachedStatus === "errored" && cachedError) {
1822
- const el = document.createElement("div");
1823
- el.style.display = "contents";
1824
- if (options.error) {
1825
- let alive2 = true;
1826
- let currentComp2 = null;
1827
- const swap2 = (fn, swapProps) => {
1828
- if (!alive2) return;
1829
- currentComp2 == null ? void 0 : currentComp2.destroy();
1830
- currentComp2 = renderInto(el, fn, swapProps);
1831
- };
1832
- const retry = () => {
1833
- loadPromise = null;
1834
- cachedStatus = "pending";
1835
- cachedError = null;
1836
- if (options.loading) swap2(options.loading);
1837
- load().then(() => {
1838
- if (!alive2) return;
1839
- if (cachedStatus === "resolved" && cachedComponent) {
1840
- swap2(cachedComponent, props);
1841
- } else if (cachedStatus === "errored" && cachedError) {
1842
- if (options.error) swap2(options.error, { error: cachedError, retry });
1843
- }
1844
- });
1845
- };
1846
- swap2(options.error, { error: cachedError, retry });
1847
- onDestroy(() => {
1848
- alive2 = false;
1849
- currentComp2 == null ? void 0 : currentComp2.destroy();
1850
- currentComp2 = null;
1851
- });
1852
- }
1853
- return el;
1854
- }
1855
- const container = document.createElement("div");
1856
- container.style.display = "contents";
1804
+ const owner = getActiveScope();
1805
+ const end = document.createComment("async");
1806
+ const frag = document.createDocumentFragment();
1807
+ frag.appendChild(end);
1857
1808
  let alive = true;
1858
- let currentComp = null;
1809
+ let viewScope = null;
1859
1810
  let delayTimer = null;
1860
1811
  let timeoutTimer = null;
1861
- const swap = (fn, swapProps) => {
1862
- if (!alive) return;
1863
- currentComp == null ? void 0 : currentComp.destroy();
1864
- currentComp = renderInto(container, fn, swapProps);
1812
+ const clearTimers = () => {
1813
+ if (delayTimer != null) clearTimeout(delayTimer);
1814
+ if (timeoutTimer != null) clearTimeout(timeoutTimer);
1815
+ delayTimer = timeoutTimer = null;
1865
1816
  };
1866
- const retryWith = (retryProps) => () => {
1867
- loadPromise = null;
1868
- cachedStatus = "pending";
1869
- cachedError = null;
1870
- if (options.loading) swap(options.loading);
1871
- load().then(() => {
1872
- if (cachedStatus === "resolved" && cachedComponent) {
1873
- swap(cachedComponent, retryProps);
1874
- } else if (cachedStatus === "errored" && cachedError) {
1875
- if (options.error) {
1876
- swap(options.error, {
1877
- error: cachedError,
1878
- retry: retryWith(retryProps)
1879
- });
1880
- }
1881
- }
1817
+ const render = (fn, fnProps) => {
1818
+ if (!alive) return;
1819
+ if (owner && owner.isDestroyed) return;
1820
+ if (viewScope) {
1821
+ disposeScope(viewScope);
1822
+ viewScope = null;
1823
+ }
1824
+ if (!fn) return;
1825
+ viewScope = createScope(owner);
1826
+ runWithScope(viewScope, () => {
1827
+ var _a3;
1828
+ insert((_a3 = end.parentNode) != null ? _a3 : frag, () => new Component(fn, fnProps), end);
1882
1829
  });
1883
1830
  };
1884
1831
  onDestroy(() => {
1885
1832
  alive = false;
1886
- currentComp == null ? void 0 : currentComp.destroy();
1887
- currentComp = null;
1888
- if (delayTimer != null) clearTimeout(delayTimer);
1889
- if (timeoutTimer != null) clearTimeout(timeoutTimer);
1833
+ clearTimers();
1834
+ if (viewScope) {
1835
+ disposeScope(viewScope);
1836
+ viewScope = null;
1837
+ }
1838
+ end.remove();
1890
1839
  });
1891
- const suspenseCtx = (_a2 = inject(SuspenseContext)) != null ? _a2 : null;
1892
- const showResolved = (compFn) => swap(compFn, props);
1893
- const showError = (err) => {
1894
- if (options.error) swap(options.error, { error: err, retry: retryWith(props) });
1895
- };
1896
- const showLoading = () => {
1897
- if (options.loading) swap(options.loading);
1840
+ const retryWith = (retryProps) => () => {
1841
+ loadPromise = null;
1842
+ status = "pending";
1843
+ error4 = null;
1844
+ if (loading) render(loading);
1845
+ load().then(() => settle(retryProps));
1898
1846
  };
1899
- const instancePromise = load().then(() => {
1847
+ const settle = (renderProps) => {
1900
1848
  if (!alive) return;
1901
- if (cachedStatus === "resolved" && cachedComponent) {
1902
- showResolved(cachedComponent);
1903
- } else if (cachedStatus === "errored" && cachedError) {
1904
- showError(cachedError);
1905
- if (onError) onError(cachedError, retryWith(props));
1849
+ clearTimers();
1850
+ if (status === "resolved" && component) {
1851
+ render(component, renderProps);
1852
+ } else if (status === "errored" && error4) {
1853
+ if (errorComp) render(errorComp, { error: error4, retry: retryWith(renderProps) });
1854
+ if (onError) onError(error4, retryWith(renderProps));
1906
1855
  }
1907
- if (delayTimer != null) clearTimeout(delayTimer);
1908
- if (timeoutTimer != null) clearTimeout(timeoutTimer);
1909
- });
1910
- if (suspenseCtx) {
1911
- suspenseCtx.register(instancePromise);
1856
+ };
1857
+ if (status === "resolved" && component) {
1858
+ render(component, props);
1859
+ return frag;
1912
1860
  }
1861
+ if (status === "errored" && error4) {
1862
+ if (errorComp) render(errorComp, { error: error4, retry: retryWith(props) });
1863
+ return frag;
1864
+ }
1865
+ const pending = load().then(() => settle(props));
1866
+ (_a2 = inject(SuspenseContext)) == null ? void 0 : _a2.register(pending);
1913
1867
  if (delay > 0) {
1914
1868
  delayTimer = setTimeout(() => {
1915
- if (alive && cachedStatus === "pending") {
1916
- showLoading();
1917
- }
1869
+ if (alive && status === "pending" && loading) render(loading);
1918
1870
  }, delay);
1919
- } else if (options.loading) {
1920
- showLoading();
1871
+ } else if (loading) {
1872
+ render(loading);
1921
1873
  }
1922
1874
  if (timeout != null) {
1923
1875
  timeoutTimer = setTimeout(() => {
1924
- if (alive && cachedStatus === "pending") {
1925
- const err = new Error(`[defineAsyncComponent] Timeout after ${timeout}ms`);
1926
- cachedError = err;
1927
- cachedStatus = "errored";
1928
- showError(err);
1929
- if (onError) onError(err, retryWith(props));
1930
- }
1876
+ if (!alive || status !== "pending") return;
1877
+ error4 = new Error(`[defineAsyncComponent] Timeout after ${timeout}ms`);
1878
+ status = "errored";
1879
+ if (errorComp) render(errorComp, { error: error4, retry: retryWith(props) });
1880
+ if (onError) onError(error4, retryWith(props));
1931
1881
  }, timeout);
1932
1882
  }
1933
- return container;
1883
+ return frag;
1934
1884
  }
1935
1885
  AsyncWrapper.__asyncLoader = load;
1936
- AsyncWrapper.__asyncResolved = () => cachedComponent;
1886
+ AsyncWrapper.__asyncResolved = () => component;
1937
1887
  return AsyncWrapper;
1938
1888
  }
1889
+ function defineAsyncComponent(loader, options = {}) {
1890
+ var _a2;
1891
+ return typeof window === "undefined" ? defineServerAsyncComponent(loader, (_a2 = options.ssr) != null ? _a2 : "blocking") : defineClientAsyncComponent(loader, options);
1892
+ }
1939
1893
  function For(props) {
1940
1894
  const fragment = document.createDocumentFragment();
1941
1895
  const marker = document.createComment("");
@@ -1978,14 +1932,14 @@ function For(props) {
1978
1932
  };
1979
1933
  const clearFallback = () => {
1980
1934
  for (const node of fallbackNodes) {
1981
- if (node.parentNode) {
1982
- node.parentNode.removeChild(node);
1983
- }
1935
+ removeNode(node);
1984
1936
  }
1985
1937
  fallbackNodes = [];
1986
1938
  };
1939
+ const ownerScope = getActiveScope();
1987
1940
  const renderItem = (item, index, parent, before, key = getKey(item, index)) => {
1988
- const parentScope = getActiveScope();
1941
+ var _a2;
1942
+ const parentScope = (_a2 = getActiveScope()) != null ? _a2 : ownerScope;
1989
1943
  const scope = createScope(parentScope);
1990
1944
  let mountedNodes = [];
1991
1945
  runWithScope(scope, () => {