@fictjs/runtime 0.17.0 → 0.17.1

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 (64) hide show
  1. package/dist/advanced.cjs +9 -9
  2. package/dist/advanced.d.cts +3 -3
  3. package/dist/advanced.d.ts +3 -3
  4. package/dist/advanced.js +4 -4
  5. package/dist/{binding-CQUGLLBI.d.ts → binding-BfzY9rae.d.ts} +2 -2
  6. package/dist/{binding-BlABuUiG.d.cts → binding-CDR2ERoq.d.cts} +2 -2
  7. package/dist/{chunk-5FVWBK4M.cjs → chunk-2J4INHDT.cjs} +40 -40
  8. package/dist/{chunk-5FVWBK4M.cjs.map → chunk-2J4INHDT.cjs.map} +1 -1
  9. package/dist/{chunk-6DNYVH5U.cjs → chunk-CKKZDUHM.cjs} +21 -18
  10. package/dist/chunk-CKKZDUHM.cjs.map +1 -0
  11. package/dist/{chunk-UQTWIV3S.js → chunk-DHRRJJ6W.js} +8 -5
  12. package/dist/chunk-DHRRJJ6W.js.map +1 -0
  13. package/dist/{chunk-IIWHTV23.js → chunk-LFLFSJFU.js} +3 -3
  14. package/dist/{chunk-ECKYFH5Q.cjs → chunk-NBDEMBBX.cjs} +43 -81
  15. package/dist/chunk-NBDEMBBX.cjs.map +1 -0
  16. package/dist/{chunk-CFAWL76V.js → chunk-OKPQWORE.js} +43 -81
  17. package/dist/chunk-OKPQWORE.js.map +1 -0
  18. package/dist/{chunk-M42N54LG.js → chunk-OLHZBAIF.js} +3 -3
  19. package/dist/{chunk-F5SDRX4J.js → chunk-R2HYEOP7.js} +470 -172
  20. package/dist/chunk-R2HYEOP7.js.map +1 -0
  21. package/dist/{chunk-INYTG4NG.cjs → chunk-UG2IFQOY.cjs} +650 -352
  22. package/dist/chunk-UG2IFQOY.cjs.map +1 -0
  23. package/dist/{chunk-WY4LI5PB.cjs → chunk-VP2WC7X3.cjs} +8 -8
  24. package/dist/{chunk-WY4LI5PB.cjs.map → chunk-VP2WC7X3.cjs.map} +1 -1
  25. package/dist/{devtools-DWIZRe7L.d.cts → devtools-BwkkQ6DN.d.cts} +1 -1
  26. package/dist/{devtools-DNnnDGu1.d.ts → devtools-CK3SVU_w.d.ts} +1 -1
  27. package/dist/index.cjs +55 -42
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +4 -4
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.dev.js +260 -156
  32. package/dist/index.dev.js.map +1 -1
  33. package/dist/index.js +16 -3
  34. package/dist/index.js.map +1 -1
  35. package/dist/internal-list.cjs +4 -4
  36. package/dist/internal-list.js +3 -3
  37. package/dist/internal.cjs +5 -5
  38. package/dist/internal.d.cts +3 -3
  39. package/dist/internal.d.ts +3 -3
  40. package/dist/internal.js +4 -4
  41. package/dist/loader.cjs +18 -18
  42. package/dist/loader.js +1 -1
  43. package/dist/{props-C04ScJgm.d.ts → props-CFoQ471Y.d.ts} +1 -1
  44. package/dist/{props-CdmuXCiu.d.cts → props-D4tK8Gn0.d.cts} +1 -1
  45. package/dist/{scope-gpOMWTlf.d.ts → scope-BFzD_7hx.d.ts} +1 -1
  46. package/dist/{scope-GwC4DJ50.d.cts → scope-Ck3mTQVS.d.cts} +1 -1
  47. package/package.json +1 -1
  48. package/src/binding.ts +561 -166
  49. package/src/context.ts +8 -1
  50. package/src/dom.ts +26 -44
  51. package/src/effect.ts +9 -12
  52. package/src/error-boundary.ts +8 -0
  53. package/src/hydration.ts +25 -6
  54. package/src/lifecycle.ts +31 -79
  55. package/src/signal.ts +4 -1
  56. package/src/suspense.ts +8 -0
  57. package/dist/chunk-6DNYVH5U.cjs.map +0 -1
  58. package/dist/chunk-CFAWL76V.js.map +0 -1
  59. package/dist/chunk-ECKYFH5Q.cjs.map +0 -1
  60. package/dist/chunk-F5SDRX4J.js.map +0 -1
  61. package/dist/chunk-INYTG4NG.cjs.map +0 -1
  62. package/dist/chunk-UQTWIV3S.js.map +0 -1
  63. /package/dist/{chunk-IIWHTV23.js.map → chunk-LFLFSJFU.js.map} +0 -0
  64. /package/dist/{chunk-M42N54LG.js.map → chunk-OLHZBAIF.js.map} +0 -0
@@ -179,8 +179,6 @@ var reportCycle = (reason, detail = void 0) => {
179
179
  var isDev2 = typeof __DEV__ !== "undefined" ? __DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
180
180
  var currentRoot;
181
181
  var currentEffectCleanups;
182
- var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
183
- var globalSuspenseHandlers = /* @__PURE__ */ new WeakMap();
184
182
  var rootDevtoolsIds = /* @__PURE__ */ new WeakMap();
185
183
  var nextRootDevtoolsId = 0;
186
184
  function registerRootDevtools(root) {
@@ -255,18 +253,27 @@ function onCleanup(fn) {
255
253
  function flushOnMount(root) {
256
254
  const cbs = root.onMountCallbacks;
257
255
  if (!cbs || cbs.length === 0) return;
256
+ try {
257
+ withRootContext(root, () => {
258
+ for (let i = 0; i < cbs.length; i++) {
259
+ const cleanup = cbs[i]();
260
+ if (typeof cleanup === "function") {
261
+ root.cleanups.push(cleanup);
262
+ }
263
+ }
264
+ });
265
+ } finally {
266
+ cbs.length = 0;
267
+ }
268
+ }
269
+ function withRootContext(root, fn) {
270
+ if (!root) return fn();
258
271
  const prevRoot = currentRoot;
259
272
  currentRoot = root;
260
273
  try {
261
- for (let i = 0; i < cbs.length; i++) {
262
- const cleanup = cbs[i]();
263
- if (typeof cleanup === "function") {
264
- root.cleanups.push(cleanup);
265
- }
266
- }
274
+ return fn();
267
275
  } finally {
268
276
  currentRoot = prevRoot;
269
- cbs.length = 0;
270
277
  }
271
278
  }
272
279
  function registerRootCleanup(fn) {
@@ -275,26 +282,20 @@ function registerRootCleanup(fn) {
275
282
  }
276
283
  }
277
284
  function clearRoot(root) {
278
- runCleanupList(root.cleanups);
285
+ runCleanupList(root.cleanups, root);
279
286
  if (root.onMountCallbacks) {
280
287
  root.onMountCallbacks.length = 0;
281
288
  }
282
289
  }
283
290
  function destroyRoot(root) {
284
291
  clearRoot(root);
285
- runCleanupList(root.destroyCallbacks);
292
+ runCleanupList(root.destroyCallbacks, root);
286
293
  if (root.errorHandlers) {
287
294
  root.errorHandlers.length = 0;
288
295
  }
289
- if (globalErrorHandlers.has(root)) {
290
- globalErrorHandlers.delete(root);
291
- }
292
296
  if (root.suspenseHandlers) {
293
297
  root.suspenseHandlers.length = 0;
294
298
  }
295
- if (globalSuspenseHandlers.has(root)) {
296
- globalSuspenseHandlers.delete(root);
297
- }
298
299
  disposeRootDevtools(root);
299
300
  }
300
301
  function createRoot(fn, options2) {
@@ -329,21 +330,23 @@ function registerEffectCleanup(fn) {
329
330
  registerRootCleanup(fn);
330
331
  }
331
332
  }
332
- function runCleanupList(list) {
333
+ function runCleanupList(list, root) {
333
334
  let error;
334
- for (let i = list.length - 1; i >= 0; i--) {
335
- try {
336
- const cleanup = list[i];
337
- if (cleanup) cleanup();
338
- } catch (err) {
339
- if (error === void 0) {
340
- error = err;
335
+ withRootContext(root, () => {
336
+ for (let i = list.length - 1; i >= 0; i--) {
337
+ try {
338
+ const cleanup = list[i];
339
+ if (cleanup) cleanup();
340
+ } catch (err) {
341
+ if (error === void 0) {
342
+ error = err;
343
+ }
341
344
  }
342
345
  }
343
- }
346
+ });
344
347
  list.length = 0;
345
348
  if (error !== void 0) {
346
- if (!handleError(error, { source: "cleanup" })) {
349
+ if (!handleError(error, { source: "cleanup" }, root)) {
347
350
  throw error;
348
351
  }
349
352
  }
@@ -363,12 +366,6 @@ function registerErrorHandler(fn) {
363
366
  currentRoot.errorHandlers = [];
364
367
  }
365
368
  currentRoot.errorHandlers.push(fn);
366
- const existing = globalErrorHandlers.get(currentRoot);
367
- if (existing) {
368
- existing.push(fn);
369
- } else {
370
- globalErrorHandlers.set(currentRoot, [fn]);
371
- }
372
369
  }
373
370
  function registerSuspenseHandler(fn) {
374
371
  if (!currentRoot) {
@@ -379,12 +376,6 @@ function registerSuspenseHandler(fn) {
379
376
  currentRoot.suspenseHandlers = [];
380
377
  }
381
378
  currentRoot.suspenseHandlers.push(fn);
382
- const existing = globalSuspenseHandlers.get(currentRoot);
383
- if (existing) {
384
- existing.push(fn);
385
- } else {
386
- globalSuspenseHandlers.set(currentRoot, [fn]);
387
- }
388
379
  }
389
380
  function handleError(err, info, startRoot) {
390
381
  let root = startRoot ?? currentRoot;
@@ -406,20 +397,6 @@ function handleError(err, info, startRoot) {
406
397
  }
407
398
  root = root.parent;
408
399
  }
409
- const globalForRoot = startRoot ? globalErrorHandlers.get(startRoot) : currentRoot ? globalErrorHandlers.get(currentRoot) : void 0;
410
- if (globalForRoot && globalForRoot.length) {
411
- for (let i = globalForRoot.length - 1; i >= 0; i--) {
412
- const handler = globalForRoot[i];
413
- try {
414
- const handled = handler(error, info);
415
- if (handled !== false) {
416
- return true;
417
- }
418
- } catch (nextErr) {
419
- error = nextErr;
420
- }
421
- }
422
- }
423
400
  return false;
424
401
  }
425
402
  function handleSuspend(token, startRoot) {
@@ -442,20 +419,6 @@ function handleSuspend(token, startRoot) {
442
419
  }
443
420
  root = root.parent;
444
421
  }
445
- const globalForRoot = startRoot && globalSuspenseHandlers.get(startRoot) ? globalSuspenseHandlers.get(startRoot) : currentRoot ? globalSuspenseHandlers.get(currentRoot) : void 0;
446
- if (globalForRoot && globalForRoot.length) {
447
- for (let i = globalForRoot.length - 1; i >= 0; i--) {
448
- const handler = globalForRoot[i];
449
- const handled = handler(token);
450
- if (handled !== false) {
451
- if (originRoot) {
452
- originRoot.suspended = true;
453
- setRootSuspendDevtools(originRoot, true);
454
- }
455
- return true;
456
- }
457
- }
458
- }
459
422
  return false;
460
423
  }
461
424
 
@@ -871,7 +834,9 @@ function runEffect(e) {
871
834
  inCleanup = true;
872
835
  activeCleanupFlushId = currentFlushId;
873
836
  try {
874
- e.runCleanup();
837
+ withRootContext(e.root, () => {
838
+ e.runCleanup();
839
+ });
875
840
  } finally {
876
841
  activeCleanupFlushId = 0;
877
842
  inCleanup = false;
@@ -1564,7 +1529,7 @@ function createEffect(fn, options2) {
1564
1529
  let cleanups = [];
1565
1530
  const rootForError = getCurrentRoot();
1566
1531
  const doCleanup = () => {
1567
- runCleanupList(cleanups);
1532
+ runCleanupList(cleanups, rootForError);
1568
1533
  cleanups = [];
1569
1534
  };
1570
1535
  const run = () => {
@@ -1589,26 +1554,26 @@ function createEffect(fn, options2) {
1589
1554
  };
1590
1555
  const disposeEffect = effectWithCleanup(run, doCleanup, rootForError, options2);
1591
1556
  const teardown = () => {
1592
- runCleanupList(cleanups);
1557
+ runCleanupList(cleanups, rootForError);
1593
1558
  disposeEffect();
1594
1559
  };
1595
1560
  registerRootCleanup(teardown);
1596
1561
  return teardown;
1597
1562
  }
1598
1563
  function createRenderEffect(fn, options2) {
1599
- let cleanup;
1564
+ let cleanups = [];
1600
1565
  const rootForError = getCurrentRoot();
1601
1566
  const doCleanup = () => {
1602
- if (cleanup) {
1603
- cleanup();
1604
- cleanup = void 0;
1605
- }
1567
+ runCleanupList(cleanups, rootForError);
1568
+ cleanups = [];
1606
1569
  };
1607
1570
  const run = () => {
1608
1571
  try {
1609
1572
  const maybeCleanup = fn();
1610
1573
  if (typeof maybeCleanup === "function") {
1611
- cleanup = maybeCleanup;
1574
+ cleanups = [maybeCleanup];
1575
+ } else {
1576
+ cleanups = [];
1612
1577
  }
1613
1578
  } catch (err) {
1614
1579
  if (handleSuspend(err, rootForError)) {
@@ -1623,10 +1588,7 @@ function createRenderEffect(fn, options2) {
1623
1588
  };
1624
1589
  const disposeEffect = effectWithCleanup(run, doCleanup, rootForError, options2);
1625
1590
  const teardown = () => {
1626
- if (cleanup) {
1627
- cleanup();
1628
- cleanup = void 0;
1629
- }
1591
+ runCleanupList(cleanups, rootForError);
1630
1592
  disposeEffect();
1631
1593
  };
1632
1594
  registerRootCleanup(teardown);
@@ -2734,4 +2696,4 @@ export {
2734
2696
  serializeValue,
2735
2697
  deserializeValue
2736
2698
  };
2737
- //# sourceMappingURL=chunk-CFAWL76V.js.map
2699
+ //# sourceMappingURL=chunk-OKPQWORE.js.map