sibujs 4.9.0 → 4.10.0

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 (62) hide show
  1. package/dist/browser.cjs +41 -4
  2. package/dist/browser.js +4 -4
  3. package/dist/build.cjs +102 -38
  4. package/dist/build.js +10 -10
  5. package/dist/cdn.dev.global.js +14 -14
  6. package/dist/cdn.full.dev.global.js +13 -13
  7. package/dist/cdn.full.global.js +12 -12
  8. package/dist/cdn.global.js +15 -15
  9. package/dist/{chunk-FNOK662L.js → chunk-2NWHJ2UJ.js} +73 -43
  10. package/dist/{chunk-KG25XMGP.js → chunk-4DCVJ4YA.js} +15 -8
  11. package/dist/{chunk-CF2KCWRE.js → chunk-54F4TPHK.js} +2 -2
  12. package/dist/{chunk-X7NRHFZR.js → chunk-5PC7OTQW.js} +1 -1
  13. package/dist/{chunk-SBTZEYNI.js → chunk-7WIHYHWD.js} +8 -1
  14. package/dist/{chunk-K6K5ACO6.js → chunk-BMCR7TXG.js} +3 -3
  15. package/dist/{chunk-G2WHYEL7.js → chunk-D6HYFOWR.js} +39 -4
  16. package/dist/{chunk-5MLWTIQE.js → chunk-EVI4ZQO3.js} +2 -2
  17. package/dist/{chunk-CDBKFGXN.js → chunk-EVOK663Z.js} +1 -1
  18. package/dist/{chunk-SYHGGDNW.js → chunk-FYUEL5IW.js} +1 -1
  19. package/dist/{chunk-562UVHMM.js → chunk-GMMDHJJT.js} +11 -6
  20. package/dist/{chunk-FHCZMHHE.js → chunk-GOL3FU5Q.js} +1 -1
  21. package/dist/{chunk-YW6HQKGO.js → chunk-GTS35FLA.js} +2 -2
  22. package/dist/{chunk-2K3Z3XO4.js → chunk-IFRIBZ4O.js} +4 -4
  23. package/dist/{chunk-DRMLIF6M.js → chunk-IL5MMSCL.js} +19 -12
  24. package/dist/{chunk-XJVTQUIV.js → chunk-ITEL5KPL.js} +5 -5
  25. package/dist/{chunk-TV464N2M.js → chunk-JCKUWWHU.js} +3 -3
  26. package/dist/{chunk-QBKCK6MJ.js → chunk-N6U4GOIU.js} +1 -1
  27. package/dist/{chunk-NQMKWBKU.js → chunk-TOPRMXFY.js} +1 -1
  28. package/dist/{chunk-7OV5Q2UU.js → chunk-VWPMWV7O.js} +4 -4
  29. package/dist/{chunk-MPWDSTYK.js → chunk-XUQUQJYE.js} +1 -1
  30. package/dist/data.cjs +48 -6
  31. package/dist/data.d.cts +9 -1
  32. package/dist/data.d.ts +9 -1
  33. package/dist/data.js +5 -5
  34. package/dist/devtools.cjs +41 -4
  35. package/dist/devtools.js +4 -4
  36. package/dist/ecosystem.cjs +41 -4
  37. package/dist/ecosystem.js +7 -7
  38. package/dist/extras.cjs +75 -25
  39. package/dist/extras.js +20 -20
  40. package/dist/index.cjs +102 -38
  41. package/dist/index.d.cts +16 -0
  42. package/dist/index.d.ts +16 -0
  43. package/dist/index.js +10 -10
  44. package/dist/motion.cjs +36 -4
  45. package/dist/motion.js +3 -3
  46. package/dist/patterns.cjs +41 -4
  47. package/dist/patterns.js +5 -5
  48. package/dist/performance.cjs +55 -14
  49. package/dist/performance.js +4 -4
  50. package/dist/plugins.cjs +163 -51
  51. package/dist/plugins.d.cts +56 -2
  52. package/dist/plugins.d.ts +56 -2
  53. package/dist/plugins.js +130 -52
  54. package/dist/ssr.cjs +50 -9
  55. package/dist/ssr.js +7 -7
  56. package/dist/testing.cjs +41 -4
  57. package/dist/testing.js +2 -2
  58. package/dist/ui.cjs +41 -4
  59. package/dist/ui.js +7 -7
  60. package/dist/widgets.cjs +36 -4
  61. package/dist/widgets.js +6 -6
  62. package/package.json +1 -1
package/dist/plugins.js CHANGED
@@ -19,7 +19,7 @@ import {
19
19
  preloadCritical,
20
20
  prerenderRoutes,
21
21
  satisfies
22
- } from "./chunk-CF2KCWRE.js";
22
+ } from "./chunk-54F4TPHK.js";
23
23
  import {
24
24
  PluginInstallCancelledError,
25
25
  createPlugin,
@@ -35,7 +35,7 @@ import {
35
35
  } from "./chunk-J6FW5TV6.js";
36
36
  import {
37
37
  span
38
- } from "./chunk-QBKCK6MJ.js";
38
+ } from "./chunk-N6U4GOIU.js";
39
39
  import {
40
40
  escapeScriptJson,
41
41
  renderToString,
@@ -48,17 +48,17 @@ import {
48
48
  import {
49
49
  appendChildren,
50
50
  resolveClassValue
51
- } from "./chunk-5MLWTIQE.js";
51
+ } from "./chunk-EVI4ZQO3.js";
52
52
  import {
53
53
  setSafeAttribute
54
- } from "./chunk-MPWDSTYK.js";
54
+ } from "./chunk-XUQUQJYE.js";
55
55
  import "./chunk-3ACAAQIN.js";
56
56
  import {
57
57
  globalSingleton
58
58
  } from "./chunk-7ZHH77QA.js";
59
59
  import {
60
60
  effect
61
- } from "./chunk-SBTZEYNI.js";
61
+ } from "./chunk-7WIHYHWD.js";
62
62
  import {
63
63
  sanitizeUrl,
64
64
  stripControlChars
@@ -69,11 +69,14 @@ import {
69
69
  import "./chunk-5HZXGZ6T.js";
70
70
  import {
71
71
  signal
72
- } from "./chunk-SYHGGDNW.js";
72
+ } from "./chunk-FYUEL5IW.js";
73
73
  import {
74
+ bindOwnerScope,
75
+ getOwnerScope,
76
+ runWithOwnerScope,
74
77
  track,
75
78
  untracked
76
- } from "./chunk-G2WHYEL7.js";
79
+ } from "./chunk-D6HYFOWR.js";
77
80
  import {
78
81
  devWarn,
79
82
  dispose,
@@ -652,12 +655,12 @@ var _ComponentLoader = class _ComponentLoader {
652
655
  * resolved, so the import happens once and later mounts call the module's
653
656
  * factory directly.
654
657
  */
655
- async instantiate(plan, route2, routePath) {
658
+ async instantiate(plan, route2, routePath, scope) {
656
659
  if (plan.kind === "factory") {
657
- return this.instantiateFactory(plan.component, route2, routePath);
660
+ return this.instantiateFactory(plan.component, route2, routePath, scope);
658
661
  }
659
662
  const factory = await this.resolveModuleFactory(plan, route2, routePath);
660
- return this.instantiateFactory(factory, route2, routePath);
663
+ return this.instantiateFactory(factory, route2, routePath, scope);
661
664
  }
662
665
  /**
663
666
  * Resolve a deferred plan's module and cache the factory it exports —
@@ -702,14 +705,14 @@ var _ComponentLoader = class _ComponentLoader {
702
705
  * `depth` bounds that unwrapping; a module whose default is itself a module
703
706
  * is a configuration error, not something to chase.
704
707
  */
705
- async instantiateFactory(component, route2, routePath, depth = 0) {
706
- const result = component();
708
+ async instantiateFactory(component, route2, routePath, scope, depth = 0) {
709
+ const result = scope ? runWithOwnerScope(scope, component) : component();
707
710
  const value = this.isThenable(result) ? await result : result;
708
711
  if (this.isElement(value)) return value;
709
712
  if (depth === 0 && this.isFactoryLike(value)) {
710
713
  const factory = this.extractFactory(value, routePath);
711
714
  this.planCache.set(this.keyFor(route2), { kind: "factory", component: factory });
712
- return this.instantiateFactory(factory, route2, routePath, depth + 1);
715
+ return this.instantiateFactory(factory, route2, routePath, scope, depth + 1);
713
716
  }
714
717
  throw new Error(`Component for route "${routePath}" must return Element, got ${typeof value}`);
715
718
  }
@@ -1114,9 +1117,12 @@ var _SibuRouter = class _SibuRouter {
1114
1117
  async loadPlan(route2, routePath) {
1115
1118
  return this.loader.loadPlan(route2, routePath);
1116
1119
  }
1117
- /** Create exactly one real instance from an already-resolved plan. */
1118
- async instantiateComponent(plan, route2, routePath) {
1119
- return this.loader.instantiate(plan, route2, routePath);
1120
+ /**
1121
+ * Create exactly one real instance from an already-resolved plan. With a
1122
+ * `scope`, the factory runs in it (see `RouteScope`).
1123
+ */
1124
+ async instantiateComponent(plan, route2, routePath, scope) {
1125
+ return this.loader.instantiate(plan, route2, routePath, scope);
1120
1126
  }
1121
1127
  /** Resolve a route's module/factory without creating any component instance. */
1122
1128
  async preloadPlan(route2, routePath) {
@@ -1272,14 +1278,72 @@ function setRoutes(routes) {
1272
1278
  if (!_routerRef.current) throw new Error("Router not initialized. Call createRouter() first.");
1273
1279
  _routerRef.current.updateRoutes(normalizeRoutes(routes));
1274
1280
  }
1281
+ var RouteScope = class {
1282
+ constructor(route2) {
1283
+ this.released = false;
1284
+ const [get, set] = signal(route2);
1285
+ this.get = get;
1286
+ this.set = set;
1287
+ }
1288
+ /** The instance's route, or `null` once released. Reactive. */
1289
+ read() {
1290
+ return this.get();
1291
+ }
1292
+ /** Hand a kept instance the route of the navigation that kept it. */
1293
+ update(route2) {
1294
+ if (!this.released) this.set(route2);
1295
+ }
1296
+ /**
1297
+ * Called when the instance is disposed. The switch to "no scope" is
1298
+ * published a microtask later, once the whole dispose has finished: a
1299
+ * teardown the instance registered after this one (an `onMount` effect, say)
1300
+ * may still be alive at this point, and must not re-run against the
1301
+ * router-global route on its way out.
1302
+ */
1303
+ release() {
1304
+ if (this.released) return;
1305
+ this.released = true;
1306
+ queueMicrotask(() => this.set(null));
1307
+ }
1308
+ };
1309
+ function activeRouteScope() {
1310
+ const scope = getOwnerScope();
1311
+ return scope instanceof RouteScope ? scope : null;
1312
+ }
1313
+ function scopedRoute(router2) {
1314
+ const scope = activeRouteScope();
1315
+ if (scope) {
1316
+ const committed = scope.read();
1317
+ if (committed !== null) return committed;
1318
+ }
1319
+ return router2.currentRoute;
1320
+ }
1321
+ var instanceScopes = /* @__PURE__ */ new WeakMap();
1322
+ async function instantiateScoped(router2, plan, routeDef, routePath, route2) {
1323
+ const scope = new RouteScope(route2);
1324
+ const node = await router2.instantiateComponent(plan, routeDef, routePath, scope);
1325
+ if (node) {
1326
+ instanceScopes.set(node, scope);
1327
+ registerDisposer(node, () => scope.release());
1328
+ }
1329
+ return node;
1330
+ }
1331
+ function updateInstanceRoute(node, route2) {
1332
+ if (node) instanceScopes.get(node)?.update(route2);
1333
+ }
1334
+ function disposeOwned(node) {
1335
+ const scope = instanceScopes.get(node);
1336
+ if (scope) runWithOwnerScope(scope, () => dispose(node));
1337
+ else dispose(node);
1338
+ }
1275
1339
  function route() {
1276
1340
  if (!_routerRef.current) throw new Error("Router not initialized. Call createRouter() first.");
1277
- return _routerRef.current.currentRoute;
1341
+ return scopedRoute(_routerRef.current);
1278
1342
  }
1279
1343
  function router() {
1280
1344
  if (!_routerRef.current) throw new Error("Router not initialized. Call createRouter() first.");
1281
1345
  return {
1282
- currentRoute: _routerRef.current.currentRoute,
1346
+ currentRoute: scopedRoute(_routerRef.current),
1283
1347
  isReady: _routerRef.current.isReady,
1284
1348
  isNavigating: _routerRef.current.isNavigating,
1285
1349
  push: (to) => _routerRef.current?.push(to),
@@ -1365,13 +1429,13 @@ function Route() {
1365
1429
  const commitTarget = (seq) => routeTorn || seq !== navSeq ? null : anchor.parentNode;
1366
1430
  const release = (node) => {
1367
1431
  if (!node) return;
1368
- dispose(node);
1432
+ disposeOwned(node);
1369
1433
  node.parentNode?.removeChild(node);
1370
1434
  };
1371
1435
  const cleanupNodes = () => {
1372
1436
  [currentNode, loadingNode, errorNode].forEach((node) => {
1373
1437
  if (!node) return;
1374
- dispose(node);
1438
+ disposeOwned(node);
1375
1439
  if (node.parentNode) {
1376
1440
  node.parentNode.removeChild(node);
1377
1441
  }
@@ -1447,7 +1511,7 @@ function Route() {
1447
1511
  const update = async () => {
1448
1512
  if (routeTorn || !_routerRef.current) return;
1449
1513
  const seq = ++navSeq;
1450
- const route2 = _routerRef.current.currentRoute;
1514
+ const route2 = scopedRoute(_routerRef.current);
1451
1515
  try {
1452
1516
  const match = _routerRef.current["matcher"].match(route2.path);
1453
1517
  if (!match) {
@@ -1459,6 +1523,7 @@ function Route() {
1459
1523
  const routeDef = match.matched[0] || match.route;
1460
1524
  const key = instanceKey(routeDef, [routeDef], route2);
1461
1525
  if (routeDef === currentTopRoute && key === currentKey && currentNode) {
1526
+ updateInstanceRoute(currentNode, route2);
1462
1527
  return;
1463
1528
  }
1464
1529
  if ("redirect" in routeDef) {
@@ -1478,7 +1543,7 @@ function Route() {
1478
1543
  }
1479
1544
  const plan = await _routerRef.current.loadPlan(routeDef, route2.path);
1480
1545
  if (!commitTarget(seq)) return;
1481
- const node = await _routerRef.current.instantiateComponent(plan, routeDef, route2.path);
1546
+ const node = await instantiateScoped(_routerRef.current, plan, routeDef, route2.path, route2);
1482
1547
  const parent = commitTarget(seq);
1483
1548
  if (!parent) {
1484
1549
  release(node);
@@ -1513,9 +1578,11 @@ function Route() {
1513
1578
  };
1514
1579
  const routeTeardown = track(wrappedUpdate);
1515
1580
  if (!routeInitialized) {
1516
- queueMicrotask(() => {
1517
- if (!routeInitialized && anchor.parentNode) wrappedUpdate();
1518
- });
1581
+ queueMicrotask(
1582
+ bindOwnerScope(() => {
1583
+ if (!routeInitialized && anchor.parentNode) wrappedUpdate();
1584
+ })
1585
+ );
1519
1586
  }
1520
1587
  const routeCleanup = () => {
1521
1588
  if (routeTorn) return;
@@ -1548,7 +1615,7 @@ function KeepAliveRoute(options) {
1548
1615
  if (kaTorn || !_routerRef.current) return;
1549
1616
  const seq = ++updateSeq;
1550
1617
  const router2 = _routerRef.current;
1551
- const route2 = router2.currentRoute;
1618
+ const route2 = scopedRoute(router2);
1552
1619
  const match = router2["matcher"].match(route2.path);
1553
1620
  if (!match) return;
1554
1621
  const { route: routeDef } = match;
@@ -1564,7 +1631,10 @@ function KeepAliveRoute(options) {
1564
1631
  if (!("component" in routeDef)) return;
1565
1632
  const cacheKey = JSON.stringify([route2.path, queryIdentity(route2.query), route2.hash]);
1566
1633
  const shouldCache = !includeNames || routeDef.name != null && includeNames.includes(routeDef.name);
1567
- if (cacheKey === currentKey && currentNode) return;
1634
+ if (cacheKey === currentKey && currentNode) {
1635
+ updateInstanceRoute(currentNode, route2);
1636
+ return;
1637
+ }
1568
1638
  if (!anchor.parentNode) return;
1569
1639
  let node = null;
1570
1640
  let fromCache = false;
@@ -1575,7 +1645,7 @@ function KeepAliveRoute(options) {
1575
1645
  try {
1576
1646
  const plan = await router2.loadPlan(routeDef, route2.path);
1577
1647
  if (kaTorn || seq !== updateSeq) return;
1578
- node = await router2.instantiateComponent(plan, routeDef, route2.path);
1648
+ node = await instantiateScoped(router2, plan, routeDef, route2.path, route2);
1579
1649
  } catch (error) {
1580
1650
  if (kaTorn || seq !== updateSeq) return;
1581
1651
  console.error("[KeepAliveRoute] Component error:", error);
@@ -1583,20 +1653,21 @@ function KeepAliveRoute(options) {
1583
1653
  }
1584
1654
  if (!node) return;
1585
1655
  if (kaTorn || seq !== updateSeq) {
1586
- dispose(node);
1656
+ disposeOwned(node);
1587
1657
  return;
1588
1658
  }
1589
1659
  }
1590
1660
  const parent = anchor.parentNode;
1591
1661
  if (!parent) {
1592
- if (!fromCache) dispose(node);
1662
+ if (!fromCache) disposeOwned(node);
1593
1663
  return;
1594
1664
  }
1595
1665
  if (currentNode && currentNode !== node) {
1596
1666
  if (currentNode.parentNode) currentNode.parentNode.removeChild(currentNode);
1597
- if (!currentCached) dispose(currentNode);
1667
+ if (!currentCached) disposeOwned(currentNode);
1598
1668
  }
1599
1669
  if (fromCache) {
1670
+ updateInstanceRoute(node, route2);
1600
1671
  const idx = lruOrder.indexOf(cacheKey);
1601
1672
  if (idx !== -1) lruOrder.splice(idx, 1);
1602
1673
  lruOrder.push(cacheKey);
@@ -1611,7 +1682,7 @@ function KeepAliveRoute(options) {
1611
1682
  }
1612
1683
  const evictNode = cache.get(evictKey);
1613
1684
  if (evictNode) {
1614
- dispose(evictNode);
1685
+ disposeOwned(evictNode);
1615
1686
  if (evictNode.parentNode) evictNode.parentNode.removeChild(evictNode);
1616
1687
  cache.delete(evictKey);
1617
1688
  }
@@ -1629,9 +1700,11 @@ function KeepAliveRoute(options) {
1629
1700
  };
1630
1701
  const kaTeardown = track(wrappedUpdate);
1631
1702
  if (!initialized) {
1632
- queueMicrotask(() => {
1633
- if (!initialized && anchor.parentNode) wrappedUpdate();
1634
- });
1703
+ queueMicrotask(
1704
+ bindOwnerScope(() => {
1705
+ if (!initialized && anchor.parentNode) wrappedUpdate();
1706
+ })
1707
+ );
1635
1708
  }
1636
1709
  const kaCleanup = () => {
1637
1710
  if (kaTorn) return;
@@ -1639,13 +1712,13 @@ function KeepAliveRoute(options) {
1639
1712
  updateSeq++;
1640
1713
  kaTeardown();
1641
1714
  for (const node of cache.values()) {
1642
- dispose(node);
1715
+ disposeOwned(node);
1643
1716
  if (node.parentNode) node.parentNode.removeChild(node);
1644
1717
  }
1645
1718
  cache.clear();
1646
1719
  lruOrder.length = 0;
1647
1720
  if (currentNode?.parentNode) currentNode.parentNode.removeChild(currentNode);
1648
- if (currentNode && !currentCached) dispose(currentNode);
1721
+ if (currentNode && !currentCached) disposeOwned(currentNode);
1649
1722
  currentNode = null;
1650
1723
  currentKey = "";
1651
1724
  currentCached = false;
@@ -1801,7 +1874,7 @@ function Suspense(props) {
1801
1874
  generation++;
1802
1875
  cleanupNodes();
1803
1876
  });
1804
- queueMicrotask(render);
1877
+ queueMicrotask(bindOwnerScope(render));
1805
1878
  return anchor;
1806
1879
  }
1807
1880
  var LAZY_MARKER = /* @__PURE__ */ Symbol.for("sibujs:lazy");
@@ -1869,7 +1942,7 @@ function Outlet() {
1869
1942
  let outletTorn = false;
1870
1943
  const clearCurrent = () => {
1871
1944
  if (currentNode) {
1872
- dispose(currentNode);
1945
+ disposeOwned(currentNode);
1873
1946
  if (currentNode.parentNode) currentNode.parentNode.removeChild(currentNode);
1874
1947
  currentNode = null;
1875
1948
  }
@@ -1879,13 +1952,13 @@ function Outlet() {
1879
1952
  const commitTarget = (seq) => outletTorn || seq !== navSeq ? null : anchor.parentNode;
1880
1953
  const release = (node) => {
1881
1954
  if (!node) return;
1882
- dispose(node);
1955
+ disposeOwned(node);
1883
1956
  node.parentNode?.removeChild(node);
1884
1957
  };
1885
1958
  const update = async () => {
1886
1959
  if (outletTorn || !_routerRef.current) return;
1887
1960
  const seq = ++navSeq;
1888
- const route2 = _routerRef.current.currentRoute;
1961
+ const route2 = scopedRoute(_routerRef.current);
1889
1962
  if (route2.matched.length < 2) {
1890
1963
  clearCurrent();
1891
1964
  return;
@@ -1896,12 +1969,15 @@ function Outlet() {
1896
1969
  return;
1897
1970
  }
1898
1971
  const key = instanceKey(childRoute, route2.matched.slice(1), route2);
1899
- if (childRoute === currentChild && key === currentKey && currentNode) return;
1972
+ if (childRoute === currentChild && key === currentKey && currentNode) {
1973
+ updateInstanceRoute(currentNode, route2);
1974
+ return;
1975
+ }
1900
1976
  try {
1901
1977
  const cacheKey = `${route2.path}\0${childRoute.path}`;
1902
1978
  const plan = await _routerRef.current.loadPlan(childRoute, cacheKey);
1903
1979
  if (!commitTarget(seq)) return;
1904
- const node = await _routerRef.current.instantiateComponent(plan, childRoute, cacheKey);
1980
+ const node = await instantiateScoped(_routerRef.current, plan, childRoute, cacheKey, route2);
1905
1981
  const parent = commitTarget(seq);
1906
1982
  if (!parent) {
1907
1983
  release(node);
@@ -1920,9 +1996,11 @@ function Outlet() {
1920
1996
  };
1921
1997
  const outletTeardown = track(update);
1922
1998
  if (!anchor.parentNode) {
1923
- queueMicrotask(() => {
1924
- if (anchor.parentNode) update();
1925
- });
1999
+ queueMicrotask(
2000
+ bindOwnerScope(() => {
2001
+ if (anchor.parentNode) update();
2002
+ })
2003
+ );
1926
2004
  }
1927
2005
  const outletCleanup = () => {
1928
2006
  if (outletTorn) return;
@@ -1930,7 +2008,7 @@ function Outlet() {
1930
2008
  navSeq++;
1931
2009
  outletTeardown();
1932
2010
  if (currentNode) {
1933
- dispose(currentNode);
2011
+ disposeOwned(currentNode);
1934
2012
  if (currentNode.parentNode) currentNode.parentNode.removeChild(currentNode);
1935
2013
  currentNode = null;
1936
2014
  }
@@ -1953,11 +2031,11 @@ function routerState() {
1953
2031
  if (!_routerRef.current) throw new Error("Router not initialized. Call createRouter() first.");
1954
2032
  const router2 = _routerRef.current;
1955
2033
  return {
1956
- currentPath: () => router2.currentRoute.path,
1957
- params: () => router2.currentRoute.params,
1958
- query: () => router2.currentRoute.query,
1959
- hash: () => router2.currentRoute.hash,
1960
- meta: () => router2.currentRoute.meta,
2034
+ currentPath: () => scopedRoute(router2).path,
2035
+ params: () => scopedRoute(router2).params,
2036
+ query: () => scopedRoute(router2).query,
2037
+ hash: () => scopedRoute(router2).hash,
2038
+ meta: () => scopedRoute(router2).meta,
1961
2039
  isNavigating: () => router2.isNavigating,
1962
2040
  isReady: () => router2.isReady
1963
2041
  };
package/dist/ssr.cjs CHANGED
@@ -1650,6 +1650,24 @@ function untracked(fn) {
1650
1650
  resumeTracking();
1651
1651
  }
1652
1652
  }
1653
+ var currentOwnerScope = null;
1654
+ function getOwnerScope() {
1655
+ return currentOwnerScope;
1656
+ }
1657
+ function runWithOwnerScope(scope, fn) {
1658
+ const prev = currentOwnerScope;
1659
+ currentOwnerScope = scope;
1660
+ try {
1661
+ return fn();
1662
+ } finally {
1663
+ currentOwnerScope = prev;
1664
+ }
1665
+ }
1666
+ function bindOwnerScope(fn) {
1667
+ const scope = currentOwnerScope;
1668
+ if (scope === null) return fn;
1669
+ return (...args) => runWithOwnerScope(scope, () => fn(...args));
1670
+ }
1653
1671
  var subscriberEpochCounter = 0;
1654
1672
  function retrack(effectFn, subscriber) {
1655
1673
  const prev = currentSubscriber;
@@ -1665,6 +1683,10 @@ function retrack(effectFn, subscriber) {
1665
1683
  currentSubscriber = subscriber;
1666
1684
  const sub2 = subscriber;
1667
1685
  if (sub2._cap === void 0) sub2._cap = currentDisposerCapture();
1686
+ const prevScope = currentOwnerScope;
1687
+ if (prevScope !== null && !sub2._epoch && sub2._scope === void 0) sub2._scope = prevScope;
1688
+ const scope = sub2._scope === void 0 ? null : sub2._scope;
1689
+ if (scope !== prevScope) currentOwnerScope = scope;
1668
1690
  const epoch = ++subscriberEpochCounter;
1669
1691
  sub2._epoch = epoch;
1670
1692
  sub2._structDirty = false;
@@ -1677,6 +1699,7 @@ function retrack(effectFn, subscriber) {
1677
1699
  effectFn();
1678
1700
  } finally {
1679
1701
  currentSubscriber = prev;
1702
+ currentOwnerScope = prevScope;
1680
1703
  if (savedDepth !== 0) {
1681
1704
  suspendDepth = savedDepth;
1682
1705
  suspendSavedSub = savedSuspendSub;
@@ -1711,23 +1734,26 @@ function track(effectFn, subscriber) {
1711
1734
  trackingSuspended = false;
1712
1735
  }
1713
1736
  currentSubscriber = subscriber;
1737
+ const sub2 = subscriber;
1738
+ if (sub2._scope === void 0) sub2._scope = currentOwnerScope;
1739
+ const prevScope = currentOwnerScope;
1740
+ currentOwnerScope = sub2._scope;
1714
1741
  try {
1715
1742
  effectFn();
1716
1743
  } finally {
1717
1744
  currentSubscriber = prev;
1745
+ currentOwnerScope = prevScope;
1718
1746
  if (savedDepth !== 0) {
1719
1747
  suspendDepth = savedDepth;
1720
1748
  suspendSavedSub = savedSuspendSub;
1721
1749
  trackingSuspended = true;
1722
1750
  }
1723
- const sub3 = subscriber;
1724
- for (let n = sub3.depsHead ?? null; n !== null; n = n.subNext) {
1751
+ for (let n = sub2.depsHead ?? null; n !== null; n = n.subNext) {
1725
1752
  const sig = n.sig;
1726
1753
  sig.__activeNode = n.prevActive;
1727
1754
  n.prevActive = null;
1728
1755
  }
1729
1756
  }
1730
- const sub2 = subscriber;
1731
1757
  return sub2._dispose ?? (sub2._dispose = () => cleanup(subscriber));
1732
1758
  }
1733
1759
  function reactiveBinding(commit, ownerNode) {
@@ -1997,7 +2023,7 @@ function forEachSubscriber(signal2, visit) {
1997
2023
  }
1998
2024
 
1999
2025
  // src/reactivity/track.ts
2000
- var _runtimeVersion = true ? "4.9.0" : "dev";
2026
+ var _runtimeVersion = true ? "4.10.0" : "dev";
2001
2027
  var REGISTRY_KEY = /* @__PURE__ */ Symbol.for("sibujs.reactive.v1");
2002
2028
  function resolveReactiveApi() {
2003
2029
  const g2 = globalThis;
@@ -2029,6 +2055,9 @@ function resolveReactiveApi() {
2029
2055
  getSubscriberCount,
2030
2056
  getSubscriberDeps,
2031
2057
  forEachSubscriber,
2058
+ getOwnerScope,
2059
+ runWithOwnerScope,
2060
+ bindOwnerScope,
2032
2061
  version: _runtimeVersion
2033
2062
  };
2034
2063
  g2[REGISTRY_KEY] = local;
@@ -2052,6 +2081,9 @@ var notifySubscribers2 = API.notifySubscribers;
2052
2081
  var getSubscriberCount2 = API.getSubscriberCount;
2053
2082
  var getSubscriberDeps2 = API.getSubscriberDeps;
2054
2083
  var forEachSubscriber2 = API.forEachSubscriber;
2084
+ var getOwnerScope2 = API.getOwnerScope ?? getOwnerScope;
2085
+ var runWithOwnerScope2 = API.runWithOwnerScope ?? runWithOwnerScope;
2086
+ var bindOwnerScope2 = API.bindOwnerScope ?? bindOwnerScope;
2055
2087
 
2056
2088
  // src/core/devtoolsHook.ts
2057
2089
  function emitDevtools(hook, event, payload) {
@@ -2068,6 +2100,11 @@ function flushUserCleanups(ctx) {
2068
2100
  const list = ctx.userCleanups;
2069
2101
  if (list.length === 0) return;
2070
2102
  ctx.userCleanups = [];
2103
+ const scope = ctx.subscriber._scope ?? null;
2104
+ if (scope === getOwnerScope2()) runCleanups(list);
2105
+ else runWithOwnerScope2(scope, () => runCleanups(list));
2106
+ }
2107
+ function runCleanups(list) {
2071
2108
  for (let i2 = list.length - 1; i2 >= 0; i2--) {
2072
2109
  try {
2073
2110
  list[i2]();
@@ -3623,11 +3660,15 @@ function defineRemoteComponent(name, loader) {
3623
3660
  registerDisposer(container, () => {
3624
3661
  disposed = true;
3625
3662
  });
3626
- loader().then((mod) => {
3627
- cached = mod.default;
3628
- if (disposed) return;
3629
- replaceChildrenSafely(container, cached());
3630
- }).catch((err) => {
3663
+ loader().then(
3664
+ // Instantiated after the module resolves, in the owner scope of the
3665
+ // render that asked for it — as `lazy()` does.
3666
+ bindOwnerScope2((mod) => {
3667
+ cached = mod.default;
3668
+ if (disposed) return;
3669
+ replaceChildrenSafely(container, cached());
3670
+ })
3671
+ ).catch((err) => {
3631
3672
  if (disposed) return;
3632
3673
  const message = err instanceof Error ? err.message : String(err);
3633
3674
  replaceChildrenSafely(
package/dist/ssr.js CHANGED
@@ -23,9 +23,9 @@ import {
23
23
  wasm,
24
24
  worker,
25
25
  workerFn
26
- } from "./chunk-KG25XMGP.js";
26
+ } from "./chunk-4DCVJ4YA.js";
27
27
  import "./chunk-52XFPGSN.js";
28
- import "./chunk-QBKCK6MJ.js";
28
+ import "./chunk-N6U4GOIU.js";
29
29
  import {
30
30
  collectStream,
31
31
  deserializeState,
@@ -47,15 +47,15 @@ import {
47
47
  trustHTML
48
48
  } from "./chunk-FC6KCJSA.js";
49
49
  import "./chunk-62BDYGAG.js";
50
- import "./chunk-5MLWTIQE.js";
51
- import "./chunk-MPWDSTYK.js";
50
+ import "./chunk-EVI4ZQO3.js";
51
+ import "./chunk-XUQUQJYE.js";
52
52
  import "./chunk-3ACAAQIN.js";
53
53
  import "./chunk-7ZHH77QA.js";
54
- import "./chunk-SBTZEYNI.js";
54
+ import "./chunk-7WIHYHWD.js";
55
55
  import "./chunk-EXXSN3BW.js";
56
56
  import "./chunk-7XHATCIH.js";
57
- import "./chunk-SYHGGDNW.js";
58
- import "./chunk-G2WHYEL7.js";
57
+ import "./chunk-FYUEL5IW.js";
58
+ import "./chunk-D6HYFOWR.js";
59
59
  import "./chunk-NYNYSPK7.js";
60
60
  export {
61
61
  Head,