@solidjs/signals 2.0.0-rc.1 → 2.0.0-rc.10

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 (150) hide show
  1. package/dist/dev-shared.js +7138 -0
  2. package/dist/dev.attribution.js +3307 -0
  3. package/dist/dev.js +5691 -4491
  4. package/dist/observe/affects.js +129 -0
  5. package/dist/observe/attribution.js +7 -0
  6. package/dist/observe/boundaries.js +793 -0
  7. package/dist/observe/core/action.js +177 -0
  8. package/dist/observe/core/async.js +849 -0
  9. package/dist/observe/core/attribution-costs.js +66 -0
  10. package/dist/observe/core/attribution-feedback.js +280 -0
  11. package/dist/observe/core/attribution-hooks.js +83 -0
  12. package/dist/observe/core/attribution-queries.js +43 -0
  13. package/dist/observe/core/attribution.js +2904 -0
  14. package/dist/observe/core/constants.js +283 -0
  15. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  16. package/dist/observe/core/core.js +1999 -0
  17. package/dist/observe/core/dev.js +343 -0
  18. package/dist/observe/core/effect.js +200 -0
  19. package/dist/observe/core/error-hooks.js +71 -0
  20. package/dist/observe/core/error.js +80 -0
  21. package/dist/observe/core/external.js +98 -0
  22. package/dist/observe/core/graph.js +155 -0
  23. package/dist/observe/core/heap.js +147 -0
  24. package/dist/observe/core/invariants.js +45 -0
  25. package/dist/observe/core/lanes.js +205 -0
  26. package/dist/observe/core/optimistic.js +627 -0
  27. package/dist/observe/core/owner.js +353 -0
  28. package/dist/observe/core/scheduler.js +1547 -0
  29. package/dist/observe/core/verdict.js +674 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +484 -0
  32. package/dist/observe/signals.js +731 -0
  33. package/dist/observe/store/index.js +44 -0
  34. package/dist/observe/store/next/optimistic.js +717 -0
  35. package/dist/observe/store/next/projection.js +266 -0
  36. package/dist/observe/store/next/reconcile.js +375 -0
  37. package/dist/observe/store/next/store.js +2480 -0
  38. package/dist/observe/store/next/target.js +51 -0
  39. package/dist/observe/store/store.js +331 -0
  40. package/dist/observe/store/storePath.js +103 -0
  41. package/dist/observe/store/utils.js +1070 -0
  42. package/dist/prod/affects.js +10 -9
  43. package/dist/prod/attribution.js +45 -0
  44. package/dist/prod/boundaries.js +388 -178
  45. package/dist/prod/core/action.js +65 -37
  46. package/dist/prod/core/async.js +378 -163
  47. package/dist/prod/core/attribution-hooks.js +3 -0
  48. package/dist/prod/core/constants.js +186 -1
  49. package/dist/prod/core/context.js +10 -16
  50. package/dist/prod/core/core.js +1546 -416
  51. package/dist/prod/core/dev.js +18 -1
  52. package/dist/prod/core/effect.js +119 -79
  53. package/dist/prod/core/error-hooks.js +71 -0
  54. package/dist/prod/core/error.js +13 -1
  55. package/dist/prod/core/external.js +4 -4
  56. package/dist/prod/core/graph.js +105 -54
  57. package/dist/prod/core/heap.js +72 -65
  58. package/dist/prod/core/invariants.js +3 -2
  59. package/dist/prod/core/lanes.js +117 -52
  60. package/dist/prod/core/optimistic.js +458 -104
  61. package/dist/prod/core/owner.js +131 -84
  62. package/dist/prod/core/scheduler.js +998 -241
  63. package/dist/prod/core/verdict.js +417 -112
  64. package/dist/prod/index.js +20 -8
  65. package/dist/prod/map.js +312 -151
  66. package/dist/prod/signals.js +363 -32
  67. package/dist/prod/store/index.js +2 -0
  68. package/dist/prod/store/next/optimistic.js +530 -197
  69. package/dist/prod/store/next/projection.js +142 -57
  70. package/dist/prod/store/next/reconcile.js +149 -103
  71. package/dist/prod/store/next/store.js +1470 -346
  72. package/dist/prod/store/next/target.js +40 -9
  73. package/dist/prod/store/store.js +23 -19
  74. package/dist/prod/store/utils.js +997 -130
  75. package/dist/types/attribution.d.ts +19 -0
  76. package/dist/types/attribution.prod.d.ts +22 -0
  77. package/dist/types/boundaries.d.ts +78 -5
  78. package/dist/types/core/action.d.ts +12 -5
  79. package/dist/types/core/async.d.ts +3 -1
  80. package/dist/types/core/attribution-costs.d.ts +35 -0
  81. package/dist/types/core/attribution-feedback.d.ts +133 -0
  82. package/dist/types/core/attribution-hooks.d.ts +304 -0
  83. package/dist/types/core/attribution-queries.d.ts +24 -0
  84. package/dist/types/core/attribution.d.ts +892 -0
  85. package/dist/types/core/constants.d.ts +179 -0
  86. package/dist/types/core/core.d.ts +299 -25
  87. package/dist/types/core/dev.d.ts +421 -8
  88. package/dist/types/core/effect.d.ts +8 -1
  89. package/dist/types/core/error-hooks.d.ts +71 -0
  90. package/dist/types/core/error.d.ts +9 -0
  91. package/dist/types/core/graph.d.ts +23 -0
  92. package/dist/types/core/heap.d.ts +5 -3
  93. package/dist/types/core/index.d.ts +6 -3
  94. package/dist/types/core/invariants.d.ts +5 -1
  95. package/dist/types/core/lanes.d.ts +51 -19
  96. package/dist/types/core/owner.d.ts +15 -3
  97. package/dist/types/core/scheduler.d.ts +248 -1
  98. package/dist/types/core/types.d.ts +124 -41
  99. package/dist/types/index.d.ts +18 -5
  100. package/dist/types/map.d.ts +2 -0
  101. package/dist/types/signals.d.ts +145 -13
  102. package/dist/types/store/index.d.ts +7 -6
  103. package/dist/types/store/next/optimistic.d.ts +18 -13
  104. package/dist/types/store/next/projection.d.ts +5 -2
  105. package/dist/types/store/next/reconcile.d.ts +7 -0
  106. package/dist/types/store/next/store.d.ts +83 -11
  107. package/dist/types/store/next/target.d.ts +108 -11
  108. package/dist/types/store/store.d.ts +20 -11
  109. package/dist/types/store/utils.d.ts +188 -0
  110. package/package.json +31 -26
  111. package/dist/node.cjs +0 -8137
  112. package/dist/types/store/optimistic.d.ts +0 -45
  113. package/dist/types/store/projection.d.ts +0 -70
  114. package/dist/types/store/reconcile.d.ts +0 -46
  115. package/dist/types-cjs/affects.d.cts +0 -47
  116. package/dist/types-cjs/boundaries.d.cts +0 -175
  117. package/dist/types-cjs/core/action.d.cts +0 -64
  118. package/dist/types-cjs/core/async.d.cts +0 -21
  119. package/dist/types-cjs/core/constants.d.cts +0 -71
  120. package/dist/types-cjs/core/core.d.cts +0 -156
  121. package/dist/types-cjs/core/dev.d.cts +0 -64
  122. package/dist/types-cjs/core/effect.d.cts +0 -30
  123. package/dist/types-cjs/core/error.d.cts +0 -47
  124. package/dist/types-cjs/core/external.d.cts +0 -15
  125. package/dist/types-cjs/core/graph.d.cts +0 -5
  126. package/dist/types-cjs/core/heap.d.cts +0 -22
  127. package/dist/types-cjs/core/index.d.cts +0 -13
  128. package/dist/types-cjs/core/invariants.d.cts +0 -59
  129. package/dist/types-cjs/core/lanes.d.cts +0 -56
  130. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  131. package/dist/types-cjs/core/owner.d.cts +0 -124
  132. package/dist/types-cjs/core/scheduler.d.cts +0 -172
  133. package/dist/types-cjs/core/types.d.cts +0 -148
  134. package/dist/types-cjs/core/verdict.d.cts +0 -2
  135. package/dist/types-cjs/index.d.cts +0 -10
  136. package/dist/types-cjs/map.d.cts +0 -69
  137. package/dist/types-cjs/package.json +0 -3
  138. package/dist/types-cjs/signals.d.cts +0 -624
  139. package/dist/types-cjs/store/index.d.cts +0 -19
  140. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  141. package/dist/types-cjs/store/next/projection.d.cts +0 -24
  142. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  143. package/dist/types-cjs/store/next/store.d.cts +0 -71
  144. package/dist/types-cjs/store/next/target.d.cts +0 -99
  145. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  146. package/dist/types-cjs/store/projection.d.cts +0 -70
  147. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  148. package/dist/types-cjs/store/store.d.cts +0 -138
  149. package/dist/types-cjs/store/storePath.d.cts +0 -58
  150. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,3 +1,20 @@
1
+ import "./core.js";
2
+
3
+ /**
4
+ * Registers the console footer appended to the first console report of
5
+ * each diagnostic code — a discovery pointer to deeper guidance. Reported
6
+ * events carry it as trailing lines of the same console entry; events that
7
+ * surface as a thrown error instead get it as a follow-up line. Returning
8
+ * undefined for an event suppresses the footer. Passing undefined
9
+ * unregisters and resets the once-per-code memory.
10
+ *
11
+ * @internal A seam for `solid-js`, which owns the repair skill the footer
12
+ * names and installs it from both of its entries; not part of `DEV`. No-op
13
+ * outside dev builds, where nothing reports to the console.
14
+ */ function setConsoleFooter(o) {
15
+ return;
16
+ }
17
+
1
18
  const DEV = undefined;
2
19
 
3
- export { DEV };
20
+ export { DEV, setConsoleFooter };
@@ -1,29 +1,36 @@
1
- import { REACTIVE_DISPOSED, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, STATUS_PENDING, EFFECT_RENDER } from "./constants.js";
1
+ import { REACTIVE_DISPOSED, LANE_RUN, STATUS_ERROR, EFFECT_USER, NOT_PENDING, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, STATUS_PENDING } from "./constants.js";
2
2
 
3
- import { createEffectNode, recompute, computed, staleValues } from "./core.js";
3
+ import { setEffectStatusNotify, ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
4
4
 
5
5
  import { unwrapStatusError, StatusError } from "./error.js";
6
6
 
7
- import { GlobalQueue, haltReactivity } from "./scheduler.js";
7
+ import { trimStaleDeps } from "./graph.js";
8
+
9
+ import { enqueueSub } from "./heap.js";
10
+
11
+ import { GlobalQueue, currentTransition, activeTransition, haltReactivity, schedule } from "./scheduler.js";
8
12
 
9
13
  /**
10
14
  * Effects are the leaf nodes of our reactive graph. When their sources change, they are
11
15
  * automatically added to the queue of effects to re-execute, which will cause them to fetch their
12
16
  * sources and recompute
13
- */ function effect(t, E, e, R) {
14
- const r = !!R?.user;
15
- const f = createEffectNode(t, E, e, r ? EFFECT_USER : EFFECT_RENDER, notifyEffectStatus, R);
16
- recompute(f, true);
17
- !R?.defer && (f.Re === EFFECT_USER || R?.schedule ? f.C.enqueue(f.Re, runEffect.bind(null, f)) : runEffect(f));
17
+ */ function effect(t, e, E, r) {
18
+ const n = !!r?.user;
19
+ const i = createEffectNode(t, e, E, n ? EFFECT_USER : EFFECT_RENDER, r);
20
+ recompute(i, true);
21
+ // A first pass that derived from a live transaction's staged world was
22
+ // staged into that transaction (recompute: born held); the transaction's
23
+ // commit replays this effect. Its first run is not this creation's (A29).
24
+ !r?.defer && i._e === NOT_PENDING && (i.je === EFFECT_USER || r?.schedule ? i.T.enqueue(i.je, runEffect.bind(null, i)) : runEffect(i, LANE_RUN));
18
25
  }
19
26
 
20
- function notifyEffectStatus(t, E) {
27
+ function notifyEffectStatus(t, e) {
21
28
  // Use passed values if provided, otherwise read from node
22
- const e = t !== undefined ? t : this.S;
23
- const R = E !== undefined ? E : this._;
24
- if (e & STATUS_ERROR) {
25
- this.C.notify(this, STATUS_PENDING, 0);
26
- if (this.Re === EFFECT_USER) {
29
+ const E = t !== undefined ? t : this.h;
30
+ const r = e !== undefined ? e : this.o?._;
31
+ if (E & STATUS_ERROR) {
32
+ this.T.notify(this, STATUS_PENDING, 0);
33
+ if (this.je === EFFECT_USER) {
27
34
  // The error handler is the error arm of the effect phase (#2840 ruling):
28
35
  // queue it like the effect function. It runs in the same imperative,
29
36
  // writable scope, throws escalate the same way, and a held transition
@@ -33,23 +40,43 @@ function notifyEffectStatus(t, E) {
33
40
  // phase takes the success arm instead. Blocked forwards (explicit
34
41
  // `status` arg without node-state writes) don't queue: the status
35
42
  // re-propagates unblocked at commit.
36
- if (this.S & STATUS_ERROR) {
37
- this.Je = true;
38
- this.C.enqueue(this.Re, this.Xe ??= runEffect.bind(null, this));
43
+ if (this.h & STATUS_ERROR) {
44
+ this.Xe = true;
45
+ this.T.enqueue(this.je, this.An ??= runEffect.bind(null, this));
39
46
  }
40
47
  return;
41
48
  }
42
- if (!this.C.notify(this, STATUS_ERROR, STATUS_ERROR)) {
43
- haltReactivity(unwrapStatusError(R));
44
- throw R;
49
+ if (!this.T.notify(this, STATUS_ERROR, STATUS_ERROR)) {
50
+ haltReactivity(unwrapStatusError(r));
51
+ throw r;
45
52
  }
46
- } else if (this.Re === EFFECT_RENDER) {
47
- this.C.notify(this, STATUS_PENDING | STATUS_ERROR, e, R);
53
+ } else if (this.je === EFFECT_RENDER) {
54
+ this.T.notify(this, STATUS_PENDING | STATUS_ERROR, E, r);
48
55
  }
49
56
  }
50
57
 
51
- function runEffect(t) {
52
- if (!t.Je || t.se & REACTIVE_DISPOSED) return;
58
+ function runEffect(t, e) {
59
+ if (!t.Xe || t.oe & REACTIVE_DISPOSED) return;
60
+ // Ownership (#3319): a value computed under a transaction is applied by that
61
+ // transaction's commit. The ordinary effect phase runs with a transaction
62
+ // active only when the flush's finalize ENTERED one (every other path parks
63
+ // or settles first): leave a run owned by a still-held transaction queued —
64
+ // `_modified` stays set — and the next gate stashes it with the owner.
65
+ // Mainline-owned runs (null) apply now. Lanes are exempt by design (they
66
+ // apply their own effects ahead of their transaction — the optimistic view)
67
+ // and mark their runs with LANE_RUN.
68
+
69
+ // Lane exemption has one exception (#3331): a lane runner for an effect that
70
+ // no longer rides a lane — its optimistic source was superseded, so the lane
71
+ // has no optimistic view left to apply, and the value this effect now
72
+ // carries (or will, once its plain recompute lands) belongs to the still-held
73
+ // transaction. Hand the run to the regular queue, where the transaction's
74
+ // gate stashes it with the owner. Lane-less runners with no live owner
75
+ // (reverts, wake-only lanes) apply now.
76
+ if (t.pn !== null && !currentTransition(t.pn).Rn && (e & LANE_RUN ? !t.o?.me : activeTransition !== null)) {
77
+ t.T.enqueue(t.je, t.An);
78
+ return;
79
+ }
53
80
  // Error arm (#2840), user effects only: a compute-phase error that is still
54
81
  // the node's settled state at effect time runs the bundle's error handler in
55
82
  // this same imperative, writable scope. Unwrap the StatusError used for
@@ -60,86 +87,99 @@ function runEffect(t) {
60
87
  // Render effects bypass: their errors route to boundaries synchronously in
61
88
  // notifyEffectStatus, and a runner queued by an earlier valueChanged in the
62
89
  // same flush must not be hijacked by a later-arriving error status.
63
- if (t.S & STATUS_ERROR && t.Re === EFFECT_USER) {
64
- const E = unwrapStatusError(t._);
65
- t._t = t.be;
66
- t.Je = false;
90
+ if (t.h & STATUS_ERROR && t.je === EFFECT_USER) {
91
+ const e = unwrapStatusError(t.o?._);
92
+ t.xn = t.ce;
93
+ t.Xe = false;
67
94
  try {
68
- t.Et ? t.Et(E, () => {
69
- const E = t.Nt;
70
- t.Nt = undefined;
71
- E?.();
72
- }) : console.error(E);
73
- } catch (E) {
74
- if (!t.C.notify(t, STATUS_ERROR, STATUS_ERROR)) {
75
- haltReactivity(E);
76
- throw E;
95
+ t.Mn ? t.Mn(e, () => {
96
+ const e = t.wn;
97
+ t.wn = undefined;
98
+ e?.();
99
+ }) : console.error(e);
100
+ } catch (e) {
101
+ if (!t.T.notify(t, STATUS_ERROR, STATUS_ERROR)) {
102
+ haltReactivity(e);
103
+ throw e;
77
104
  }
78
105
  }
79
106
  return;
80
107
  }
81
- const E = t.Nt;
82
- t.Nt = undefined;
108
+ // Captured before the callback: its own throw errors the node below, but
109
+ // the compute pass that produced `_value` was clean, so its tail still goes.
110
+ const E = t.o?._ == null;
111
+ const r = t.wn;
112
+ t.wn = undefined;
83
113
  try {
84
- E?.();
85
- const e = t.ft(t.be, t._t);
114
+ r?.();
115
+ const e = t.Qn(t.ce, t.xn);
86
116
  if (false && e !== undefined && typeof e !== "function") ;
87
117
  // The final cleanup is invoked by disposeChildren at true disposal.
88
- t.Nt = e;
89
- } catch (E) {
90
- t._ = new StatusError(t, E);
91
- t.S |= STATUS_ERROR;
92
- if (!t.C.notify(t, STATUS_ERROR, STATUS_ERROR)) {
93
- haltReactivity(E);
94
- throw E;
118
+ t.wn = e;
119
+ } catch (e) {
120
+ ext(t)._ = new StatusError(t, e);
121
+ t.h |= STATUS_ERROR;
122
+ if (!t.T.notify(t, STATUS_ERROR, STATUS_ERROR)) {
123
+ haltReactivity(e);
124
+ throw e;
95
125
  }
96
126
  } finally {
97
- t._t = t.be;
98
- t.Je = false;
127
+ t.xn = t.ce;
128
+ t.Xe = false;
129
+ // The run applied: this is the frame now, so the dependency tail the
130
+ // compute pass left linked goes (A30, #3438 — `recompute` defers an
131
+ // effect's trim while a run is owed; the twin of `commitPendingNode`'s
132
+ // trim for a staged pass). An errored compute kept its full list with
133
+ // `_depsTail` marking where it stopped; leave it, as the commit does.
134
+ if (E) trimStaleDeps(t);
99
135
  }
100
136
  }
101
137
 
102
- GlobalQueue.et = runEffect;
138
+ GlobalQueue.Cn = runEffect;
103
139
 
104
140
  /**
105
141
  * Internal tracked effect - bypasses heap, goes directly to effect queue.
106
142
  * Runs as a leaf owner: child primitives and onCleanup are forbidden (false throws).
107
143
  * Uses stale reads.
108
- */ function trackedEffect(t, E) {
144
+ */ function trackedEffect(t, e) {
109
145
  const run = () => {
110
- if (!e.Je || e.se & REACTIVE_DISPOSED) return;
146
+ // `_modified` is NOT redundant with the heap: the heap dedups within a
147
+ // pass, but a held transition's passes each enqueue `_run` into the same
148
+ // user queue, and this gate is what collapses them into one run at commit.
149
+ if (!E.Xe || E.oe & REACTIVE_DISPOSED) return;
111
150
  try {
112
- e.Je = false;
113
- recompute(e);
151
+ E.Xe = false;
152
+ recompute(E);
114
153
  } finally {}
115
154
  };
116
- const e = computed(() => {
117
- const E = e.Nt;
118
- e.Nt = undefined;
119
- E?.();
120
- const R = staleValues(t);
121
- e.Nt = R;
155
+ const E = computed(() => {
156
+ const e = E.wn;
157
+ E.wn = undefined;
158
+ e?.();
159
+ const r = staleValues(t);
160
+ E.wn = r;
122
161
  }, {
123
- ...E,
162
+ ...e,
124
163
  lazy: true
125
164
  });
126
- e.Nt = undefined;
127
- e.T = e.T & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
128
- e.Je = true;
129
- e.Re = EFFECT_TRACKED;
130
- e.i = (t, E) => {
131
- const R = t !== undefined ? t : e.S;
132
- if (R & STATUS_ERROR) {
133
- e.C.notify(e, STATUS_PENDING, 0);
134
- const t = E !== undefined ? E : e._;
135
- if (!e.C.notify(e, STATUS_ERROR, STATUS_ERROR)) {
136
- haltReactivity(unwrapStatusError(t));
137
- throw t;
138
- }
139
- }
140
- };
141
- e.ht = run;
142
- e.C.enqueue(EFFECT_USER, run);
165
+ E.wn = undefined;
166
+ E.C = E.C & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
167
+ E.Xe = true;
168
+ E.je = EFFECT_TRACKED;
169
+ // Status dispatch rides the SHARED notifier (statusNotifierOf keys off
170
+ // _type): its error arm is behavior-identical to the closure that used to
171
+ // live here, without the per-node NodeExtension allocation.
172
+ E.$e = run;
173
+ // The first run rides the heap like every wake (GlobalQueue._update), so a
174
+ // tracked effect created inside a render-effect callback runs after that
175
+ // pass's staged writes commit, not before.
176
+ enqueueSub(E);
177
+ schedule();
143
178
  }
144
179
 
180
+ // Install the shared effect status notifier (statusNotifierOf serves it to
181
+ // every effect node) — module-scope: any bundle that creates effects
182
+ // evaluates this module.
183
+ setEffectStatusNotify(notifyEffectStatus);
184
+
145
185
  export { effect, trackedEffect };
@@ -0,0 +1,71 @@
1
+ import { ROOT_ERROR_HOOK } from "./scheduler.js";
2
+
3
+ let ambientHook;
4
+
5
+ const reported = new WeakSet;
6
+
7
+ /**
8
+ * Registers the ambient client error hook — the one call a browser `init()`
9
+ * makes to see every failure a boundary renders a fallback for, in
10
+ * production. (Uncaught errors reach `reportError` / `window.onerror`.)
11
+ *
12
+ * ```ts
13
+ * configureClientErrors({
14
+ * onError: (error, { ownerPath }) =>
15
+ * Sentry.captureException(error, {
16
+ * mechanism: { type: "solid.error_boundary", handled: true }
17
+ * })
18
+ * });
19
+ * ```
20
+ */ function configureClientErrors(e) {
21
+ if (e && e.onError !== undefined && typeof e.onError !== "function") {
22
+ throw new TypeError(`Invalid onError: expected a function, received ${typeof e.onError}.`);
23
+ }
24
+ ambientHook = e ? e.onError : undefined;
25
+ }
26
+
27
+ /** The nearest root's hook above `owner` (parked under `ROOT_ERROR_HOOK`), else the ambient one. */ function hookFor(e) {
28
+ for (let n = e; n; n = n._parent) {
29
+ const e = n[ROOT_ERROR_HOOK];
30
+ if (e !== undefined) return e;
31
+ }
32
+ return ambientHook;
33
+ }
34
+
35
+ /** Component labels up the owner chain, root first — `_name` where the runtime keeps it. */ function labels(e) {
36
+ const n = [];
37
+ for (let o = e; o; o = o._parent) {
38
+ const e = o._name;
39
+ if (typeof e === "string" && e.length) n.push(e);
40
+ }
41
+ return n.length ? n.reverse() : undefined;
42
+ }
43
+
44
+ /**
45
+ * Tells the client error hook about `error`, caught by the boundary whose
46
+ * owner is `owner`, thrown by `thrower` (the computation the engine's status
47
+ * wrapper named; unknown for a value that never crossed one) — once per
48
+ * error object. A throwing hook is reported on the console and otherwise
49
+ * ignored — a monitor must never take the app down.
50
+ * @internal
51
+ */ function reportClientError(e, n, o) {
52
+ const r = e !== null && (typeof e === "object" || typeof e === "function");
53
+ if (r) {
54
+ if (reported.has(e)) return;
55
+ reported.add(e);
56
+ }
57
+ const t = hookFor(n);
58
+ if (t === undefined) return;
59
+ const i = {};
60
+ const f = labels(n);
61
+ const c = labels(o) ?? f;
62
+ if (c !== undefined) i.ownerPath = c;
63
+ if (f !== undefined) i.boundaryPath = f;
64
+ try {
65
+ t(e, i);
66
+ } catch (e) {
67
+ console.error(e);
68
+ }
69
+ }
70
+
71
+ export { configureClientErrors, reportClientError };
@@ -53,6 +53,18 @@ class StatusError extends Error {
53
53
  return r instanceof StatusError ? r.cause : r;
54
54
  }
55
55
 
56
+ /**
57
+ * Rejection value of `until(fn, { timeout })` when the predicate does not turn
58
+ * truthy within the window. Inside an `action()`, the rejection is thrown back
59
+ * in at the `yield` point — catchable there, or the action fails and its
60
+ * optimistic state reverts.
61
+ */ class TimeoutError extends Error {
62
+ constructor(r = "Timed out waiting for condition") {
63
+ super(r);
64
+ this.name = "TimeoutError";
65
+ }
66
+ }
67
+
56
68
  class NoOwnerError extends Error {
57
69
  constructor() {
58
70
  super("");
@@ -65,4 +77,4 @@ class ContextNotFoundError extends Error {
65
77
  }
66
78
  }
67
79
 
68
- export { ContextNotFoundError, NoOwnerError, NotReadyError, StatusError, unwrapStatusError };
80
+ export { ContextNotFoundError, NoOwnerError, NotReadyError, StatusError, TimeoutError, unwrapStatusError };
@@ -46,11 +46,11 @@ function wireExternalSource(e) {
46
46
  equals: false,
47
47
  ownedWrite: true
48
48
  });
49
- const r = externalSourceConfig.factory(e.ce, () => {
49
+ const r = externalSourceConfig.factory(e.he, () => {
50
50
  setSignal(n, undefined);
51
51
  });
52
52
  cleanup(() => r.dispose());
53
- e.ce = e => {
53
+ e.he = e => {
54
54
  read(n);
55
55
  return r.track(e);
56
56
  };
@@ -64,8 +64,8 @@ function externalUntrack(e) {
64
64
  // removed on reset) so core's null checks stay equivalent to the old
65
65
  // `externalSourceConfig` truthiness checks.
66
66
  function syncExternalHooks() {
67
- GlobalQueue.dt = externalSourceConfig ? wireExternalSource : null;
68
- GlobalQueue.St = externalSourceConfig ? externalUntrack : null;
67
+ GlobalQueue.Zn = externalSourceConfig ? wireExternalSource : null;
68
+ GlobalQueue.jn = externalSourceConfig ? externalUntrack : null;
69
69
  }
70
70
 
71
71
  function enableExternalSource(e) {
@@ -1,78 +1,127 @@
1
- import { CONFIG_AUTO_DISPOSE, REACTIVE_ZOMBIE, STATUS_PENDING, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
1
+ import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
2
+
3
+ import { slotUnobservedHook } from "./core.js";
2
4
 
3
5
  import { deleteFromHeap, queueFor } from "./heap.js";
4
6
 
5
7
  import { disposeChildren } from "./owner.js";
6
8
 
7
- import "./scheduler.js";
9
+ import { bumpNotifyEpoch } from "./scheduler.js";
8
10
 
9
11
  // https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
10
- function unlinkSubs(l) {
11
- const n = l.it;
12
- const e = l.nt;
13
- const u = l.ue;
14
- const s = l.ll;
15
- if (u !== null) u.ll = s; else n.rt = s;
16
- if (s !== null) s.ue = u; else {
17
- n.o = u;
18
- if (u === null) {
19
- n.ut?.();
12
+ function unlinkSubs(e) {
13
+ const n = e.Oe;
14
+ const l = e.Ne;
15
+ const o = e.Ae;
16
+ const s = e.el;
17
+ if (o !== null) o.el = s; else n.mn = s;
18
+ if (s !== null) s.Ae = o; else {
19
+ n.u = o;
20
+ if (o === null) {
21
+ // Slot nodes (store leaves) dispatch to the ONE shared hook — no
22
+ // per-node unobserved closure, no NodeExtension to hold it.
23
+ if (n.C & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.o?.Hn?.();
20
24
  // No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
21
25
  // A pending node is exempt: its in-flight async work (or the
22
26
  // transition holding it) is an observer — tearing down would orphan
23
27
  // the work and re-execute it on the next read. The settle path runs
24
28
  // this same last-one-out check when that observer releases (the
25
- // untracked-read dispose in core.ts guards on pending identically).
26
- const l = n;
27
- l.ce && l.T & CONFIG_AUTO_DISPOSE && !(l.se & REACTIVE_ZOMBIE) && !(l.S & STATUS_PENDING) && unobserved(l);
29
+ // untracked-read dormancy sweep guards on pending identically).
30
+ const e = n;
31
+ e.he && e.C & CONFIG_AUTO_DISPOSE && !(e.oe & REACTIVE_ZOMBIE) && !(e.h & STATUS_PENDING) && unobserved(e);
28
32
  }
29
33
  }
30
- return e;
34
+ return l;
31
35
  }
32
36
 
33
- function trimStaleDeps(l) {
34
- const n = l.Ye;
35
- let e = n !== null ? n.nt : l.tt;
36
- if (e !== null) {
37
+ function trimStaleDeps(e) {
38
+ const n = e.Nn;
39
+ let l = n !== null ? n.Ne : e.Ie;
40
+ if (l !== null) {
37
41
  do {
38
- e = unlinkSubs(e);
39
- } while (e !== null);
40
- if (n !== null) n.nt = null; else l.tt = null;
42
+ l = unlinkSubs(l);
43
+ } while (l !== null);
44
+ if (n !== null) n.Ne = null; else e.Ie = null;
41
45
  }
42
46
  }
43
47
 
44
- function unobserved(l) {
45
- deleteFromHeap(l, queueFor(l));
46
- let n = l.tt;
47
- while (n !== null) {
48
+ // Shared by unobserved() and the disposeChildren child loop. The truthy guard
49
+ // (not `!== null`) matters: plain Owners in a child chain have no _deps field,
50
+ // and skipping early also avoids adding one (hidden-class churn) via the
51
+ // null-out below.
52
+ function clearDeps(e) {
53
+ let n = e.Ie;
54
+ if (!n) return;
55
+ do {
48
56
  n = unlinkSubs(n);
57
+ } while (n !== null);
58
+ e.Ie = null;
59
+ e.Nn = null;
60
+ }
61
+
62
+ function unobserved(e) {
63
+ deleteFromHeap(e, queueFor(e));
64
+ clearDeps(e);
65
+ disposeChildren(e, true);
66
+ }
67
+
68
+ /**
69
+ * Deferred dormancy for never-observed auto-dispose computeds (#3078).
70
+ *
71
+ * An untracked top-level read of a subscriber-less observation-lifecycle memo
72
+ * used to call unobserved() inline at the end of read(). That kept the leak
73
+ * closed (the compute links the memo into its deps' sub lists — without a
74
+ * teardown point a never-observed memo is retained by its sources forever;
75
+ * upstream alien-signals has exactly this retention), but it made reads
76
+ * destructive: each read disposed the node, the next read revived it with a
77
+ * full recompute in whatever ambient transition/lane context happened to be
78
+ * current, so consecutive reads could return different answers with no write
79
+ * in between.
80
+ *
81
+ * Instead, reads queue the node here and the scheduler sweeps at the top of
82
+ * the next flush (before runHeap, so a same-tick dirtying is reclaimed
83
+ * instead of recomputed). Reads become idempotent within a tick (the node
84
+ * stays alive and serves its cache, uniform with observed memos) while
85
+ * reclamation still happens within one microtask — the enqueue site arms
86
+ * schedule(), so a flush is guaranteed even when no other work is queued.
87
+ */ const dormantNodes = new Set;
88
+
89
+ function sweepDormant() {
90
+ if (dormantNodes.size === 0) return;
91
+ for (const e of dormantNodes) {
92
+ // Re-validate at sweep time: the node may have gained a subscriber (its
93
+ // lifecycle is the unlinkSubs cascade now), gone pending (in-flight async
94
+ // is an observer; the settle path re-runs last-one-out), lost its
95
+ // AUTO_DISPOSE bit (owner teardown strips it, #3024), or already been
96
+ // torn down.
97
+ if (!e.u && e.C & CONFIG_AUTO_DISPOSE && !(e.h & STATUS_PENDING) && !(e.oe & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
98
+ unobserved(e);
99
+ }
49
100
  }
50
- l.tt = null;
51
- l.Ye = null;
52
- disposeChildren(l, true);
101
+ dormantNodes.clear();
53
102
  }
54
103
 
55
104
  // https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L52
56
- function link(l, n, e = false) {
105
+ function link(e, n, l = false) {
57
106
  // Repeat touches within one pass AND-combine `_pendingObserver`: a probe
58
107
  // read (`isPending(() => x())`) beside a value read of the same dep must
59
108
  // not relabel the value dependency as probe-only — the value read is what
60
109
  // real-error propagation and affects() coverage key off, regardless of
61
110
  // read order within the computation.
62
- const u = n.Ye;
63
- if (u !== null && u.it === l) {
64
- u.ye &&= e;
111
+ const o = n.Nn;
112
+ if (o !== null && o.Oe === e) {
113
+ o.ze &&= l;
65
114
  return;
66
115
  }
67
116
  let s = null;
68
- const t = n.se & REACTIVE_RECOMPUTING_DEPS;
117
+ const t = n.oe & REACTIVE_RECOMPUTING_DEPS;
69
118
  if (t) {
70
- s = u !== null ? u.nt : n.tt;
71
- if (s !== null && s.it === l) {
72
- s.nl = n.Ze;
73
- n.Ye = s;
119
+ s = o !== null ? o.Ne : n.Ie;
120
+ if (s !== null && s.Oe === e) {
121
+ s.Be = n.Ye;
122
+ n.Nn = s;
74
123
  // First touch of this pass: the previous pass's label is stale.
75
- s.ye = e;
124
+ s.ze = l;
76
125
  return;
77
126
  }
78
127
  }
@@ -81,24 +130,26 @@ function link(l, n, e = false) {
81
130
  // [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
82
131
  // (the old alien-signals `isValidLink` walk, O(n²) when a computation
83
132
  // re-reads earlier deps non-consecutively, e.g. store leaf reads).
84
- const i = l.rt;
85
- if (i !== null && i.fe === n && (!t || i.nl === n.Ze)) {
133
+ const r = e.mn;
134
+ if (r !== null && r.ge === n && (!t || r.Be === n.Ye)) {
86
135
  // Gen-matched during a recompute = repeat touch this pass (AND); outside
87
136
  // a recompute there is no pass boundary, so the latest read labels it.
88
- if (t) i.ye &&= e; else i.ye = e;
137
+ if (t) r.ze &&= l; else r.ze = l;
89
138
  return;
90
139
  }
91
- const o = n.Ye = l.rt = {
92
- it: l,
93
- fe: n,
94
- nt: s,
95
- ll: i,
96
- ue: null,
97
- nl: n.Ze,
98
- ye: e
140
+ const u = n.Nn = e.mn = {
141
+ Oe: e,
142
+ ge: n,
143
+ Ne: s,
144
+ el: r,
145
+ Ae: null,
146
+ Be: n.Ye,
147
+ ze: l
99
148
  };
100
- if (u !== null) u.nt = o; else n.tt = o;
101
- if (i !== null) i.ue = o; else l.o = o;
149
+ if (o !== null) o.Ne = u; else n.Ie = u;
150
+ if (r !== null) r.Ae = u; else e.u = u;
151
+ // New subscriber edge: staged-rewrite skips (§12d) must not miss it.
152
+ bumpNotifyEpoch();
102
153
  }
103
154
 
104
- export { link, trimStaleDeps, unlinkSubs, unobserved };
155
+ export { clearDeps, dormantNodes, link, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };