@solidjs/signals 2.0.0-rc.6 → 2.0.0-rc.8

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 (131) hide show
  1. package/dist/dev-shared.js +5243 -0
  2. package/dist/dev.attribution.js +2333 -0
  3. package/dist/dev.js +1758 -6621
  4. package/dist/observe/affects.js +127 -0
  5. package/dist/observe/attribution.js +1 -0
  6. package/dist/observe/boundaries.js +586 -0
  7. package/dist/observe/core/action.js +167 -0
  8. package/dist/observe/core/async.js +736 -0
  9. package/dist/observe/core/attribution-hooks.js +60 -0
  10. package/dist/observe/core/attribution.js +2318 -0
  11. package/dist/{types-cjs/core/constants.d.cts → observe/core/constants.js} +135 -71
  12. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  13. package/dist/observe/core/core.js +1289 -0
  14. package/dist/observe/core/dev.js +232 -0
  15. package/dist/observe/core/effect.js +179 -0
  16. package/dist/observe/core/error.js +80 -0
  17. package/dist/observe/core/external.js +98 -0
  18. package/dist/observe/core/graph.js +155 -0
  19. package/dist/observe/core/heap.js +147 -0
  20. package/dist/observe/core/invariants.js +43 -0
  21. package/dist/observe/core/lanes.js +168 -0
  22. package/dist/observe/core/optimistic.js +438 -0
  23. package/dist/observe/core/owner.js +308 -0
  24. package/dist/observe/core/scheduler.js +1190 -0
  25. package/dist/observe/core/verdict.js +551 -0
  26. package/dist/observe/index.js +55 -0
  27. package/dist/observe/map.js +482 -0
  28. package/dist/{types-cjs/signals.d.cts → observe/signals.js} +305 -317
  29. package/dist/observe/store/index.js +38 -0
  30. package/dist/observe/store/next/optimistic.js +651 -0
  31. package/dist/observe/store/next/projection.js +242 -0
  32. package/dist/observe/store/next/reconcile.js +373 -0
  33. package/dist/observe/store/next/store.js +2213 -0
  34. package/dist/observe/store/next/target.js +51 -0
  35. package/dist/observe/store/store.js +323 -0
  36. package/dist/observe/store/storePath.js +103 -0
  37. package/dist/observe/store/utils.js +210 -0
  38. package/dist/prod/attribution.js +32 -0
  39. package/dist/prod/boundaries.js +3 -1
  40. package/dist/prod/core/action.js +52 -32
  41. package/dist/prod/core/async.js +177 -128
  42. package/dist/prod/core/attribution-hooks.js +3 -0
  43. package/dist/prod/core/constants.js +32 -1
  44. package/dist/prod/core/context.js +10 -16
  45. package/dist/prod/core/core.js +505 -286
  46. package/dist/prod/core/dev.js +2 -0
  47. package/dist/prod/core/effect.js +72 -43
  48. package/dist/prod/core/external.js +2 -2
  49. package/dist/prod/core/graph.js +40 -36
  50. package/dist/prod/core/heap.js +50 -51
  51. package/dist/prod/core/lanes.js +43 -22
  52. package/dist/prod/core/optimistic.js +224 -80
  53. package/dist/prod/core/owner.js +43 -39
  54. package/dist/prod/core/scheduler.js +347 -232
  55. package/dist/prod/core/verdict.js +71 -74
  56. package/dist/prod/index.js +9 -5
  57. package/dist/prod/map.js +311 -150
  58. package/dist/prod/signals.js +52 -38
  59. package/dist/prod/store/next/optimistic.js +127 -131
  60. package/dist/prod/store/next/projection.js +3 -3
  61. package/dist/prod/store/next/reconcile.js +149 -294
  62. package/dist/prod/store/next/store.js +694 -380
  63. package/dist/prod/store/next/target.js +32 -10
  64. package/dist/prod/store/store.js +12 -14
  65. package/dist/prod/store/utils.js +36 -27
  66. package/dist/types/attribution.d.ts +15 -0
  67. package/dist/types/attribution.prod.d.ts +13 -0
  68. package/dist/types/core/async.d.ts +1 -1
  69. package/dist/types/core/attribution-hooks.d.ts +183 -6
  70. package/dist/types/core/attribution.d.ts +435 -24
  71. package/dist/types/core/constants.d.ts +31 -0
  72. package/dist/types/core/core.d.ts +19 -3
  73. package/dist/types/core/dev.d.ts +165 -26
  74. package/dist/types/core/effect.d.ts +8 -1
  75. package/dist/types/core/heap.d.ts +5 -3
  76. package/dist/types/core/index.d.ts +2 -1
  77. package/dist/types/core/invariants.d.ts +1 -1
  78. package/dist/types/core/lanes.d.ts +17 -0
  79. package/dist/types/core/scheduler.d.ts +69 -4
  80. package/dist/types/core/types.d.ts +29 -9
  81. package/dist/types/index.d.ts +9 -2
  82. package/dist/types/map.d.ts +2 -0
  83. package/dist/types/signals.d.ts +10 -0
  84. package/dist/types/store/index.d.ts +4 -6
  85. package/dist/types/store/next/optimistic.d.ts +4 -2
  86. package/dist/types/store/next/reconcile.d.ts +5 -12
  87. package/dist/types/store/next/store.d.ts +8 -9
  88. package/dist/types/store/next/target.d.ts +56 -55
  89. package/dist/types/store/store.d.ts +14 -9
  90. package/dist/types/store/utils.d.ts +7 -0
  91. package/package.json +21 -16
  92. package/dist/node.cjs +0 -11121
  93. package/dist/prod/store/next/patch-hooks.js +0 -13
  94. package/dist/prod/store/next/patch.js +0 -614
  95. package/dist/types/store/next/patch-hooks.d.ts +0 -41
  96. package/dist/types/store/next/patch.d.ts +0 -91
  97. package/dist/types-cjs/affects.d.cts +0 -47
  98. package/dist/types-cjs/boundaries.d.cts +0 -175
  99. package/dist/types-cjs/core/action.d.cts +0 -64
  100. package/dist/types-cjs/core/async.d.cts +0 -23
  101. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -63
  102. package/dist/types-cjs/core/attribution.d.cts +0 -239
  103. package/dist/types-cjs/core/core.d.cts +0 -176
  104. package/dist/types-cjs/core/dev.d.cts +0 -95
  105. package/dist/types-cjs/core/effect.d.cts +0 -30
  106. package/dist/types-cjs/core/error.d.cts +0 -56
  107. package/dist/types-cjs/core/external.d.cts +0 -15
  108. package/dist/types-cjs/core/graph.d.cts +0 -28
  109. package/dist/types-cjs/core/heap.d.cts +0 -22
  110. package/dist/types-cjs/core/index.d.cts +0 -13
  111. package/dist/types-cjs/core/invariants.d.cts +0 -59
  112. package/dist/types-cjs/core/lanes.d.cts +0 -44
  113. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  114. package/dist/types-cjs/core/owner.d.cts +0 -124
  115. package/dist/types-cjs/core/scheduler.d.cts +0 -231
  116. package/dist/types-cjs/core/types.d.cts +0 -204
  117. package/dist/types-cjs/core/verdict.d.cts +0 -2
  118. package/dist/types-cjs/index.d.cts +0 -10
  119. package/dist/types-cjs/map.d.cts +0 -69
  120. package/dist/types-cjs/package.json +0 -3
  121. package/dist/types-cjs/store/index.d.cts +0 -21
  122. package/dist/types-cjs/store/next/optimistic.d.cts +0 -23
  123. package/dist/types-cjs/store/next/patch-hooks.d.cts +0 -41
  124. package/dist/types-cjs/store/next/patch.d.cts +0 -91
  125. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  126. package/dist/types-cjs/store/next/reconcile.d.cts +0 -17
  127. package/dist/types-cjs/store/next/store.d.cts +0 -127
  128. package/dist/types-cjs/store/next/target.d.cts +0 -192
  129. package/dist/types-cjs/store/store.d.cts +0 -138
  130. package/dist/types-cjs/store/storePath.d.cts +0 -58
  131. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -0,0 +1,736 @@
1
+ import { STATUS_UNINITIALIZED, CONFIG_CHILD_COMPANIONS, STATUS_ERROR, STATUS_PENDING, CONFIG_INPUTS_PUBLISHED, REACTIVE_DIRTY, REACTIVE_OPTIMISTIC_DIRTY, NOT_PENDING, CONFIG_AUTO_DISPOSE, REACTIVE_ZOMBIE, REACTIVE_DISPOSED } from "./constants.js";
2
+
3
+ import { attrHooks } from "./attribution-hooks.js";
4
+
5
+ import { untrack, ext, statusNotifierOf, setSignal, context } from "./core.js";
6
+
7
+ import "./invariants.js";
8
+
9
+ import { StatusError, NotReadyError } from "./error.js";
10
+
11
+ import { trimStaleDeps, unobserved } from "./graph.js";
12
+
13
+ import { enqueueSub } from "./heap.js";
14
+
15
+ import { hasActiveOverride, assignOrMergeLane, resolveLane, resolveTransition } from "./lanes.js";
16
+
17
+ import { cleanup } from "./owner.js";
18
+
19
+ import { GlobalQueue, schedule, flush, queuePendingNode, insertSubs, clock, waitingTransition, currentTransition, globalQueue, setOrigin, origin } from "./scheduler.js";
20
+
21
+ // The lazily-created Set is the ONE container for pending sources. Its
22
+ // predecessor — a singular slot promoted to a Set on the second source —
23
+ // created dual state whose migration invariant was easy to break: a third
24
+ // overlapping source landed beside the Set and removePendingSource refused
25
+ // to clear it, stranding the Set members' pending forever (#2893).
26
+ function addPendingSource(e, t) {
27
+ if (e.o?.ee?.has(t)) return false;
28
+ (ext(e).ee ??= new Set).add(t);
29
+ return true;
30
+ }
31
+
32
+ function removePendingSource(e, t) {
33
+ const n = e.o?.ee;
34
+ if (!n?.delete(t)) return false;
35
+ if (!n.size) e.o.ee = undefined;
36
+ return true;
37
+ }
38
+
39
+ function clearPendingSources(e) {
40
+ // This set is node-owned and never shared; dropping the sole reference
41
+ // releases the set and every entry without a redundant clear() walk.
42
+ if (e.o !== null) e.o.ee = undefined;
43
+ }
44
+
45
+ // A rejection-pending only resolves through the settle sweep over the
46
+ // SOURCE's subscribers, so it is retryable iff a tracked read created that
47
+ // edge: a dep that IS the source, or one whose own pending chain carries it
48
+ // (pending sources propagate the origin node, so this covers any depth).
49
+ // Also guards branch-local recovery: another dependency may still need the source.
50
+ function retryReaches(e, t) {
51
+ for (let n = e.te; n; n = n.ne) {
52
+ const e = n.oe.re || n.oe;
53
+ if (e === t || e.o?.ee?.has(t)) return true;
54
+ }
55
+ return false;
56
+ }
57
+
58
+ /**
59
+ * A loading-window node hit an unready source (sync throw in recompute, or a
60
+ * NotReadyError-rejected flight): register for the source's settle — the
61
+ * settlePendingSource walk runs off `_pendingSources` + `_blocked` alone —
62
+ * with NO read-visible pending status, no downstream propagation, no
63
+ * transition, no lane registration. Commit #0 keeps serving.
64
+ */ function parkLoadingWindow(e, t) {
65
+ ext(e).ie = true;
66
+ if (t.source) addPendingSource(e, t.source);
67
+ // A settled error is the node's answer ("the error stays the answer until
68
+ // this retry can actually run") — the park must not replace it: reads
69
+ // throw `_error` while STATUS_ERROR is set, and overwriting it here leaks
70
+ // a pending-class NotReadyError from a read-invisible park (#2989).
71
+ if (!(e.S & STATUS_ERROR)) setPendingError(e, t.source, t);
72
+ }
73
+
74
+ function setPendingError(e, t, n) {
75
+ if (!t) {
76
+ if (e.o !== null) e.o._ = null;
77
+ return;
78
+ }
79
+ if (n instanceof NotReadyError && n.source === t) {
80
+ ext(e)._ = n;
81
+ return;
82
+ }
83
+ const r = e.o?._;
84
+ if (!(r instanceof NotReadyError) || r.source !== t) {
85
+ ext(e)._ = new NotReadyError(t);
86
+ }
87
+ }
88
+
89
+ function forEachDependent(e, t) {
90
+ for (let n = e.u; n !== null; n = n.se) t(n.le, n);
91
+ // `?? null`: affects() marks route plain signals (no `_child` slot) through here.
92
+ for (let n = e.o?.i ?? null; n !== null; n = n.ue) {
93
+ for (let e = n.u; e !== null; e = e.se) t(e.le, e);
94
+ }
95
+ }
96
+
97
+ // Queue a node to re-run on the next flush (used both when a pending source
98
+ // settles and when an `isPending` observer must re-evaluate after a real error):
99
+ // shared scheduling helper in heap.ts (tracked effects bypass the heap).
100
+ // Settle-time counterpart of unlinkSubs' last-one-out check. A lazy node that
101
+ // loses its last subscriber while STATUS_PENDING is exempt from autodispose
102
+ // (the in-flight work is an observer), so whatever CLEARS that pending state
103
+ // must run the release — otherwise the node stays linked and recomputes
104
+ // forever with zero subscribers (#2934). The node's own promise/iterator
105
+ // callbacks handle their own release (settleAutodispose in handleAsync); this
106
+ // covers derivatively-pending dependents, which have no callbacks of their own.
107
+ function releaseIfSettledUnobserved(e) {
108
+ e.ot && e.T & CONFIG_AUTO_DISPOSE && !e.u && !(e.it & REACTIVE_ZOMBIE) && !(e.S & STATUS_PENDING) && unobserved(e);
109
+ }
110
+
111
+ // Error-path sweep: notifyStatus(STATUS_ERROR) clears dependents' pending
112
+ // sources through its own recursion (no per-node settle callback), so after
113
+ // the propagation completes, walk the same graph for stranded lazy nodes.
114
+ // Collect-then-release so unobserved() never unlinks under the walk.
115
+ function releaseSettledDependents(e) {
116
+ let t;
117
+ const n = new Set;
118
+ const visit = e => {
119
+ if (n.has(e)) return;
120
+ n.add(e);
121
+ if (!e.u && e.T & CONFIG_AUTO_DISPOSE) (t ??= []).push(e);
122
+ forEachDependent(e, visit);
123
+ };
124
+ forEachDependent(e, visit);
125
+ if (t) for (const e of t) releaseIfSettledUnobserved(e);
126
+ }
127
+
128
+ // Error-dimension twin of settlePendingSource's blocked re-enqueue (#2949):
129
+ // a node in STATUS_ERROR that recovers by recomputing to an UNCHANGED value
130
+ // fires no value notification — the recovery is completely silent. But a
131
+ // dependent that re-ran during the error window consumed its dirty flag and
132
+ // committed nothing (the fresh sibling values it read were absorbed into an
133
+ // errored run), so its committed value is stale. The propagated error is one
134
+ // object identity down the whole dependent tree, and holding it is exactly
135
+ // the "blocked on this error" marker — re-enqueue those holders so they
136
+ // re-run: fresh values commit and flow, and a dependent with another
137
+ // still-broken source simply re-errors. Pending recovery uses
138
+ // settlePendingSource to clear inherited status and retry blocked readers.
139
+ // Walks the full dependent graph
140
+ // (releaseSettledDependents shape): identity holders can sit below an
141
+ // intermediate whose own error state has since been scrubbed or replaced
142
+ // (e.g. an error boundary's tree node).
143
+ function settleErroredDependents(e, t) {
144
+ let n = false;
145
+ const r = new Set;
146
+ const visit = e => {
147
+ if (r.has(e)) return;
148
+ r.add(e);
149
+ if (e.o?._ === t) {
150
+ enqueueSub(e);
151
+ n = true;
152
+ }
153
+ forEachDependent(e, visit);
154
+ };
155
+ forEachDependent(e, visit);
156
+ if (n) schedule();
157
+ }
158
+
159
+ // Retire `source` from pending state along the dependent graph rooted at `el`.
160
+ // By default, `el` is the source whose flight settled or was superseded.
161
+ // With a distinct `source`, `el` is a recovered computation that dropped it:
162
+ // the source may still be pending, so dependents with another path to it stay pending.
163
+ function settlePendingSource(e, t = e) {
164
+ // Landing and branch recovery already cleared el's own set. Superseded
165
+ // re-parks can retain an abandoned self entry (source === el), which must
166
+ // retire in the same walk as its propagated copies.
167
+ removePendingSource(e, t);
168
+ let n = false;
169
+ let r;
170
+ const o = new Set;
171
+ // Companion updates no-op without the verdict layer (null hook).
172
+ const i = GlobalQueue.fe;
173
+ const settle = s => {
174
+ if (o.has(s)) return;
175
+ // A conditional dropped this source, but another dependency can still
176
+ // carry it. Only retire pending state inherited through the recovered
177
+ // branch. Deliberately NOT marked visited on this early return: the
178
+ // carrying dependency may itself be a later branch of this same walk
179
+ // (two unchanged memos converging), and its visit must be free to
180
+ // re-examine this node once that branch has retired the source.
181
+ if (t !== e && retryReaches(s, t)) return;
182
+ if (!removePendingSource(s, t)) return;
183
+ o.add(s);
184
+ s.ae = clock;
185
+ const l = s.o?.ee?.values().next().value;
186
+ // STATUS_ERROR + pending sources only coexist via an errored loading
187
+ // window's park (notifyStatus(STATUS_ERROR) clears pending sources
188
+ // otherwise): the settled error stays the answer through the settle —
189
+ // nulling it here would have reads throw `null` until the re-enqueued
190
+ // retry lands, or lose it entirely if that retry parks again (#2989).
191
+ const u = s.S & STATUS_ERROR;
192
+ if (l) {
193
+ if (!u) setPendingError(s, l);
194
+ i?.(s);
195
+ } else {
196
+ s.S &= ~STATUS_PENDING;
197
+ if (!u) setPendingError(s);
198
+ i?.(s);
199
+ if (s.o?.ie) {
200
+ enqueueSub(s);
201
+ n = true;
202
+ }
203
+ if (s.o !== null) s.o.ie = false;
204
+ // Fully settled with nobody watching: release candidate (#2934). Checked
205
+ // again at release time — deferred so unobserved() can't unlink subs
206
+ // lists this walk is still iterating.
207
+ if (!s.u && s.T & CONFIG_AUTO_DISPOSE) (r ??= []).push(s);
208
+ }
209
+ forEachDependent(s, settle);
210
+ };
211
+ forEachDependent(e, settle);
212
+ // Release before the flush schedule below: unobserved() pulls the node back
213
+ // out of the heap, so the enqueueSub above never recomputes a released node.
214
+ if (r) for (const e of r) releaseIfSettledUnobserved(e);
215
+ if (n) schedule();
216
+ }
217
+
218
+ // Object-thenable detection (Promises/A+ shape).
219
+ function isThenable(e) {
220
+ return e != null && typeof e === "object" && typeof e.then === "function";
221
+ }
222
+
223
+ /** Fire and clear a node's iterator-flight cancellation hook (#3122). */ function releaseFlightTeardown(e) {
224
+ const t = e.o?.ce;
225
+ if (t != null) {
226
+ e.o.ce = null;
227
+ t();
228
+ }
229
+ }
230
+
231
+ function handleAsync(e, t, n) {
232
+ let r = false;
233
+ let o = false;
234
+ if (typeof t === "object" && t !== null) {
235
+ untrack(() => {
236
+ r = t[Symbol.asyncIterator];
237
+ o = !r && isThenable(t);
238
+ });
239
+ }
240
+ if (!o && !r) {
241
+ if (e.o !== null) e.o.Se = null;
242
+ // A sync landing is the first real answer for a loadingValue node.
243
+ e.de = false;
244
+ return t;
245
+ }
246
+ // Flight replacement relies on recompute's supersede release for iterator
247
+ // teardown (#3122): every handleAsync call — including the projection
248
+ // self-registration — runs during a recompute of `el`, which has already
249
+ // fired _flightTeardown. A future non-recompute registration path must
250
+ // release it here before overwriting _inFlight.
251
+ ext(e).Se = t;
252
+ // Provenance of the question this flight asks (#3331): the action whose
253
+ // window is registering it, or the flight whose landing is. Its landings
254
+ // propagate under it (asyncWrite) so an override downstream can tell a
255
+ // stale answer from its own.
256
+ const i = origin;
257
+ // Attribution hook: a new flight is registered. Fired here (not in the
258
+ // branches below) so every flight shape — plain thenable, iterator, the
259
+ // flattened combinations — is announced exactly once, while the recompute
260
+ // frame that caused it is still on the engine's stack. Not inside a try
261
+ // (#2883 — see attribution-hooks.ts).
262
+ if (attrHooks !== null) attrHooks.flightStart(e, t);
263
+ let s;
264
+ // Settle-time transition re-entry. The loading rail is invisible to
265
+ // transactions (#2933): a boundary-caught first load never registers as an
266
+ // async reporter, so its settle — the boundary's fallback -> content
267
+ // reveal — must flow ambiently. The node can still carry a `_transition`
268
+ // stamp (pending-node bookkeeping rides through the stamping sites), and
269
+ // blindly re-entering that stamped, still-incomplete transaction stashed
270
+ // the reveal with it — a deadlock when the transaction's completion
271
+ // depended on the reveal (#2937). An ESCAPED first load did register and
272
+ // keeps transition scheduling; initialized (value-holding) pending settles
273
+ // are the transaction's reveal machinery and always re-enter.
274
+ const settleTransition = () => {
275
+ let t = resolveTransition(e);
276
+ // A lane-routed node's landing is revealed by its lane, ahead of the
277
+ // transaction that owns the lane (whose own commit is only the override's
278
+ // confirm/revert). Entering that owner here would fold every transaction
279
+ // waiting on this flight into it at the landing — a reveal that
280
+ // discovered the flight (#3305) would then wait on the owner's action
281
+ // instead of on the flight (#3334). Enter the waiter: the transaction
282
+ // whose blocker this landing clears.
283
+ if (e.o?.Te) t = waitingTransition(e) ?? t;
284
+ if (t && e.S & STATUS_UNINITIALIZED && !currentTransition(t).Ie.has(e)) {
285
+ // Drop the stale stamp too: the plain settle write (setSignal) and the
286
+ // stash-path restamp both re-enter the transaction through it.
287
+ e.Ee = null;
288
+ return;
289
+ }
290
+ globalQueue.initTransition(t);
291
+ };
292
+ const handleError = n => {
293
+ if (e.o?.Se !== t) return;
294
+ // NotReadyError from rejected promises should be treated as pending, not error
295
+ let r = n instanceof NotReadyError;
296
+ if (r && e.de) {
297
+ // Loading window: the flight died waiting on an unready source. Keep
298
+ // serving commit #0 — same parking as recompute's catch for sync
299
+ // dependency throws. The dead flight is released so the clock-gated
300
+ // error-retry pull (updateIfNecessary) can also re-ask.
301
+ if (e.o !== null) e.o.Se = null;
302
+ parkLoadingWindow(e, n);
303
+ e.ae = clock;
304
+ return;
305
+ }
306
+ settleTransition();
307
+ notifyStatus(e, r ? STATUS_PENDING : STATUS_ERROR, n);
308
+ // A NotReady rejection is a landing into another pending source. The
309
+ // rejected flight will never settle its self entry, so transfer ownership
310
+ // after notifyStatus has propagated the replacement source.
311
+ if (r) settlePendingSource(e);
312
+ e.ae = clock;
313
+ // A real error settles derivatively-pending dependents (notifyStatus
314
+ // cleared their pending sources), so stranded lazy ones release here —
315
+ // the error twin of settlePendingSource's release (#2934).
316
+ if (!r) releaseSettledDependents(e);
317
+ };
318
+ const asyncWrite = (r, o) => {
319
+ if (e.o?.Se !== t) return;
320
+ // If the node was dirtied by a newer write (optimistic override or regular),
321
+ // skip this stale async result — the upcoming flush will recompute the node
322
+ // with the new value, creating a fresh Promise that supersedes this one.
323
+ if (e.it & (REACTIVE_DIRTY | REACTIVE_OPTIMISTIC_DIRTY)) return;
324
+ // The landing propagates under the flight's provenance (#3331) — through
325
+ // the flush below, which clears it.
326
+ setOrigin(i);
327
+ settleTransition();
328
+ const s = !!(e.S & STATUS_UNINITIALIZED);
329
+ // Captured before clearStatus wipes it: a quiet re-ask's landing may be
330
+ // transition-held below, and the displayed value keeps answering the same
331
+ // question until the hold commits — the classification must survive to
332
+ // that reveal or companion synchronization briefly classifies the held
333
+ // old value as pending, a one-frame pulse to direct observers (#3178).
334
+ // A truthy capture implies `_x` exists, so the restore writes it directly.
335
+ const l = e.o?.Ne;
336
+ trimStaleDeps(e);
337
+ clearStatus(e);
338
+ if (l) e.o.Ne = true;
339
+ const u = resolveLane(e);
340
+ if (u) u._e.delete(e);
341
+ // Attribution hook: lets the engine snapshot state before the landing
342
+ // branches, so it can tell whether the plain path's setSignal committed a
343
+ // change (and only then classify it as an async landing).
344
+ if (attrHooks !== null) attrHooks.asyncStart(e);
345
+ if (n) {
346
+ try {
347
+ n(r);
348
+ } catch (e) {
349
+ handleError(e);
350
+ return;
351
+ }
352
+ if (s) clearStatus(e, true);
353
+ } else if (e.o?.De !== undefined) {
354
+ // Optimistic node — resting OR covered by an active override — holds
355
+ // through the shared pending-node path, exactly like a plain async memo,
356
+ // so the commit clears STATUS_UNINITIALIZED (#2806) and elevation to
357
+ // _value happens on this value's OWN transition schedule (A18 as
358
+ // re-ruled 2026-07-07: _value only changes at commit points). With an
359
+ // override active the hold and its eventual commit are unobservable
360
+ // (A17 — every reader sees the override); the revert reveals whatever
361
+ // has committed by then, so corrections reveal atomically with their
362
+ // transition rather than escaping it.
363
+ if (e.Pe === NOT_PENDING) queuePendingNode(e);
364
+ e.Pe = r;
365
+ // The hold is a companion-visible write like any other (A13/A19): the
366
+ // clearStatus() above computed its verdict before the hold existed, so
367
+ // isPending must re-derive (the value is not final until commit — V1)
368
+ // and latest() must see the fresh in-flight value (V2). Subscribers are
369
+ // only notified when the hold is visible to them: under an active
370
+ // override every reader sees the override (A17), so waking subs would
371
+ // re-show an unchanged view — the revert is the notification point.
372
+ // Under an override the landing is handed to the engine's
373
+ // supersedeOverride (A18 supersession, #3331): own-source truth that
374
+ // differs from the override ends the optimism for the graph now (plain
375
+ // channel, lane demoted); a matching arrival is silent except to an
376
+ // authoritative-view reader (until()'s predicate) waiting on exactly
377
+ // this staged truth (#3164 — without the wake the hold deadlocks: the
378
+ // landing waits on the transaction, the transaction on the action, the
379
+ // action on an until() never re-notified). The hook is installed with
380
+ // the engine, which an active override implies. The propagation runs
381
+ // under this flight's provenance (setOrigin above).
382
+ GlobalQueue.Ae?.(e, r);
383
+ if (!hasActiveOverride(e)) {
384
+ if (attrHooks !== null) attrHooks.asyncEnd(e, undefined, r, true);
385
+ insertSubs(e);
386
+ } else GlobalQueue.Oe(e, r);
387
+ e.ae = clock;
388
+ } else if (u) {
389
+ // Route through lane's effect queue for independent flushing
390
+ const t = e.Re;
391
+ const n = e.ge;
392
+ const o = e.Ue;
393
+ try {
394
+ if (!t && s || !o || !o(r, n)) {
395
+ e.ge = r;
396
+ e.ae = clock;
397
+ // The latest() shadow write gives latest() effects independent lanes; the
398
+ // _pendingSignal update is a no-op repeat of the clearStatus() call above
399
+ // (computePendingState doesn't read _value).
400
+ GlobalQueue.Ae?.(e, r);
401
+ insertSubs(e, true);
402
+ }
403
+ } catch (t) {
404
+ // A user comparator throwing during async resolution has no caller to
405
+ // surface to (we're in promise machinery) — route it through the node's
406
+ // error status so boundaries contain it instead of an unhandled
407
+ // rejection (#2837).
408
+ notifyStatus(e, STATUS_ERROR, t);
409
+ }
410
+ // Attribution hook — unconditional, and OUTSIDE the try: rollup's
411
+ // tryCatchDeoptimization retains anything referenced inside a try even
412
+ // behind a folded false guard, so even a dev-only flag smuggled out of
413
+ // the commit branch leaves prod residue (#2883). The engine instead
414
+ // detects whether this landing committed by comparing the node against
415
+ // its asyncStart snapshot (see attribution.ts).
416
+ if (attrHooks !== null) attrHooks.asyncEnd(e, n, r, true);
417
+ } else {
418
+ try {
419
+ setSignal(e, () => r);
420
+ } catch (t) {
421
+ // Same containment as above: setSignal's comparator throw is the only
422
+ // pre-commit failure here, and there is no user callsite to throw to.
423
+ notifyStatus(e, STATUS_ERROR, t);
424
+ }
425
+ // Attribution hook: this path landed through setSignal, whose write
426
+ // hook already saw any committed change — direct=false lets the engine
427
+ // reclassify that write as an async landing iff it actually committed.
428
+ // Outside the try (#2883 — see attribution-hooks.ts).
429
+ if (attrHooks !== null) attrHooks.asyncEnd(e, undefined, r, false);
430
+ }
431
+ // First real answer landing: the window closes when the answer becomes
432
+ // OBSERVABLE. A direct commit is observable now; a transition-held write
433
+ // (`_pendingValue` set above or inside setSignal) is not — the verdict's
434
+ // held-value branch is window-gated, and commitPendingNode closes the
435
+ // window when the hold commits, so no one-frame isPending pulse can leak
436
+ // to live observers between the landing and its commit (#2990). The
437
+ // quiet re-ask classification follows the same schedule (#3178).
438
+ if (e.Pe === NOT_PENDING) {
439
+ e.de = false;
440
+ if (l) e.o.Ne = false;
441
+ }
442
+ settlePendingSource(e);
443
+ schedule();
444
+ flush();
445
+ o?.();
446
+ };
447
+ // A pending node's in-flight promise is an observer: `unlinkSubs` skips
448
+ // autodispose while STATUS_PENDING so subscriber churn can't orphan the
449
+ // work (a lazy async memo would otherwise tear down and re-execute — one
450
+ // fetch per suspended re-read). Settling is that observer's release, so
451
+ // it runs the same last-one-out check the other release sites run.
452
+ // Returns whether the node released, so the iterator branch can stop
453
+ // pulling values instead of pumping an unobserved stream forever (#2935).
454
+ const settleAutodispose = () => {
455
+ if (e.T & CONFIG_AUTO_DISPOSE && !e.u && !(e.S & STATUS_PENDING)) {
456
+ unobserved(e);
457
+ return true;
458
+ }
459
+ return false;
460
+ };
461
+ // Consumes an AsyncIterable as this flight's value stream. Two postures:
462
+ // LIVE (called synchronously from this read — the compute returned an
463
+ // iterable directly, or a sync-settled thenable held one), where the
464
+ // initial drain may stash a sync first yield for the caller to return and
465
+ // close registration uses the ambient owner; and DEFERRED (the flattening
466
+ // path — a thenable resolved to an iterable in a later microtask), where
467
+ // there is no caller to serve and no ambient owner: sync-settled steps
468
+ // write through asyncWrite, and close registration goes through the slot
469
+ // the thenable branch pre-registered while it still owned the context.
470
+ // Returns whether a sync answer landed (first yield or empty completion) —
471
+ // meaningful only in the live posture.
472
+ const consumeIterator = (n, r) => {
473
+ const o = n[Symbol.asyncIterator]();
474
+ let i = false;
475
+ let l = false;
476
+ let u = !r;
477
+ const close = () => {
478
+ if (l) return;
479
+ l = true;
480
+ try {
481
+ const e = o.return?.();
482
+ if (isThenable(e)) e.then(undefined, () => {});
483
+ } catch {}
484
+ };
485
+ r ? r(close) : cleanup(close);
486
+ // Flight-identity cancellation (#3122): the registration above is the
487
+ // owner-death backstop, but its disposal list can be zombie-deferred
488
+ // until the SUPERSEDING flight settles. The teardown slot fires at the
489
+ // _inFlight release sites so supersede stops this stream immediately.
490
+ ext(e).ce = close;
491
+ // Release check before each next pull: an unobserved lazy node must tear
492
+ // down (its close above runs via disposal, closing the iterator) instead
493
+ // of pumping the stream forever with zero subscribers (#2935).
494
+ const iterateOrRelease = () => {
495
+ if (!settleAutodispose()) iterate();
496
+ };
497
+ const iterate = () => {
498
+ let n, r, f = false, a = false, c = true;
499
+ // Protocol tolerance, matching `for await`: `await` unwraps whatever
500
+ // next() returns — a thenable OR a bare IteratorResult. Real producers
501
+ // use the bare form as a promise-free fast path when a value is already
502
+ // buffered (seroval's deserialized streams do), so a bare result is
503
+ // assimilated as an already-settled step instead of crashing on `.then`.
504
+ const S = o.next();
505
+ const d = isThenable(S) ? S : {
506
+ then: e => void e(S)
507
+ };
508
+ d.then(r => {
509
+ // The sync stash only serves the INITIAL drain (handleAsync's caller
510
+ // consumes syncValue / throws NotReady from it). A sync-settled step
511
+ // after an async gap — seroval buffering values between pulls, a
512
+ // sync-thenable producer mid-stream — has no caller reading the
513
+ // stash: it must write through the async path or the value is
514
+ // silently dropped. (The deferred posture never has a caller, so
515
+ // initialRead starts false there and everything writes through.)
516
+ if (c && u) {
517
+ n = r;
518
+ f = true;
519
+ if (r.done) l = true;
520
+ } else if (e.o?.Se !== t) {
521
+ return;
522
+ } else if (!r.done) {
523
+ i = true;
524
+ asyncWrite(r.value, iterateOrRelease);
525
+ } else {
526
+ l = true;
527
+ if (i) {
528
+ schedule();
529
+ flush();
530
+ } else {
531
+ // Empty completion settles like the immediately-done sync path.
532
+ asyncWrite(undefined);
533
+ }
534
+ settleAutodispose();
535
+ }
536
+ }, n => {
537
+ if (c && u) {
538
+ r = n;
539
+ a = true;
540
+ } else if (e.o?.Se === t) {
541
+ l = true;
542
+ handleError(n);
543
+ settleAutodispose();
544
+ }
545
+ });
546
+ c = false;
547
+ if (a) {
548
+ // Match the promise branch, but only rethrow during the initial read.
549
+ l = true;
550
+ handleError(r);
551
+ if (u) throw r;
552
+ return true;
553
+ }
554
+ if (f && !n.done) {
555
+ s = n.value;
556
+ i = true;
557
+ return iterate();
558
+ }
559
+ return f && n.done;
560
+ };
561
+ const f = iterate();
562
+ // Later iterate() calls run from asyncWrite, where rethrowing would be unhandled.
563
+ u = false;
564
+ return i || f;
565
+ };
566
+ // Landed-synchronously verdict for a LIVE iterator drain; null when no live
567
+ // drain ran (plain promise flight, or a deferred flatten). Drives the
568
+ // shared NotReady/loading tail below.
569
+ let l = null;
570
+ // Flatten one async level: a thenable that RESOLVES to an AsyncIterable —
571
+ // the shape every async stub returning a stream produces — consumes as the
572
+ // stream itself rather than settling on the iterable object. One level
573
+ // only: A+ `then` already collapses nested thenables, so the resolved
574
+ // value is never itself a thenable.
575
+ const flattenIfIterable = (e, t) => {
576
+ let n = false;
577
+ if (typeof e === "object" && e !== null) {
578
+ untrack(() => {
579
+ n = e[Symbol.asyncIterator];
580
+ });
581
+ }
582
+ if (!n) return false;
583
+ const r = consumeIterator(e, t);
584
+ if (!t) l = r;
585
+ return true;
586
+ };
587
+ if (o) {
588
+ let n = false, r = false, o, i = true;
589
+ // Close registration for the flattening path. Consumption starts in a
590
+ // microtask where the ambient owner is gone (or worse, someone else's),
591
+ // so `cleanup()` can't be used — the close targets el's disposal list
592
+ // directly, exactly where a live cleanup() during this recompute would
593
+ // have put it. Deliberately NOT pre-registered at flight start: a
594
+ // non-null `_disposal` reclassifies the node into recompute's deferred
595
+ // (zombie) disposal path, and plain promise flights — the overwhelming
596
+ // majority — must not pay that. Only a flight that actually flattens
597
+ // becomes disposal-bearing, which is exactly the class a directly
598
+ // returned iterable already occupies.
599
+ const registerDeferredClose = t => {
600
+ if (!e.he) e.he = t; else if (Array.isArray(e.he)) e.he.push(t); else e.he = [ e.he, t ];
601
+ };
602
+ t.then(r => {
603
+ if (i) {
604
+ s = r;
605
+ n = true;
606
+ } else if (e.o?.Se === t && !(e.it & REACTIVE_DISPOSED) && flattenIfIterable(r, registerDeferredClose)) ; else {
607
+ asyncWrite(r);
608
+ settleAutodispose();
609
+ }
610
+ }, e => {
611
+ if (i) {
612
+ o = e;
613
+ r = true;
614
+ } else {
615
+ handleError(e);
616
+ settleAutodispose();
617
+ }
618
+ });
619
+ i = false;
620
+ if (r) {
621
+ // Settle through the same status path an async rejection uses, then
622
+ // unwind the in-progress synchronous read so the errored node isn't
623
+ // momentarily read as `undefined`.
624
+ handleError(o);
625
+ throw o;
626
+ } else if (!n) {
627
+ // Loading window: serve commit #0 instead of suspending. No transition
628
+ // is opened — first-flight work on a loadingValue node is loading-class
629
+ // (invisible to boundaries and transitions); the flight itself is
630
+ // already registered in _inFlight and lands through asyncWrite.
631
+ if (e.de) return e.ge;
632
+ globalQueue.initTransition(resolveTransition(e));
633
+ throw new NotReadyError(context);
634
+ } else if (!flattenIfIterable(s)) {
635
+ // Synchronously-resolved promise: the first real answer landed.
636
+ e.de = false;
637
+ }
638
+ // A sync-resolved promise holding an AsyncIterable flattened LIVE (we
639
+ // are still inside the synchronous read): full initial-drain semantics
640
+ // apply and the shared tail below settles the verdict.
641
+ }
642
+ if (r) flattenIfIterable(t);
643
+ if (l !== null) {
644
+ if (!l) {
645
+ // Loading window: serve commit #0 (see the promise branch above).
646
+ if (e.de) return e.ge;
647
+ globalQueue.initTransition(resolveTransition(e));
648
+ throw new NotReadyError(context);
649
+ }
650
+ // A sync first yield (or immediate empty completion) is the first real
651
+ // answer; async yields clear inside asyncWrite.
652
+ e.de = false;
653
+ }
654
+ return s;
655
+ }
656
+
657
+ function clearStatus(e, t = false) {
658
+ if (e.o?.ee) clearPendingSources(e);
659
+ if (e.o?.ie) if (e.o !== null) e.o.ie = false;
660
+ // The pending window is over; its quiet classification dies with it.
661
+ // (Unconditional: _reask is baked into the node literals, so this is a
662
+ // plain store to an existing slot — no shape change.)
663
+ if (e.o !== null) e.o.Ne = false;
664
+ e.S = t ? 0 : e.S & STATUS_UNINITIALIZED;
665
+ if (e.o?._) setPendingError(e);
666
+ // Update pending signal for isPending() reactivity (companions only exist
667
+ // once the verdict layer created them, which installs the hooks).
668
+ if (e.o?.be || e.o?.pe) GlobalQueue.fe(e);
669
+ if (e.o?.i && e.T & CONFIG_CHILD_COMPANIONS && GlobalQueue.Ge !== null) GlobalQueue.Ge(e);
670
+ const n = statusNotifierOf(e);
671
+ if (n) n.call(e);
672
+ }
673
+
674
+ function notifyStatus(e, t, n, r, o) {
675
+ // Wrap regular errors to track source node
676
+ if (t === STATUS_ERROR && !(n instanceof StatusError) && !(n instanceof NotReadyError)) n = new StatusError(e, n);
677
+ const i = t === STATUS_PENDING && n instanceof NotReadyError ? n.source : undefined;
678
+ const s = i === e;
679
+ const l = t === STATUS_PENDING && e.o?.De !== undefined && !s;
680
+ const u = l && hasActiveOverride(e);
681
+ if (!r) {
682
+ if (t === STATUS_PENDING && i) {
683
+ addPendingSource(e, i);
684
+ // A fresh flight from a settled state starts with its inputs unpublished
685
+ // (a replacement flight while still pending keeps the mark: the first
686
+ // flight's committed inputs are still the frame).
687
+ if (!(e.S & STATUS_PENDING)) e.T &= ~CONFIG_INPUTS_PUBLISHED;
688
+ e.S = STATUS_PENDING | e.S & STATUS_UNINITIALIZED;
689
+ // Preserve the current source on this propagation so render-effect notification
690
+ // can register every distinct pending source with the transition.
691
+ setPendingError(e, i, n);
692
+ } else {
693
+ clearPendingSources(e);
694
+ e.S = t | (t !== STATUS_ERROR ? e.S & STATUS_UNINITIALIZED : 0);
695
+ ext(e)._ = n;
696
+ }
697
+ GlobalQueue.fe?.(e);
698
+ if (e.o?.i && e.T & CONFIG_CHILD_COMPANIONS && GlobalQueue.Ge !== null) GlobalQueue.Ge(e);
699
+ }
700
+ if (o && !r) {
701
+ assignOrMergeLane(e, o);
702
+ }
703
+ const f = r || u;
704
+ const a = r || l ? undefined : o;
705
+ const c = statusNotifierOf(e);
706
+ if (c) {
707
+ if (r && t === STATUS_PENDING) {
708
+ return;
709
+ }
710
+ if (f) {
711
+ c.call(e, t, n);
712
+ } else {
713
+ c.call(e);
714
+ }
715
+ return;
716
+ }
717
+ forEachDependent(e, (e, r) => {
718
+ e.ae = clock;
719
+ if (t === STATUS_PENDING && i && !e.o?.ee?.has(i) || t !== STATUS_PENDING && (e.o?._ !== n || e.o?.ee)) {
720
+ // A pending-observer link is the subscription an `isPending` read created.
721
+ // It exists so the observer re-runs when the source settles, but it must
722
+ // not carry a real (non-NotReadyError) error — the synchronous `isPending`
723
+ // read swallows those, and the async path must match. Re-run the observer
724
+ // so `isPending` re-evaluates (to not-pending) instead of forwarding.
725
+ if (r.ye && t !== STATUS_PENDING && !(n instanceof NotReadyError)) {
726
+ enqueueSub(e);
727
+ schedule();
728
+ return;
729
+ }
730
+ if (!f && !e.Ee) queuePendingNode(e);
731
+ notifyStatus(e, t, n, f, a);
732
+ }
733
+ });
734
+ }
735
+
736
+ export { addPendingSource, clearStatus, forEachDependent, handleAsync, isThenable, notifyStatus, parkLoadingWindow, releaseFlightTeardown, releaseSettledDependents, setPendingError, settleErroredDependents, settlePendingSource };