@solidjs/signals 2.0.0-rc.15 → 2.0.0-rc.17

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 (90) hide show
  1. package/dist/dev-shared.js +2268 -1734
  2. package/dist/dev.attribution.js +75 -52
  3. package/dist/dev.js +1348 -658
  4. package/dist/observe/affects-marks.js +86 -0
  5. package/dist/observe/affects.js +22 -73
  6. package/dist/observe/boundaries.js +192 -190
  7. package/dist/observe/core/async.js +177 -131
  8. package/dist/observe/core/attribution-queries.js +1 -1
  9. package/dist/observe/core/attribution.js +176 -159
  10. package/dist/observe/core/constants.js +17 -3
  11. package/dist/observe/core/context.js +5 -3
  12. package/dist/observe/core/core.js +520 -364
  13. package/dist/observe/core/dev.js +66 -38
  14. package/dist/observe/core/effect.js +50 -48
  15. package/dist/observe/core/error.js +5 -3
  16. package/dist/observe/core/external.js +5 -6
  17. package/dist/observe/core/graph.js +60 -44
  18. package/dist/observe/core/heap.js +33 -33
  19. package/dist/observe/core/identities.js +62 -0
  20. package/dist/observe/core/lanes.js +238 -260
  21. package/dist/observe/core/owner.js +117 -79
  22. package/dist/observe/core/scheduler.js +381 -217
  23. package/dist/observe/core/truth.js +45 -0
  24. package/dist/observe/core/verdict.js +91 -50
  25. package/dist/observe/deferred.js +184 -0
  26. package/dist/observe/index.js +7 -1
  27. package/dist/observe/map.js +345 -260
  28. package/dist/observe/reveal.js +76 -76
  29. package/dist/observe/signals.js +47 -31
  30. package/dist/observe/store/affects.js +18 -18
  31. package/dist/observe/store/edges.js +39 -0
  32. package/dist/observe/store/optimistic.js +146 -100
  33. package/dist/observe/store/projection.js +68 -55
  34. package/dist/observe/store/store.js +180 -118
  35. package/dist/prod/affects-marks.js +86 -0
  36. package/dist/prod/affects.js +23 -72
  37. package/dist/prod/boundaries.js +156 -154
  38. package/dist/prod/core/async.js +173 -127
  39. package/dist/prod/core/constants.js +17 -3
  40. package/dist/prod/core/context.js +5 -3
  41. package/dist/prod/core/core.js +495 -343
  42. package/dist/prod/core/effect.js +70 -68
  43. package/dist/prod/core/error.js +5 -3
  44. package/dist/prod/core/external.js +5 -6
  45. package/dist/prod/core/graph.js +60 -44
  46. package/dist/prod/core/heap.js +38 -38
  47. package/dist/prod/core/identities.js +62 -0
  48. package/dist/prod/core/lanes.js +230 -252
  49. package/dist/prod/core/owner.js +114 -77
  50. package/dist/prod/core/scheduler.js +327 -163
  51. package/dist/prod/core/truth.js +45 -0
  52. package/dist/prod/core/verdict.js +90 -49
  53. package/dist/prod/deferred.js +182 -0
  54. package/dist/prod/index.js +7 -1
  55. package/dist/prod/map.js +360 -275
  56. package/dist/prod/reveal.js +76 -76
  57. package/dist/prod/signals.js +42 -26
  58. package/dist/prod/store/affects.js +6 -6
  59. package/dist/prod/store/edges.js +39 -0
  60. package/dist/prod/store/optimistic.js +143 -98
  61. package/dist/prod/store/projection.js +25 -19
  62. package/dist/prod/store/store.js +157 -100
  63. package/dist/types/affects-marks.d.ts +14 -0
  64. package/dist/types/boundaries.d.ts +1 -1
  65. package/dist/types/core/async.d.ts +10 -0
  66. package/dist/types/core/constants.d.ts +13 -1
  67. package/dist/types/core/core.d.ts +54 -5
  68. package/dist/types/core/dev.d.ts +51 -13
  69. package/dist/types/core/error.d.ts +9 -1
  70. package/dist/types/core/graph.d.ts +11 -0
  71. package/dist/types/core/identities.d.ts +17 -0
  72. package/dist/types/core/index.d.ts +2 -1
  73. package/dist/types/core/lanes.d.ts +2 -14
  74. package/dist/types/core/owner.d.ts +9 -3
  75. package/dist/types/core/scheduler.d.ts +70 -32
  76. package/dist/types/core/truth.d.ts +16 -0
  77. package/dist/types/core/types.d.ts +21 -0
  78. package/dist/types/core/verdict.d.ts +32 -0
  79. package/dist/types/deferred.d.ts +28 -0
  80. package/dist/types/index.d.ts +6 -0
  81. package/dist/types/map.d.ts +2 -2
  82. package/dist/types/signals.d.ts +28 -7
  83. package/dist/types/store/edges.d.ts +9 -0
  84. package/dist/types/store/index.d.ts +10 -3
  85. package/dist/types/store/optimistic.d.ts +3 -2
  86. package/dist/types/store/projection.d.ts +4 -3
  87. package/dist/types/store/store.d.ts +1 -1
  88. package/dist/types/store/target.d.ts +16 -8
  89. package/dist/types/store/types.d.ts +14 -0
  90. package/package.json +1 -1
@@ -53,13 +53,22 @@ const diagnostics = {
53
53
  }
54
54
  };
55
55
 
56
+ // Flight identity → earliest declared start (see `AttributionSlot.markFlight`).
57
+ // Weak: a stamp must not keep a settled promise alive.
58
+ const flightOrigins = new WeakMap;
59
+
56
60
  const attributionSlot = {
57
61
  get installed() {
58
62
  return attrHooks;
59
63
  },
60
64
  withInteraction: withInteraction,
61
65
  withOrigin: withOrigin,
62
- currentOrigin: currentOrigin
66
+ currentOrigin: currentOrigin,
67
+ markFlight(e, n = performance.now()) {
68
+ // Earliest wins (`undefined <= n` is false: the first mark always lands).
69
+ if (!(flightOrigins.get(e) <= n)) flightOrigins.set(e, n);
70
+ },
71
+ flightOrigin: e => flightOrigins.get(e)
63
72
  };
64
73
 
65
74
  const RECORDS = Symbol.for("@solidjs/signals/observe/records");
@@ -70,38 +79,38 @@ function recordsChannel() {
70
79
  const n = new Map;
71
80
  const t = new Map;
72
81
  return e[RECORDS] = {
73
- subscribe(e, o, r) {
74
- const i = n.get(e);
82
+ subscribe(e, i, o) {
83
+ const r = n.get(e);
75
84
  // Set semantics: one entry per function, however often it is passed —
76
85
  // the first subscription's options stand for it.
77
- if (i === undefined || !i.includes(o)) {
78
- n.set(e, i === undefined ? [ o ] : [ ...i, o ]);
79
- if (r !== undefined && r.bodies) {
86
+ if (r === undefined || !r.includes(i)) {
87
+ n.set(e, r === undefined ? [ i ] : [ ...r, i ]);
88
+ if (o !== undefined && o.bodies) {
80
89
  let n = t.get(e);
81
90
  if (n === undefined) t.set(e, n = new Set);
82
- n.add(o);
91
+ n.add(i);
83
92
  }
84
93
  }
85
94
  return () => {
86
- const r = n.get(e);
87
- if (r === undefined || !r.includes(o)) return;
88
- const i = r.filter(e => e !== o);
89
- if (i.length > 0) n.set(e, i); else n.delete(e);
95
+ const o = n.get(e);
96
+ if (o === undefined || !o.includes(i)) return;
97
+ const r = o.filter(e => e !== i);
98
+ if (r.length > 0) n.set(e, r); else n.delete(e);
90
99
  const s = t.get(e);
91
- if (s !== undefined && s.delete(o) && s.size === 0) t.delete(e);
100
+ if (s !== undefined && s.delete(i) && s.size === 0) t.delete(e);
92
101
  };
93
102
  },
94
- observed(e, o) {
95
- return o === "bodies" ? t.has(e) : n.has(e);
103
+ observed(e, i) {
104
+ return i === "bodies" ? t.has(e) : n.has(e);
96
105
  },
97
- emit(e, t, o) {
98
- const r = n.get(e);
99
- if (r === undefined) return;
106
+ emit(e, t, i) {
107
+ const o = n.get(e);
108
+ if (o === undefined) return;
100
109
  // A throwing listener is reported and the rest still hear the record.
101
110
  // The try/catch per call allocates nothing unless something throws.
102
- for (let e = 0; e < r.length; e++) {
111
+ for (let e = 0; e < o.length; e++) {
103
112
  try {
104
- r[e](t, o);
113
+ o[e](t, i);
105
114
  } catch (e) {
106
115
  console.error(e);
107
116
  }
@@ -149,7 +158,7 @@ let hasExclusions = false;
149
158
 
150
159
  function isExcluded(e) {
151
160
  if (!hasExclusions || !e) return false;
152
- let n = "_parent" in e ? e : e.L ?? null;
161
+ let n = "_parent" in e ? e : e.H ?? null;
153
162
  for (;n !== null; n = n._parent) {
154
163
  const e = markedOwners.get(n);
155
164
  if (e !== undefined) return e;
@@ -175,7 +184,7 @@ const DEV = undefined;
175
184
  * Public as `OBSERVE.ownerPath`; the core's own sites import it directly.
176
185
  */ function ownerPath(e) {
177
186
  if (!e) return undefined;
178
- let n = "_parent" in e ? e : e.L ?? null;
187
+ let n = "_parent" in e ? e : e.H ?? null;
179
188
  const t = [];
180
189
  for (;n !== null; n = n._parent) {
181
190
  const e = n._name;
@@ -184,15 +193,28 @@ const DEV = undefined;
184
193
  return t.length ? t.reverse() : undefined;
185
194
  }
186
195
 
196
+ /**
197
+ * The innermost source location on the subject's chain: the subject's own
198
+ * `_loc` (a signal or computation created with `{ loc }`), else the first
199
+ * `_loc` up the owners — a signal hops to its registering owner, then
200
+ * `_parent` upward (a component root carries its JSX site). The same walk
201
+ * `ownerPath` makes; `undefined` when nothing on the chain was located.
202
+ */ function locationOf(e) {
203
+ // Owners have a `_parent` key (null on a root); a signal has none and hops
204
+ // to its registering `_owner` instead.
205
+ for (let n = e; n; n = n._parent !== undefined ? n._parent : n.H) if (n._loc) return n._loc;
206
+ return undefined;
207
+ }
208
+
187
209
  /**
188
210
  * Records a diagnostic on the structured channel (listeners, captures) and
189
211
  * returns the entry. `subject` locates it: the current reactive `context` by
190
212
  * default (right for the synchronous rule checks — they fire inside the
191
213
  * scope that misbehaved); pass the node for scheduler-time findings whose
192
214
  * ambient context is the flush, or `null` for events that have no location
193
- * by nature. An `ownerPath` already on the event wins over the subject walk
194
- * (hosts whose owners are not signals' owners compute their own). Console
195
- * output is a separate, dev-tier step — see `reportDiagnostic`.
215
+ * by nature. An `ownerPath` (or `loc`) already on the event wins over the
216
+ * subject walk (hosts whose owners are not signals' owners compute their
217
+ * own). Console output is a separate, dev-tier step — see `reportDiagnostic`.
196
218
  */ function emitDiagnostic(e, n = context) {
197
219
  const t = {
198
220
  sequence: ++diagnosticSequence,
@@ -208,9 +230,13 @@ const DEV = undefined;
208
230
  const e = ownerPath(n);
209
231
  if (e) t.ownerPath = e;
210
232
  }
211
- const o = n ?? undefined;
212
- if (o !== undefined) eventSubjects.set(t, o);
213
- for (const e of diagnosticListeners) e(t, o);
233
+ if (t.loc === undefined) {
234
+ const e = locationOf(n);
235
+ if (e !== undefined) t.loc = e;
236
+ }
237
+ const i = n ?? undefined;
238
+ if (i !== undefined) eventSubjects.set(t, i);
239
+ for (const e of diagnosticListeners) e(t, i);
214
240
  for (const e of diagnosticCaptures) e.push(t);
215
241
  return t;
216
242
  }
@@ -229,9 +255,11 @@ const DEV = undefined;
229
255
  /**
230
256
  * The console face of a diagnostic — ONE entry per finding: the message, the
231
257
  * owner path (`in <App> › <TodoRow> › effect`) so a human can locate it, the
232
- * once-per-code footer as trailing lines, and — when the subject is a
233
- * binding effect the rendering runtime tagged — the element it writes, as a
234
- * second console argument (hover highlights it, click jumps to Elements).
258
+ * source location (`at src/App.tsx:18:3` — see `locationLine`) when a node on
259
+ * the chain was compiled with one, the once-per-code footer as trailing
260
+ * lines, and — when the subject is a binding effect the rendering runtime
261
+ * tagged — the element it writes, as a second console argument (hover
262
+ * highlights it, click jumps to Elements).
235
263
  * Severity picks the console method. Call sites report the entry
236
264
  * `emitDiagnostic` returned so the structured and console channels never
237
265
  * disagree. Dev-tier: in an observe build this is a no-op, so wiring paths
@@ -246,7 +274,7 @@ const DEV = undefined;
246
274
  * locate signal subjects. The per-owner `_signals` list and the devtools
247
275
  * `onGraph` hook are dev-tier — the observe build pays one property write.
248
276
  */ function registerGraph(e, n) {
249
- e.L = n;
277
+ e.H = n;
250
278
  }
251
279
 
252
280
  /**
@@ -322,16 +350,16 @@ function shouldWarnGraphSize(e, n) {
322
350
  * node, re-warning only once the count has grown by GRAPH_SIZE_WARN_EVERY.
323
351
  */ function noteFanOut(e, n, t) {
324
352
  if (!shouldWarnGraphSize(e, n)) return;
325
- const o = e._name;
326
- const r = `[HUGE_FAN_OUT] ${o ? `Signal "${o}"` : "A signal"} changed with ${n} subscribers — ` + `every one re-runs this flush. If many independent computations read the same value ` + `(for example every row of a list comparing against one selected id), prefer a per-key ` + `store or projection so only the items whose result flipped update.`;
353
+ const i = e._name;
354
+ const o = `[HUGE_FAN_OUT] ${i ? `Signal "${i}"` : "A signal"} changed with ${n} subscribers — ` + `every one re-runs this flush. If many independent computations read the same value ` + `(for example every row of a list comparing against one selected id), prefer a per-key ` + `store or projection so only the items whose result flipped update.`;
327
355
  reportDiagnostic(emitDiagnostic({
328
356
  code: "HUGE_FAN_OUT",
329
357
  kind: "graph",
330
358
  severity: "warn",
331
- message: r,
332
- nodeName: o,
359
+ message: o,
360
+ nodeName: i,
333
361
  ownerId: e.id,
334
- ownerName: o,
362
+ ownerName: i,
335
363
  data: t === undefined ? {
336
364
  count: n
337
365
  } : {
@@ -348,12 +376,12 @@ function shouldWarnGraphSize(e, n) {
348
376
  */ function noteFanIn(e, n) {
349
377
  if (!shouldWarnGraphSize(e, n)) return;
350
378
  const t = e._name;
351
- const o = `[HUGE_FAN_IN] ${t ? `Computation "${t}"` : "A computation"} tracked ${n} sources. ` + `It will re-run when any of them change. Narrow the read or split the derivation so each ` + `computation tracks only what it needs.`;
379
+ const i = `[HUGE_FAN_IN] ${t ? `Computation "${t}"` : "A computation"} tracked ${n} sources. ` + `It will re-run when any of them change. Narrow the read or split the derivation so each ` + `computation tracks only what it needs.`;
352
380
  reportDiagnostic(emitDiagnostic({
353
381
  code: "HUGE_FAN_IN",
354
382
  kind: "graph",
355
383
  severity: "warn",
356
- message: o,
384
+ message: i,
357
385
  nodeName: t,
358
386
  ownerId: e.id,
359
387
  ownerName: t,
@@ -12,30 +12,30 @@ import { trimStaleDeps } from "./graph.js";
12
12
 
13
13
  import { enqueueSub } from "./heap.js";
14
14
 
15
- import { globalQueue, schedule, GlobalQueue, haltReactivity } from "./scheduler.js";
15
+ import { globalQueue, schedule, heldRunHook, haltReactivity, GlobalQueue } from "./scheduler.js";
16
16
 
17
17
  /**
18
18
  * Effects are the leaf nodes of our reactive graph. When their sources change, they are
19
19
  * automatically added to the queue of effects to re-execute, which will cause them to fetch their
20
20
  * sources and recompute
21
- */ function effect(t, e, u, o) {
22
- const E = !!o?.user;
23
- const r = createEffectNode(t, e, u, E ? EFFECT_USER : EFFECT_RENDER, o);
21
+ */ function effect(t, e, o, u) {
22
+ const E = !!u?.user;
23
+ const r = createEffectNode(t, e, o, E ? EFFECT_USER : EFFECT_RENDER, u);
24
24
  recompute(r, true);
25
25
  // A first pass that read a staged value was staged itself (recompute: born
26
26
  // staged); the flush's commit replays this effect. Its first run is not this
27
27
  // creation's (A29). A lane's node likewise: its run is the lane's, queued
28
28
  // by the pass and released at the reveal (lanes.ts).
29
- !o?.defer && r.Oe === NOT_PENDING && !r.m?._t?.B && (r.u === EFFECT_USER || o?.schedule ? globalQueue.enqueue(r.u, runEffect.bind(null, r)) : runEffect(r, r.u));
29
+ !u?.defer && r.ue === NOT_PENDING && !r.T?.Je?.V && (r.i === EFFECT_USER || u?.schedule ? globalQueue.enqueue(r.i, runEffect.bind(null, r)) : runEffect(r, r.i));
30
30
  }
31
31
 
32
32
  function notifyEffectStatus(t, e) {
33
33
  // Use passed values if provided, otherwise read from node
34
- const u = t !== undefined ? t : this.S;
35
- const o = e !== undefined ? e : this.m?.F;
36
- if (u & STATUS_ERROR) {
34
+ const o = t !== undefined ? t : this.m;
35
+ const u = e !== undefined ? e : this.T?.F;
36
+ if (o & STATUS_ERROR) {
37
37
  globalQueue.notify(this, STATUS_PENDING, 0);
38
- if (this.u === EFFECT_USER) {
38
+ if (this.i === EFFECT_USER) {
39
39
  // The error handler is the error arm of the effect phase (#2840 ruling):
40
40
  // queue it like the effect function. It runs in the same imperative,
41
41
  // writable scope and throws escalate the same way. No payload is queued — the node already carries `_statusFlags`/`_error`,
@@ -43,23 +43,25 @@ function notifyEffectStatus(t, e) {
43
43
  // phase takes the success arm instead. Blocked forwards (explicit
44
44
  // `status` arg without node-state writes) don't queue: the status
45
45
  // re-propagates unblocked at commit.
46
- if (this.S & STATUS_ERROR) {
47
- this.lt = true;
48
- globalQueue.enqueue(this.u, this.Y ??= runEffect.bind(null, this));
46
+ if (this.m & STATUS_ERROR) {
47
+ this.Qe = true;
48
+ globalQueue.enqueue(this.i, this.W ??= runEffect.bind(null, this));
49
49
  }
50
50
  return;
51
51
  }
52
52
  if (!globalQueue.notify(this, STATUS_ERROR, STATUS_ERROR)) {
53
- haltReactivity(unwrapStatusError(o));
54
- throw o;
53
+ // Dev locates the halt at the node that threw: the StatusError's
54
+ // source, upstream of this effect when a computed failed.
55
+ haltReactivity(unwrapStatusError(u));
56
+ throw u;
55
57
  }
56
- } else if (this.u === EFFECT_RENDER) {
57
- globalQueue.notify(this, STATUS_PENDING | STATUS_ERROR, u, o);
58
+ } else if (this.i === EFFECT_RENDER) {
59
+ globalQueue.notify(this, STATUS_PENDING | STATUS_ERROR, o, u);
58
60
  }
59
61
  }
60
62
 
61
63
  function runEffect(t, e) {
62
- if (!t.lt || t.R & REACTIVE_DISPOSED) return;
64
+ if (!t.Qe || t.R & REACTIVE_DISPOSED) return;
63
65
  // A queued run behind a fallback (boundaries.ts) waits for the reveal: a
64
66
  // user effect's, which would read a DOM that is not attached, and a render
65
67
  // effect's update too (maintainer, 2026-10-02: "we held the queue but let
@@ -68,7 +70,7 @@ function runEffect(t, e) {
68
70
  // hidden subtree. The synchronous first render on creation is not a queued
69
71
  // run and goes through. `_modified` stays set; the boundary re-queues the
70
72
  // run (`release`).
71
- if (GlobalQueue.Ee && GlobalQueue.Ee(t)) return;
73
+ if (heldRunHook?.(t)) return;
72
74
  // Error arm (#2840), user effects only: a compute-phase error that is still
73
75
  // the node's settled state at effect time runs the bundle's error handler in
74
76
  // this same imperative, writable scope. Unwrap the StatusError used for
@@ -79,12 +81,12 @@ function runEffect(t, e) {
79
81
  // Render effects bypass: their errors route to boundaries synchronously in
80
82
  // notifyEffectStatus, and a runner queued by an earlier valueChanged in the
81
83
  // same flush must not be hijacked by a later-arriving error status.
82
- if (t.S & STATUS_ERROR && t.u === EFFECT_USER) {
83
- const e = unwrapStatusError(t.m?.F);
84
- t.Nt = t.Ae;
85
- t.lt = false;
84
+ if (t.m & STATUS_ERROR && t.i === EFFECT_USER) {
85
+ const e = unwrapStatusError(t.T?.F);
86
+ t._t = t.Ie;
87
+ t.Qe = false;
86
88
  try {
87
- t.Lt ? t.Lt(e, () => {
89
+ t.ht ? t.ht(e, () => {
88
90
  const e = t.kt;
89
91
  t.kt = undefined;
90
92
  e?.();
@@ -99,43 +101,43 @@ function runEffect(t, e) {
99
101
  }
100
102
  // Captured before the callback: its own throw errors the node below, but
101
103
  // the compute pass that produced `_value` was clean, so its tail still goes.
102
- const u = t.m?.F == null;
104
+ const o = t.T?.F == null;
103
105
  // Observe tier, like its `effectRunEnd` twin below: the frame the engine
104
106
  // opens here is what stamps the callback's writes as the effect's (the
105
107
  // cascade an observer reports) and what times the callback (the `effect`
106
108
  // record) — facts a production observer needs, not only a dev console.
107
109
  if (attrHooks !== null) attrHooks.effectRunStart(t);
108
- const o = t.kt;
110
+ const u = t.kt;
109
111
  t.kt = undefined;
110
112
  try {
111
- o?.();
112
- const e = t.Ut(t.Ae, t.Nt);
113
+ u?.();
114
+ const e = t.Ge(t.Ie, t._t);
113
115
  if (false && e !== undefined && typeof e !== "function") ;
114
116
  // The final cleanup is invoked by disposeChildren at true disposal.
115
117
  t.kt = e;
116
118
  } catch (e) {
117
119
  ext(t).F = new StatusError(t, e);
118
- t.S |= STATUS_ERROR;
120
+ t.m |= STATUS_ERROR;
119
121
  if (!globalQueue.notify(t, STATUS_ERROR, STATUS_ERROR)) {
120
122
  haltReactivity(e);
121
123
  throw e;
122
124
  }
123
125
  } finally {
124
- t.Nt = t.Ae;
125
- t.lt = false;
126
+ t._t = t.Ie;
127
+ t.Qe = false;
126
128
  // The run applied: this is the frame now, so the dependency tail the
127
129
  // compute pass left linked goes (A30, #3438 — `recompute` defers an
128
130
  // effect's trim while a run is owed; the twin of `commitPendingNode`'s
129
131
  // trim for a staged pass). An errored compute kept its full list with
130
132
  // `_depsTail` marking where it stopped; leave it, as the commit does.
131
- if (u) trimStaleDeps(t);
133
+ if (o) trimStaleDeps(t);
132
134
  }
133
135
  // Outside the try (see the rule in attribution-hooks.ts). Reached whether or
134
136
  // not the callback threw — a throw that escapes the catch above halts.
135
137
  if (attrHooks !== null) attrHooks.effectRunEnd(t);
136
138
  }
137
139
 
138
- GlobalQueue.q = runEffect;
140
+ GlobalQueue.K = runEffect;
139
141
 
140
142
  /**
141
143
  * Internal tracked effect - bypasses heap, goes directly to effect queue.
@@ -146,38 +148,38 @@ GlobalQueue.q = runEffect;
146
148
  // `_modified` is NOT redundant with the heap: the heap dedups within a
147
149
  // pass, but several passes in one flush each enqueue `_run` into the same
148
150
  // user queue, and this gate is what collapses them into one run.
149
- if (!u.lt || u.R & REACTIVE_DISPOSED) return;
150
- if (GlobalQueue.Ee && GlobalQueue.Ee(u)) return;
151
+ if (!o.Qe || o.R & REACTIVE_DISPOSED) return;
152
+ if (heldRunHook?.(o)) return;
151
153
  try {
152
- u.lt = false;
153
- recompute(u);
154
+ o.Qe = false;
155
+ recompute(o);
154
156
  } finally {}
155
157
  };
156
- const u = computed(() => {
157
- const e = u.kt;
158
- u.kt = undefined;
158
+ const o = computed(() => {
159
+ const e = o.kt;
160
+ o.kt = undefined;
159
161
  e?.();
160
- const o = staleValues(t);
161
- u.kt = o;
162
+ const u = staleValues(t);
163
+ o.kt = u;
162
164
  }, {
163
165
  ...e,
164
166
  lazy: true
165
167
  });
166
- u.kt = undefined;
167
- u.i = u.i & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
168
- u.lt = true;
169
- u.u = EFFECT_TRACKED;
168
+ o.kt = undefined;
169
+ o.l = o.l & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
170
+ o.Qe = true;
171
+ o.i = EFFECT_TRACKED;
170
172
  // Observe-tier label: the computed literal defaulted its `_name` slot to
171
173
  // "computed"; relabel by kind (a store into the slot, not a new field).
172
- if (e?.name === undefined) u._name = "trackedEffect";
174
+ if (e?.name === undefined) o._name = "trackedEffect";
173
175
  // Status dispatch rides the SHARED notifier (statusNotifierOf keys off
174
176
  // _type): its error arm is behavior-identical to the closure that used to
175
177
  // live here, without the per-node NodeExtension allocation.
176
- u.M = run;
178
+ o.M = run;
177
179
  // The first run rides the heap like every wake (GlobalQueue._update), so a
178
180
  // tracked effect created inside a render-effect callback runs after that
179
181
  // pass's staged writes commit, not before.
180
- enqueueSub(u);
182
+ enqueueSub(o);
181
183
  schedule();
182
184
  }
183
185
 
@@ -23,7 +23,6 @@
23
23
  * ```
24
24
  */
25
25
  class NotReadyError extends Error {
26
- source;
27
26
  constructor(r) {
28
27
  // Control-flow throw: it happens on every read of a pending source, so in
29
28
  // production skip V8's eager stack capture (proportional to stack depth —
@@ -40,9 +39,12 @@ class NotReadyError extends Error {
40
39
  }
41
40
 
42
41
  class StatusError extends Error {
43
- source;
44
42
  constructor(r, o) {
45
- super(o instanceof Error ? o.message : String(o), {
43
+ // Best-effort message: formatting must never replace the original (#4112).
44
+ try {
45
+ var t = String(o instanceof Error ? o.message : o);
46
+ } catch {}
47
+ super(t, {
46
48
  cause: o
47
49
  });
48
50
  this.source = r;
@@ -2,7 +2,7 @@ import { signal, setSignal, read } from "./core.js";
2
2
 
3
3
  import { cleanup } from "./owner.js";
4
4
 
5
- import { GlobalQueue } from "./scheduler.js";
5
+ import { setExternalHooks } from "./scheduler.js";
6
6
 
7
7
  let externalSourceConfig = null;
8
8
 
@@ -37,7 +37,7 @@ let externalSourceConfig = null;
37
37
  * ```
38
38
  */
39
39
  // Wires a freshly created computed through the active external-source bridge.
40
- // Lives here (installed on GlobalQueue while a config is active) rather than
40
+ // Lives here (installed as a scheduler hook while a config is active) rather than
41
41
  // inline in core: esbuild cannot literal-track the mutable config binding the
42
42
  // way rollup does, so an inline `if (externalSourceConfig)` block ships in
43
43
  // every bundle even though only enableExternalSource() can make it reachable.
@@ -46,11 +46,11 @@ function wireExternalSource(e) {
46
46
  equals: false,
47
47
  ownedWrite: true
48
48
  });
49
- const r = externalSourceConfig.factory(e.ee, () => {
49
+ const r = externalSourceConfig.factory(e.X, () => {
50
50
  setSignal(n, undefined);
51
51
  });
52
52
  cleanup(() => r.dispose());
53
- e.ee = e => {
53
+ e.X = e => {
54
54
  read(n);
55
55
  return r.track(e);
56
56
  };
@@ -64,8 +64,7 @@ function externalUntrack(e) {
64
64
  // removed on reset) so core's presence checks stay equivalent to the old
65
65
  // `externalSourceConfig` truthiness checks.
66
66
  function syncExternalHooks() {
67
- GlobalQueue.xt = externalSourceConfig ? wireExternalSource : undefined;
68
- GlobalQueue.Wt = externalSourceConfig ? externalUntrack : undefined;
67
+ if (externalSourceConfig) setExternalHooks(wireExternalSource, externalUntrack); else setExternalHooks(undefined, undefined);
69
68
  }
70
69
 
71
70
  function enableExternalSource(e) {
@@ -1,8 +1,8 @@
1
- import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, REACTIVE_RECOMPUTING_DEPS, CONFIG_SLOT_NODE } from "./constants.js";
1
+ import { REACTIVE_RECOMPUTING_DEPS, CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE } from "./constants.js";
2
2
 
3
3
  import { deleteFromHeap } from "./heap.js";
4
4
 
5
- import { disposeChildren } from "./owner.js";
5
+ import { disposeChildren, runCleanup } from "./owner.js";
6
6
 
7
7
  import { bumpNotifyEpoch, dirtyQueue } from "./scheduler.js";
8
8
 
@@ -17,38 +17,42 @@ function setSlotUnobserved(e) {
17
17
 
18
18
  // https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
19
19
  function unlinkSubs(e) {
20
- const n = e.I;
21
- const o = e._;
22
- const l = e.o;
23
- const t = e.ln;
24
- if (l !== null) l.ln = t; else n.Dt = t;
25
- if (t !== null) t.o = l; else {
26
- n.t = l;
27
- if (l === null) {
20
+ const n = e.S;
21
+ const l = e.G;
22
+ const o = e.t;
23
+ const s = e.en;
24
+ if (o !== null) o.en = s; else n.dt = s;
25
+ if (s !== null) s.t = o; else {
26
+ n.o = o;
27
+ if (o === null) {
28
28
  // Store slot nodes dispatch to the ONE shared hook — no per-node
29
29
  // unobserved closure, no NodeExtension to hold it.
30
- if (n.i & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.m?.Ft?.();
30
+ // A user hook that throws is collected like a cleanup (owner.ts): the
31
+ // unlink and the teardown around it carry on.
32
+ if (n.l & CONFIG_SLOT_NODE) slotUnobservedHook(n); else if (n.T?.Dt) runCleanup(n.T.Dt);
31
33
  // No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
32
34
  // A pending node is exempt: its in-flight async work is an observer —
33
35
  // tearing down would orphan the work and re-execute it on the next
34
36
  // read. The settle path runs this same last-one-out check when that
35
37
  // observer releases (the untracked-read dormancy sweep guards on
36
38
  // pending identically).
39
+ // During a pass's teardown of its unfinished frame, the release waits
40
+ // for the pass to end (`deferredReleases`, #4142).
37
41
  const e = n;
38
- e.ee && e.i & CONFIG_AUTO_DISPOSE && !(e.R & REACTIVE_ZOMBIE) && !(e.S & STATUS_PENDING) && unobserved(e);
42
+ e.X && e.l & CONFIG_AUTO_DISPOSE && !(e.R & REACTIVE_ZOMBIE) && !(e.m & STATUS_PENDING) && (deferredReleases ? deferredReleases.push(e) : unobserved(e));
39
43
  }
40
44
  }
41
- return o;
45
+ return l;
42
46
  }
43
47
 
44
48
  function trimStaleDeps(e) {
45
- const n = e.p;
46
- let o = n !== null ? n._ : e.G;
47
- if (o !== null) {
49
+ const n = e._;
50
+ let l = n !== null ? n.G : e.C;
51
+ if (l !== null) {
48
52
  do {
49
- o = unlinkSubs(o);
50
- } while (o !== null);
51
- if (n !== null) n._ = null; else e.G = null;
53
+ l = unlinkSubs(l);
54
+ } while (l !== null);
55
+ if (n !== null) n.G = null; else e.C = null;
52
56
  }
53
57
  }
54
58
 
@@ -57,15 +61,27 @@ function trimStaleDeps(e) {
57
61
  // and skipping early also avoids adding one (hidden-class churn) via the
58
62
  // null-out below.
59
63
  function clearDeps(e) {
60
- let n = e.G;
64
+ let n = e.C;
61
65
  if (!n) return;
62
66
  do {
63
67
  n = unlinkSubs(n);
64
68
  } while (n !== null);
65
- e.G = null;
66
- e.p = null;
69
+ e.C = null;
70
+ e._ = null;
67
71
  }
68
72
 
73
+ /**
74
+ * Last-one-out releases held back while a pass tears down the frame of an
75
+ * earlier pass that never committed (#4142). The pass is about to rebuild
76
+ * the same children, which read the same lazy nodes again. Released on the
77
+ * spot, a lazy async memo whose only reader was the old frame's child memo
78
+ * was torn down, re-ran on the new child's read, went pending, and the cycle
79
+ * repeated forever. `recompute` collects them around that teardown and
80
+ * releases what is still unobserved when the pass ends.
81
+ */ let deferredReleases = null;
82
+
83
+ const deferReleases = e => deferredReleases = e;
84
+
69
85
  function unobserved(e) {
70
86
  deleteFromHeap(e, dirtyQueue);
71
87
  clearDeps(e);
@@ -101,7 +117,7 @@ function sweepDormant() {
101
117
  // is an observer; the settle path re-runs last-one-out), lost its
102
118
  // AUTO_DISPOSE bit (owner teardown strips it, #3024), or already been
103
119
  // torn down.
104
- if (!e.t && e.i & CONFIG_AUTO_DISPOSE && !(e.S & STATUS_PENDING) && !(e.R & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
120
+ if (!e.o && e.l & CONFIG_AUTO_DISPOSE && !(e.m & STATUS_PENDING) && !(e.R & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
105
121
  unobserved(e);
106
122
  }
107
123
  }
@@ -110,15 +126,15 @@ function sweepDormant() {
110
126
 
111
127
  // https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L52
112
128
  function link(e, n) {
113
- const o = n.p;
114
- if (o !== null && o.I === e) return;
115
- let l = null;
116
- const t = n.R & REACTIVE_RECOMPUTING_DEPS;
117
- if (t) {
118
- l = o !== null ? o._ : n.G;
119
- if (l !== null && l.I === e) {
120
- l.Pe = n.pe;
121
- n.p = l;
129
+ const l = n._;
130
+ if (l !== null && l.S === e) return;
131
+ let o = null;
132
+ const s = n.R & REACTIVE_RECOMPUTING_DEPS;
133
+ if (s) {
134
+ o = l !== null ? l.G : n.C;
135
+ if (o !== null && o.S === e) {
136
+ o.Te = n.Ne;
137
+ n._ = o;
122
138
  return;
123
139
  }
124
140
  }
@@ -127,20 +143,20 @@ function link(e, n) {
127
143
  // [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
128
144
  // (the old alien-signals `isValidLink` walk, O(n²) when a computation
129
145
  // re-reads earlier deps non-consecutively, e.g. store leaf reads).
130
- const s = e.Dt;
131
- if (s !== null && s.l === n && (!t || s.Pe === n.pe)) return;
132
- const u = n.p = e.Dt = {
133
- I: e,
134
- l: n,
135
- _: l,
136
- ln: s,
137
- o: null,
138
- Pe: n.pe
146
+ const r = e.dt;
147
+ if (r !== null && r.u === n && (!s || r.Te === n.Ne)) return;
148
+ const t = n._ = e.dt = {
149
+ S: e,
150
+ u: n,
151
+ G: o,
152
+ en: r,
153
+ t: null,
154
+ Te: n.Ne
139
155
  };
140
- if (o !== null) o._ = u; else n.G = u;
141
- if (s !== null) s.o = u; else e.t = u;
156
+ if (l !== null) l.G = t; else n.C = t;
157
+ if (r !== null) r.t = t; else e.o = t;
142
158
  // New subscriber edge: staged-rewrite skips (§12d) must not miss it.
143
159
  bumpNotifyEpoch();
144
160
  }
145
161
 
146
- export { clearDeps, dormantNodes, link, setSlotUnobserved, slotUnobservedHook, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };
162
+ export { clearDeps, deferReleases, deferredReleases, dormantNodes, link, setSlotUnobserved, slotUnobservedHook, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };