sibujs 4.13.0 → 4.14.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 (107) hide show
  1. package/README.md +1 -1
  2. package/dist/browser.cjs +15 -2
  3. package/dist/browser.js +9 -7
  4. package/dist/build.cjs +880 -281
  5. package/dist/build.d.cts +68 -3
  6. package/dist/build.d.ts +68 -3
  7. package/dist/build.js +88 -30
  8. package/dist/cdn.dev.global.js +12 -12
  9. package/dist/cdn.full.dev.global.js +13 -13
  10. package/dist/cdn.full.global.js +12 -12
  11. package/dist/cdn.global.js +12 -12
  12. package/dist/{chunk-7K7W4AA5.js → chunk-2TTRW2TE.js} +6 -6
  13. package/dist/{chunk-J6FW5TV6.js → chunk-3HEX6QJQ.js} +5 -3
  14. package/dist/chunk-3HZOSMPX.js +90 -0
  15. package/dist/{chunk-GNSRXK34.js → chunk-4FJSAUKB.js} +11 -3
  16. package/dist/{chunk-IV74C2YX.js → chunk-4TQDTWWN.js} +6 -5
  17. package/dist/{chunk-L3QHS4O4.js → chunk-7ILEHTVX.js} +1 -1
  18. package/dist/{chunk-CK5F2IR5.js → chunk-A454RAEK.js} +4 -4
  19. package/dist/{chunk-BRRRVLHQ.js → chunk-AE32RGWX.js} +10 -6
  20. package/dist/{chunk-EXXSN3BW.js → chunk-B3HOT4TK.js} +1 -1
  21. package/dist/{chunk-F4W7WYXY.js → chunk-BKZ5N6NK.js} +8 -6
  22. package/dist/{chunk-MNEITZ27.js → chunk-BNXRWZZV.js} +49 -8
  23. package/dist/chunk-BOYKGGVD.js +2015 -0
  24. package/dist/{chunk-G6366I2A.js → chunk-CCKUNHVU.js} +2 -2
  25. package/dist/{chunk-346BYZL2.js → chunk-CJ7KS3DF.js} +16 -10
  26. package/dist/chunk-CNPT6NKV.js +1859 -0
  27. package/dist/{chunk-ENFRHCMK.js → chunk-F67F77IA.js} +2 -2
  28. package/dist/{chunk-TUCPL2HB.js → chunk-GIJ33UJZ.js} +1 -1
  29. package/dist/chunk-GVAMIU6K.js +195 -0
  30. package/dist/{chunk-HDKDBC6V.js → chunk-HQIAL7F2.js} +8 -6
  31. package/dist/{chunk-ZE5LF44R.js → chunk-JTFQ7IL4.js} +8 -8
  32. package/dist/{chunk-AM6DZLBM.js → chunk-LJMX4SQ7.js} +2 -2
  33. package/dist/{chunk-HVVRXRGO.js → chunk-MIRKTVH4.js} +7 -14
  34. package/dist/{chunk-YJ57VR6Y.js → chunk-N7A6FKWW.js} +5 -3
  35. package/dist/chunk-NT3ZYB5S.js +167 -0
  36. package/dist/{chunk-Z3EZX6DZ.js → chunk-QS6GMWDD.js} +151 -86
  37. package/dist/chunk-R5U7XKVJ.js +16 -0
  38. package/dist/{chunk-3C56VNCK.js → chunk-RVR5NPFL.js} +3 -3
  39. package/dist/{chunk-F2UWOZ6J.js → chunk-RVWJGWCL.js} +2 -2
  40. package/dist/{chunk-NYNYSPK7.js → chunk-S37PZD6I.js} +30 -45
  41. package/dist/{chunk-QV5WEOFD.js → chunk-SVULV7O4.js} +119 -26
  42. package/dist/{chunk-C2FAO6VQ.js → chunk-TLS4NVIB.js} +5 -5
  43. package/dist/{chunk-M25RIH6Y.js → chunk-UUIKJJIK.js} +10 -8
  44. package/dist/chunk-UYTYNCMZ.js +199 -0
  45. package/dist/chunk-VM2U5LEL.js +2596 -0
  46. package/dist/{chunk-24L5RDPS.js → chunk-Y4LUM2XS.js} +8 -6
  47. package/dist/data.cjs +265 -35
  48. package/dist/data.d.cts +31 -1
  49. package/dist/data.d.ts +31 -1
  50. package/dist/data.js +16 -10
  51. package/dist/devtools.cjs +15 -2
  52. package/dist/devtools.js +9 -7
  53. package/dist/{dispose-GEIG2KOF.js → dispose-EIHHHDC7.js} +3 -1
  54. package/dist/ecosystem.cjs +62 -23
  55. package/dist/ecosystem.js +14 -12
  56. package/dist/extras.cjs +3520 -270
  57. package/dist/extras.d.cts +3 -3
  58. package/dist/extras.d.ts +3 -3
  59. package/dist/extras.js +39 -29
  60. package/dist/index.cjs +442 -253
  61. package/dist/index.d.cts +93 -283
  62. package/dist/index.d.ts +93 -283
  63. package/dist/index.js +26 -16
  64. package/dist/motion.cjs +12 -1
  65. package/dist/motion.js +6 -4
  66. package/dist/patterns.cjs +15 -2
  67. package/dist/patterns.js +10 -8
  68. package/dist/performance.cjs +36 -2
  69. package/dist/performance.d.cts +2 -2
  70. package/dist/performance.d.ts +2 -2
  71. package/dist/performance.js +14 -10
  72. package/dist/plugins.cjs +5225 -1807
  73. package/dist/plugins.d.cts +8 -834
  74. package/dist/plugins.d.ts +8 -834
  75. package/dist/plugins.js +64 -2329
  76. package/dist/prerenderServer-MXJEVWA3.js +350 -0
  77. package/dist/renderRoute-DP20XwMS.d.cts +86 -0
  78. package/dist/renderRoute-fxgsm2Ir.d.ts +86 -0
  79. package/dist/routeHead-CE9SV-cH.d.cts +995 -0
  80. package/dist/routeHead-DzVxPviY.d.ts +995 -0
  81. package/dist/{routeMiddleware-B1sp4P7a.d.ts → routeMiddleware-BySbueoE.d.ts} +0 -25
  82. package/dist/{routeMiddleware-CedQTsLK.d.cts → routeMiddleware-CijZD5eW.d.cts} +0 -25
  83. package/dist/ssr-JpGpHnpC.d.cts +841 -0
  84. package/dist/ssr-JpGpHnpC.d.ts +841 -0
  85. package/dist/{ssr-VBM6J5SJ.js → ssr-NECEU4X4.js} +15 -6
  86. package/dist/ssr-dom.cjs +1862 -0
  87. package/dist/ssr-dom.d.cts +341 -0
  88. package/dist/ssr-dom.d.ts +341 -0
  89. package/dist/ssr-dom.js +19 -0
  90. package/dist/ssr.cjs +7630 -2064
  91. package/dist/ssr.d.cts +63 -5
  92. package/dist/ssr.d.ts +63 -5
  93. package/dist/ssr.js +136 -14
  94. package/dist/testing.cjs +6543 -87
  95. package/dist/testing.d.cts +80 -1
  96. package/dist/testing.d.ts +80 -1
  97. package/dist/testing.js +117 -4
  98. package/dist/ui.cjs +36 -2
  99. package/dist/ui.js +17 -14
  100. package/dist/widgets.cjs +14 -1
  101. package/dist/widgets.js +11 -9
  102. package/package.json +9 -2
  103. package/dist/chunk-2F4PSJ5Z.js +0 -765
  104. package/dist/chunk-7XHATCIH.js +0 -121
  105. package/dist/chunk-B36ADEIR.js +0 -21
  106. package/dist/ssr-Db0Sgdu3.d.cts +0 -245
  107. package/dist/ssr-Db0Sgdu3.d.ts +0 -245
@@ -1,28 +1,36 @@
1
+ import {
2
+ registerTransferCollector,
3
+ takeTransferred,
4
+ takeTransferredSection
5
+ } from "./chunk-3HZOSMPX.js";
1
6
  import {
2
7
  derived
3
- } from "./chunk-YJ57VR6Y.js";
8
+ } from "./chunk-N7A6FKWW.js";
4
9
  import {
5
10
  globalSingleton
6
11
  } from "./chunk-7ZHH77QA.js";
7
12
  import {
8
13
  effect
9
- } from "./chunk-BRRRVLHQ.js";
14
+ } from "./chunk-AE32RGWX.js";
10
15
  import {
11
16
  sanitizeUrl
12
- } from "./chunk-EXXSN3BW.js";
17
+ } from "./chunk-B3HOT4TK.js";
13
18
  import {
14
- getRequestScopedCache
15
- } from "./chunk-7XHATCIH.js";
19
+ getRequestScopedCache,
20
+ isSSR,
21
+ requestSlot,
22
+ trackPending
23
+ } from "./chunk-UYTYNCMZ.js";
16
24
  import {
17
25
  batch,
18
26
  signal
19
- } from "./chunk-GNSRXK34.js";
27
+ } from "./chunk-4FJSAUKB.js";
20
28
  import {
21
29
  untracked
22
- } from "./chunk-HVVRXRGO.js";
30
+ } from "./chunk-MIRKTVH4.js";
23
31
  import {
24
32
  reportError
25
- } from "./chunk-NYNYSPK7.js";
33
+ } from "./chunk-S37PZD6I.js";
26
34
 
27
35
  // src/data/abort.ts
28
36
  function isAbortError(error) {
@@ -218,8 +226,34 @@ function sharedView(entry) {
218
226
  }
219
227
  var globalQueryCache = globalSingleton(/* @__PURE__ */ Symbol.for("sibujs.query.cache.v1"), () => /* @__PURE__ */ new Map());
220
228
  function getActiveQueryCache() {
221
- return getRequestScopedCache("query") ?? globalQueryCache;
229
+ const requestCache = getRequestScopedCache("query");
230
+ if (requestCache) return requestCache;
231
+ primeFromTransfer();
232
+ return globalQueryCache;
233
+ }
234
+ var SERVER_EFFECT = { server: true };
235
+ function primeFromTransfer() {
236
+ const entries = takeTransferredSection("q");
237
+ const now = Date.now();
238
+ for (const key of Object.keys(entries)) {
239
+ const record = entries[key];
240
+ if (!record || typeof record !== "object" || record.d === void 0) continue;
241
+ if (globalQueryCache.has(key)) continue;
242
+ const entry = getOrCreateEntry(globalQueryCache, key, record.d);
243
+ const t = typeof record.t === "number" && Number.isFinite(record.t) ? record.t : now;
244
+ entry.dataUpdatedAt = Math.min(t, now);
245
+ }
222
246
  }
247
+ registerTransferCollector("q", () => {
248
+ const cache = getRequestScopedCache("query");
249
+ if (!cache) return void 0;
250
+ const out = {};
251
+ for (const [key, entry] of cache) {
252
+ if (entry.noTransfer || entry.data === void 0 || entry.error) continue;
253
+ out[key] = { d: entry.data, t: entry.dataUpdatedAt };
254
+ }
255
+ return out;
256
+ });
223
257
  function abandonEntry(entry) {
224
258
  if (entry.gcTimer) clearTimeout(entry.gcTimer);
225
259
  entry.gcTimer = null;
@@ -265,11 +299,13 @@ function query(key, fetcher, options = {}) {
265
299
  onError,
266
300
  onSettled,
267
301
  select,
268
- structuralSharing = true
302
+ structuralSharing = true,
303
+ ssr = true
269
304
  } = options;
305
+ const onServer = isSSR();
270
306
  const resolveKey = typeof key === "function" ? key : () => key;
271
307
  const enabledGate = typeof enabled === "function" ? derived(() => Boolean(enabled())) : null;
272
- const isEnabled = enabledGate ?? (() => Boolean(enabled));
308
+ const isEnabled = onServer && !ssr ? () => false : enabledGate ?? (() => Boolean(enabled));
273
309
  const cache = getActiveQueryCache();
274
310
  const [data, setData] = signal(initialData);
275
311
  const [isFetching, setIsFetching] = signal(false);
@@ -343,7 +379,7 @@ function query(key, fetcher, options = {}) {
343
379
  selectedEntry = entry;
344
380
  selectedValue = value;
345
381
  setData(value);
346
- }) : null;
382
+ }, SERVER_EFFECT) : null;
347
383
  function detachFromEntry() {
348
384
  const entry = attachedEntry;
349
385
  const key2 = attachedKey;
@@ -426,7 +462,7 @@ function query(key, fetcher, options = {}) {
426
462
  runCallback("query onSettled", () => onSettled?.());
427
463
  return;
428
464
  }
429
- entry.promise = promise;
465
+ entry.promise = trackPending(promise, `query:${key2}`, false);
430
466
  try {
431
467
  const result = await promise;
432
468
  if (entry.generation !== generation) return;
@@ -498,6 +534,7 @@ function query(key, fetcher, options = {}) {
498
534
  return;
499
535
  }
500
536
  const entry = getOrCreateEntry(cache, key2, initialData);
537
+ if (!ssr) entry.noTransfer = true;
501
538
  const reattached = attachedEntry !== entry;
502
539
  attachToEntry(entry, key2);
503
540
  if (keyChanged) setIsFetching(entry.promise !== null);
@@ -519,15 +556,15 @@ function query(key, fetcher, options = {}) {
519
556
  if (on && (entry.data === void 0 || isDataStale)) {
520
557
  doFetch();
521
558
  }
522
- });
523
- if (refetchInterval && refetchInterval > 0) {
559
+ }, SERVER_EFFECT);
560
+ if (!onServer && refetchInterval && refetchInterval > 0) {
524
561
  intervalTimer = setInterval(() => {
525
562
  if (!disposed && currentKey) doFetch();
526
563
  }, refetchInterval);
527
564
  }
528
565
  let focusHandler = null;
529
566
  let onlineHandler = null;
530
- if (typeof globalThis !== "undefined" && typeof globalThis.addEventListener === "function") {
567
+ if (!onServer && typeof globalThis !== "undefined" && typeof globalThis.addEventListener === "function") {
531
568
  if (refetchOnWindowFocus) {
532
569
  focusHandler = () => {
533
570
  if (!disposed && currentKey) doFetch();
@@ -956,6 +993,28 @@ function throttle(getter, interval) {
956
993
  }
957
994
 
958
995
  // src/data/resource.ts
996
+ function transferSlot() {
997
+ return requestSlot("resource:transfer", () => /* @__PURE__ */ new Map());
998
+ }
999
+ function withheldSlot() {
1000
+ return requestSlot("resource:transfer:withheld", () => /* @__PURE__ */ new Set());
1001
+ }
1002
+ registerTransferCollector("r", () => {
1003
+ const slot = transferSlot();
1004
+ if (!slot || slot.size === 0) return void 0;
1005
+ const withheld = withheldSlot();
1006
+ const out = {};
1007
+ let any = false;
1008
+ for (const [key, value] of slot) {
1009
+ if (withheld?.has(key)) continue;
1010
+ out[key] = value;
1011
+ any = true;
1012
+ }
1013
+ return any ? out : void 0;
1014
+ });
1015
+ function withholdTransfer(key) {
1016
+ withheldSlot()?.add(key);
1017
+ }
959
1018
  function resource(sourceOrFetcher, fetcherOrOptions, maybeOptions) {
960
1019
  let source = null;
961
1020
  let fetcher;
@@ -969,10 +1028,14 @@ function resource(sourceOrFetcher, fetcherOrOptions, maybeOptions) {
969
1028
  fetcher = (_source, info) => rawFetcher(info);
970
1029
  options = fetcherOrOptions ?? {};
971
1030
  }
972
- const [data, setData] = signal(options.initialValue);
1031
+ const transferred = options.key !== void 0 ? takeTransferred("r", options.key) : void 0;
1032
+ const hydrated = transferred !== void 0;
1033
+ const initialValue = hydrated ? transferred : options.initialValue;
1034
+ const onServer = isSSR();
1035
+ const [data, setData] = signal(initialValue);
973
1036
  const [loading, setLoading] = signal(false);
974
1037
  const [error, setError] = signal(void 0);
975
- let currentData = options.initialValue;
1038
+ let currentData = initialValue;
976
1039
  function commitData(next, explicit) {
977
1040
  const sharing = options.structuralSharing ?? true;
978
1041
  const shared = untracked(
@@ -980,6 +1043,7 @@ function resource(sourceOrFetcher, fetcherOrOptions, maybeOptions) {
980
1043
  );
981
1044
  currentData = shared.ok ? shared.value : next;
982
1045
  setData(currentData);
1046
+ if (onServer && options.key !== void 0) transferSlot()?.set(options.key, currentData);
983
1047
  return currentData;
984
1048
  }
985
1049
  let abortController = null;
@@ -1025,19 +1089,28 @@ function resource(sourceOrFetcher, fetcherOrOptions, maybeOptions) {
1025
1089
  }
1026
1090
  }
1027
1091
  }
1092
+ const run = (sourceValue) => trackPending(doFetch(sourceValue), "resource", false);
1028
1093
  if (source) {
1029
- effectCleanup = effect(() => {
1030
- const sourceValue = source();
1031
- doFetch(sourceValue);
1032
- });
1033
- } else if (options.immediate !== false) {
1034
- doFetch(void 0);
1094
+ let skipFirst = hydrated;
1095
+ effectCleanup = effect(
1096
+ () => {
1097
+ const sourceValue = source();
1098
+ if (skipFirst) {
1099
+ skipFirst = false;
1100
+ return;
1101
+ }
1102
+ run(sourceValue);
1103
+ },
1104
+ { server: true }
1105
+ );
1106
+ } else if (options.immediate !== false && !hydrated) {
1107
+ run(void 0);
1035
1108
  }
1036
1109
  return {
1037
1110
  data,
1038
1111
  loading,
1039
1112
  error,
1040
- refetch: () => doFetch(source ? source() : void 0),
1113
+ refetch: () => run(source ? source() : void 0),
1041
1114
  mutate: (value) => {
1042
1115
  const newValue = typeof value === "function" ? value(currentData) : value;
1043
1116
  commitData(newValue, true);
@@ -1338,8 +1411,27 @@ function currentScope() {
1338
1411
  }
1339
1412
  return scope;
1340
1413
  }
1414
+ function automaticKey(loader, context) {
1415
+ const key = `loader:${context.path}${loader.name ? `:${loader.name}` : ""}`;
1416
+ const cache = getRequestScopedCache("routeLoader");
1417
+ if (!cache) return key;
1418
+ let owners = cache.get("owners");
1419
+ if (!owners) {
1420
+ owners = /* @__PURE__ */ new Map();
1421
+ cache.set("owners", owners);
1422
+ }
1423
+ const owner = owners.get(key);
1424
+ if (owner === void 0) {
1425
+ owners.set(key, loader);
1426
+ return key;
1427
+ }
1428
+ if (owner === loader) return key;
1429
+ withholdTransfer(key);
1430
+ return void 0;
1431
+ }
1341
1432
  function executeLoader(loader, context, options) {
1342
- const res = resource(({ signal: signal2 }) => loader(context, { signal: signal2 }), options);
1433
+ const key = options?.key ?? automaticKey(loader, context);
1434
+ const res = resource(({ signal: signal2 }) => loader(context, { signal: signal2 }), { ...options, key });
1343
1435
  const disposeResource = res.dispose;
1344
1436
  res.dispose = () => {
1345
1437
  _disposed.add(res);
@@ -1667,6 +1759,7 @@ export {
1667
1759
  previous,
1668
1760
  debounce,
1669
1761
  throttle,
1762
+ withholdTransfer,
1670
1763
  resource,
1671
1764
  offlineStore,
1672
1765
  syncAdapter,
@@ -4,22 +4,22 @@ import {
4
4
  } from "./chunk-N5TBYXHW.js";
5
5
  import {
6
6
  watch
7
- } from "./chunk-3C56VNCK.js";
7
+ } from "./chunk-RVR5NPFL.js";
8
8
  import {
9
9
  createId,
10
10
  domBinding,
11
11
  idSegment
12
- } from "./chunk-G6366I2A.js";
12
+ } from "./chunk-CCKUNHVU.js";
13
13
  import {
14
14
  derived
15
- } from "./chunk-YJ57VR6Y.js";
15
+ } from "./chunk-N7A6FKWW.js";
16
16
  import {
17
17
  stripHtml
18
- } from "./chunk-EXXSN3BW.js";
18
+ } from "./chunk-B3HOT4TK.js";
19
19
  import {
20
20
  batch,
21
21
  signal
22
- } from "./chunk-GNSRXK34.js";
22
+ } from "./chunk-4FJSAUKB.js";
23
23
 
24
24
  // src/widgets/Combobox.ts
25
25
  var boundComboboxes = /* @__PURE__ */ new WeakMap();
@@ -1,29 +1,31 @@
1
1
  import {
2
2
  isBlockedElement
3
- } from "./chunk-F2UWOZ6J.js";
3
+ } from "./chunk-RVWJGWCL.js";
4
4
  import {
5
5
  globalSingleton
6
6
  } from "./chunk-7ZHH77QA.js";
7
7
  import {
8
8
  effect
9
- } from "./chunk-BRRRVLHQ.js";
9
+ } from "./chunk-AE32RGWX.js";
10
10
  import {
11
11
  sanitizeUrl
12
- } from "./chunk-EXXSN3BW.js";
12
+ } from "./chunk-B3HOT4TK.js";
13
13
  import {
14
14
  signal
15
- } from "./chunk-GNSRXK34.js";
15
+ } from "./chunk-4FJSAUKB.js";
16
16
  import {
17
17
  bindOwnerScope
18
- } from "./chunk-HVVRXRGO.js";
18
+ } from "./chunk-MIRKTVH4.js";
19
19
  import {
20
- DEV,
21
- devWarn,
22
20
  dispose,
23
21
  registerDisposer,
24
22
  replaceChildrenSafely,
25
23
  reportError
26
- } from "./chunk-NYNYSPK7.js";
24
+ } from "./chunk-S37PZD6I.js";
25
+ import {
26
+ DEV,
27
+ devWarn
28
+ } from "./chunk-NT3ZYB5S.js";
27
29
 
28
30
  // src/performance/scheduler.ts
29
31
  var Priority = {
@@ -0,0 +1,199 @@
1
+ import {
2
+ devWarn,
3
+ holdHydration,
4
+ hydrationOwners
5
+ } from "./chunk-NT3ZYB5S.js";
6
+ import {
7
+ __require
8
+ } from "./chunk-R5U7XKVJ.js";
9
+
10
+ // src/core/rendering/streamBoundary.ts
11
+ var _a;
12
+ var slot = globalThis[_a = /* @__PURE__ */ Symbol.for("sibujs.streamBoundary.v1")] ?? (globalThis[_a] = { hook: null, current: null });
13
+ function openBoundary(container) {
14
+ return slot.hook ? slot.hook(container) : null;
15
+ }
16
+ function currentBoundary() {
17
+ return slot.current;
18
+ }
19
+ function runInBoundary(boundary, fn) {
20
+ const prev = slot.current;
21
+ slot.current = boundary;
22
+ try {
23
+ return fn();
24
+ } finally {
25
+ slot.current = prev;
26
+ }
27
+ }
28
+ function setBoundaryHook(hook) {
29
+ slot.hook = hook;
30
+ }
31
+
32
+ // src/core/ssr-context.ts
33
+ var SSR_KEY = /* @__PURE__ */ Symbol.for("sibujs.ssr.v1");
34
+ function detectSSRShared() {
35
+ let detected = null;
36
+ try {
37
+ if (typeof process !== "undefined" && process.versions && process.versions.node) {
38
+ let mod = null;
39
+ const getBuiltin = process.getBuiltinModule;
40
+ if (typeof getBuiltin === "function") {
41
+ mod = getBuiltin("node:async_hooks");
42
+ } else if (typeof __require === "function") {
43
+ mod = __require("async_hooks");
44
+ }
45
+ if (mod) detected = new mod.AsyncLocalStorage();
46
+ }
47
+ const globalAls = globalThis.AsyncLocalStorage;
48
+ if (!detected && typeof globalAls === "function") detected = new globalAls();
49
+ } catch {
50
+ detected = null;
51
+ }
52
+ return {
53
+ als: detected,
54
+ fallbackStore: { ssr: false, suspenseIdCounter: 0, locale: void 0 },
55
+ fallbackDepth: 0
56
+ };
57
+ }
58
+ var _shared = globalThis[SSR_KEY] ?? (globalThis[SSR_KEY] = detectSSRShared());
59
+ var als = _shared.als;
60
+ var fallbackStore = _shared.fallbackStore;
61
+ _shared.fallbackDepth ?? (_shared.fallbackDepth = 0);
62
+ var _alsWarned = false;
63
+ function warnMissingAsyncLocalStorage() {
64
+ if (_alsWarned || als) return;
65
+ const isNode = typeof process !== "undefined" && !!process.versions?.node;
66
+ if (!isNode) return;
67
+ _alsWarned = true;
68
+ const version = process.versions.node;
69
+ devWarn(
70
+ `SSR request isolation is UNAVAILABLE on this runtime (Node ${version}). AsyncLocalStorage could not be loaded, so concurrent requests share one SSR store: request state and the query cache can bleed between them. Node >= 22.3 is required for isolated SSR under ESM; the CommonJS build works on older versions. A fully synchronous render is unaffected.`
71
+ );
72
+ }
73
+ function assertRequestIsolation(api) {
74
+ if (als || typeof window !== "undefined") return;
75
+ throw new Error(
76
+ `[SibuJS SSR] ${api} needs AsyncLocalStorage to keep concurrent requests apart, and this runtime has none. Use Node >= 22.3 (or the CommonJS build on older Node), Deno or Bun, or enable AsyncLocalStorage on your edge runtime (Cloudflare Workers: the nodejs_compat flag).`
77
+ );
78
+ }
79
+ function getSSRStore() {
80
+ if (als) {
81
+ const s = als.getStore();
82
+ if (s) return s;
83
+ }
84
+ return fallbackStore;
85
+ }
86
+ function getRequestStore() {
87
+ if (als) return als.getStore() ?? null;
88
+ return _shared.fallbackDepth > 0 ? fallbackStore : null;
89
+ }
90
+ function isSSR() {
91
+ return getSSRStore().ssr;
92
+ }
93
+ function getRequestScopedCache(name) {
94
+ if (!isSSR()) return null;
95
+ const store = getSSRStore();
96
+ const caches = store.caches ?? (store.caches = /* @__PURE__ */ new Map());
97
+ let c = caches.get(name);
98
+ if (!c) {
99
+ c = /* @__PURE__ */ new Map();
100
+ caches.set(name, c);
101
+ }
102
+ return c;
103
+ }
104
+ function requestSlot(name, create) {
105
+ const store = getRequestStore();
106
+ if (!store) return void 0;
107
+ const slots = store.slots ?? (store.slots = /* @__PURE__ */ new Map());
108
+ if (!slots.has(name) && create) slots.set(name, create());
109
+ return slots.get(name);
110
+ }
111
+ var PRERENDER_HOST = /* @__PURE__ */ Symbol.for("sibujs.prerender.v1");
112
+ function isServer() {
113
+ return getSSRStore().ssr || globalThis[PRERENDER_HOST] !== void 0;
114
+ }
115
+ function isClient() {
116
+ return !isServer();
117
+ }
118
+ function enableSSR() {
119
+ getSSRStore().ssr = true;
120
+ }
121
+ function disableSSR() {
122
+ getSSRStore().ssr = false;
123
+ }
124
+ function runInSSRContext(fn) {
125
+ const store = {
126
+ ssr: true,
127
+ suspenseIdCounter: 0,
128
+ idCounter: 0,
129
+ locale: void 0,
130
+ pending: /* @__PURE__ */ new Set(),
131
+ wake: null
132
+ };
133
+ if (als) {
134
+ return als.run(store, fn);
135
+ }
136
+ warnMissingAsyncLocalStorage();
137
+ const prev = { ...fallbackStore };
138
+ Object.assign(fallbackStore, store);
139
+ _shared.fallbackDepth++;
140
+ try {
141
+ return fn();
142
+ } finally {
143
+ _shared.fallbackDepth--;
144
+ for (const key of Object.keys(fallbackStore)) {
145
+ if (!(key in prev)) delete fallbackStore[key];
146
+ }
147
+ Object.assign(fallbackStore, prev);
148
+ }
149
+ }
150
+ function trackPending(promise, label, hydration = true) {
151
+ const store = getRequestStore();
152
+ const pending = store?.pending;
153
+ const sessions = pending || !hydration ? [] : hydrationOwners();
154
+ if (!pending && sessions.length === 0) return promise;
155
+ const entry = { label, since: Date.now(), boundary: currentBoundary() ?? void 0 };
156
+ pending?.add(entry);
157
+ const release = holdHydration(sessions, entry);
158
+ const done = () => {
159
+ pending?.delete(entry);
160
+ store?.wake?.();
161
+ release();
162
+ };
163
+ try {
164
+ Promise.resolve(promise).then(done, done);
165
+ } catch {
166
+ done();
167
+ }
168
+ return promise;
169
+ }
170
+ function withSSR(fn) {
171
+ const store = getSSRStore();
172
+ const wasSSR = store.ssr;
173
+ store.ssr = true;
174
+ try {
175
+ return fn();
176
+ } finally {
177
+ if (!wasSSR) store.ssr = false;
178
+ }
179
+ }
180
+
181
+ export {
182
+ openBoundary,
183
+ currentBoundary,
184
+ runInBoundary,
185
+ setBoundaryHook,
186
+ assertRequestIsolation,
187
+ getSSRStore,
188
+ getRequestStore,
189
+ isSSR,
190
+ getRequestScopedCache,
191
+ requestSlot,
192
+ isServer,
193
+ isClient,
194
+ enableSSR,
195
+ disableSSR,
196
+ runInSSRContext,
197
+ trackPending,
198
+ withSSR
199
+ };