@solidjs/signals 2.0.0-rc.7 → 2.0.0-rc.9

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 (134) hide show
  1. package/dist/dev-shared.js +6357 -0
  2. package/dist/dev.attribution.js +2485 -0
  3. package/dist/dev.js +2851 -7027
  4. package/dist/observe/affects.js +129 -0
  5. package/dist/observe/attribution.js +7 -0
  6. package/dist/observe/boundaries.js +641 -0
  7. package/dist/observe/core/action.js +177 -0
  8. package/dist/observe/core/async.js +846 -0
  9. package/dist/observe/core/attribution-costs.js +66 -0
  10. package/dist/observe/core/attribution-feedback.js +282 -0
  11. package/dist/observe/core/attribution-hooks.js +82 -0
  12. package/dist/observe/core/attribution-queries.js +28 -0
  13. package/dist/observe/core/attribution.js +2095 -0
  14. package/dist/observe/core/constants.js +248 -0
  15. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  16. package/dist/observe/core/core.js +1789 -0
  17. package/dist/observe/core/dev.js +293 -0
  18. package/dist/observe/core/effect.js +195 -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 +585 -0
  27. package/dist/observe/core/owner.js +322 -0
  28. package/dist/observe/core/scheduler.js +1428 -0
  29. package/dist/observe/core/verdict.js +669 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +484 -0
  32. package/dist/{types-cjs/signals.d.cts → observe/signals.js} +311 -317
  33. package/dist/observe/store/index.js +40 -0
  34. package/dist/observe/store/next/optimistic.js +660 -0
  35. package/dist/observe/store/next/projection.js +255 -0
  36. package/dist/observe/store/next/reconcile.js +375 -0
  37. package/dist/observe/store/next/store.js +2327 -0
  38. package/dist/observe/store/next/target.js +51 -0
  39. package/dist/observe/store/store.js +325 -0
  40. package/dist/observe/store/storePath.js +103 -0
  41. package/dist/observe/store/utils.js +1023 -0
  42. package/dist/prod/attribution.js +41 -0
  43. package/dist/prod/boundaries.js +128 -76
  44. package/dist/prod/core/action.js +65 -37
  45. package/dist/prod/core/async.js +324 -172
  46. package/dist/prod/core/constants.js +57 -1
  47. package/dist/prod/core/context.js +3 -3
  48. package/dist/prod/core/core.js +1003 -364
  49. package/dist/prod/core/dev.js +17 -1
  50. package/dist/prod/core/effect.js +76 -42
  51. package/dist/prod/core/error-hooks.js +71 -0
  52. package/dist/prod/core/external.js +4 -4
  53. package/dist/prod/core/graph.js +37 -37
  54. package/dist/prod/core/heap.js +61 -56
  55. package/dist/prod/core/lanes.js +107 -63
  56. package/dist/prod/core/optimistic.js +374 -93
  57. package/dist/prod/core/owner.js +62 -46
  58. package/dist/prod/core/scheduler.js +653 -286
  59. package/dist/prod/core/verdict.js +245 -127
  60. package/dist/prod/index.js +15 -5
  61. package/dist/prod/map.js +292 -141
  62. package/dist/prod/signals.js +29 -16
  63. package/dist/prod/store/next/optimistic.js +77 -55
  64. package/dist/prod/store/next/projection.js +31 -20
  65. package/dist/prod/store/next/reconcile.js +87 -84
  66. package/dist/prod/store/next/store.js +718 -401
  67. package/dist/prod/store/next/target.js +32 -10
  68. package/dist/prod/store/store.js +12 -14
  69. package/dist/prod/store/utils.js +950 -130
  70. package/dist/types/attribution.d.ts +20 -0
  71. package/dist/types/attribution.prod.d.ts +22 -0
  72. package/dist/types/boundaries.d.ts +10 -1
  73. package/dist/types/core/action.d.ts +12 -5
  74. package/dist/types/core/async.d.ts +1 -1
  75. package/dist/types/core/attribution-costs.d.ts +35 -0
  76. package/dist/types/core/attribution-feedback.d.ts +133 -0
  77. package/dist/types/core/attribution-hooks.d.ts +147 -9
  78. package/dist/types/core/attribution-queries.d.ts +10 -0
  79. package/dist/types/core/attribution.d.ts +216 -182
  80. package/dist/types/core/constants.d.ts +56 -0
  81. package/dist/types/core/core.d.ts +190 -2
  82. package/dist/types/core/dev.d.ts +246 -28
  83. package/dist/types/core/effect.d.ts +8 -1
  84. package/dist/types/core/error-hooks.d.ts +71 -0
  85. package/dist/types/core/index.d.ts +4 -1
  86. package/dist/types/core/invariants.d.ts +4 -0
  87. package/dist/types/core/lanes.d.ts +39 -5
  88. package/dist/types/core/scheduler.d.ts +153 -0
  89. package/dist/types/core/types.d.ts +32 -9
  90. package/dist/types/index.d.ts +10 -3
  91. package/dist/types/map.d.ts +2 -0
  92. package/dist/types/signals.d.ts +8 -0
  93. package/dist/types/store/index.d.ts +2 -0
  94. package/dist/types/store/next/optimistic.d.ts +1 -1
  95. package/dist/types/store/next/store.d.ts +11 -5
  96. package/dist/types/store/next/target.d.ts +37 -10
  97. package/dist/types/store/utils.d.ts +178 -0
  98. package/package.json +21 -17
  99. package/dist/node.cjs +0 -10541
  100. package/dist/node.dev.cjs +0 -13724
  101. package/dist/types-cjs/affects.d.cts +0 -47
  102. package/dist/types-cjs/boundaries.d.cts +0 -175
  103. package/dist/types-cjs/core/action.d.cts +0 -64
  104. package/dist/types-cjs/core/async.d.cts +0 -23
  105. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -127
  106. package/dist/types-cjs/core/attribution.d.cts +0 -495
  107. package/dist/types-cjs/core/constants.d.cts +0 -159
  108. package/dist/types-cjs/core/core.d.cts +0 -185
  109. package/dist/types-cjs/core/dev.d.cts +0 -136
  110. package/dist/types-cjs/core/effect.d.cts +0 -30
  111. package/dist/types-cjs/core/error.d.cts +0 -56
  112. package/dist/types-cjs/core/external.d.cts +0 -15
  113. package/dist/types-cjs/core/graph.d.cts +0 -28
  114. package/dist/types-cjs/core/heap.d.cts +0 -24
  115. package/dist/types-cjs/core/index.d.cts +0 -13
  116. package/dist/types-cjs/core/invariants.d.cts +0 -59
  117. package/dist/types-cjs/core/lanes.d.cts +0 -54
  118. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  119. package/dist/types-cjs/core/owner.d.cts +0 -124
  120. package/dist/types-cjs/core/scheduler.d.cts +0 -236
  121. package/dist/types-cjs/core/types.d.cts +0 -204
  122. package/dist/types-cjs/core/verdict.d.cts +0 -2
  123. package/dist/types-cjs/index.d.cts +0 -10
  124. package/dist/types-cjs/map.d.cts +0 -69
  125. package/dist/types-cjs/package.json +0 -3
  126. package/dist/types-cjs/store/index.d.cts +0 -18
  127. package/dist/types-cjs/store/next/optimistic.d.cts +0 -25
  128. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  129. package/dist/types-cjs/store/next/reconcile.d.cts +0 -10
  130. package/dist/types-cjs/store/next/store.d.cts +0 -121
  131. package/dist/types-cjs/store/next/target.d.cts +0 -166
  132. package/dist/types-cjs/store/store.d.cts +0 -143
  133. package/dist/types-cjs/store/storePath.d.cts +0 -58
  134. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -0,0 +1,1789 @@
1
+ import { releaseFlightTeardown, handleAsync, clearStatus, parkLoadingWindow, notifyStatus, settlePendingSource, settleErroredDependents } from "./async.js";
2
+
3
+ import { NOT_PENDING, EFFECT_TRACKED, EFFECT_USER, CONFIG_HELD_CHILDREN, REACTIVE_OPTIMISTIC_DIRTY, CONFIG_OPTIMISTIC, CONFIG_DERIVED_OVERRIDE, STATUS_UNINITIALIZED, STATUS_ERROR, STATUS_PENDING, REACTIVE_REASK, REACTIVE_RECOMPUTING_DEPS, CONFIG_SYNC, CONFIG_HAS_LANE, REACTIVE_MISSED_WAKE, REACTIVE_NONE, REACTIVE_SNAPSHOT_STALE, unwrapOverride, CONFIG_DIRECT_COMMIT, CONFIG_HAS_COMPANIONS, CONFIG_PROMOTED, CONFIG_ADOPTED_UNFLUSHED, CONFIG_CHILDREN_FORBIDDEN, CONFIG_FRESH_READ, CONFIG_INPUTS_PUBLISHED, CONFIG_AUTO_DISPOSE, REACTIVE_LAZY, REACTIVE_DISPOSED, REACTIVE_CHECK, REACTIVE_DIRTY, REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, CONFIG_AUTHORITATIVE_READ, CONFIG_OVERRIDE_SUPERSEDED, CONFIG_AUTHORITATIVE_OBSERVED, defaultContext, CONFIG_HELD_TRUTH, CONFIG_TRANSPARENT, CONFIG_OWNED_WRITE, CONFIG_NO_SNAPSHOT, CONFIG_IN_SNAPSHOT_SCOPE, NO_SNAPSHOT, CONFIG_HAS_SNAPSHOT, REACTIVE_MANUAL_WRITE, CONFIG_FW_CHILDREN, CONFIG_SLOT_NODE, STORE_SNAPSHOT_PROPS } from "./constants.js";
4
+
5
+ import { NotReadyError } from "./error.js";
6
+
7
+ import { trimStaleDeps, link, dormantNodes } from "./graph.js";
8
+
9
+ import { deleteFromHeap, queueFor, insertIntoHeapHeight, enqueueSub, markNode, markHeap, insertIntoHeap } from "./heap.js";
10
+
11
+ import { GlobalQueue, bumpNotifyEpoch, activeTransition, globalQueue, clock, currentTransition, insertSubs, queuePendingNode, wakeParked, heldTrims, runInTransition, schedule, batchJoins, notifyEpoch, dirtyQueue, projectionWriteActive, reaskArmed, armReaskClear } from "./scheduler.js";
12
+
13
+ import { GRAPH_SIZE_WARN_AT, noteFanIn } from "./dev.js";
14
+
15
+ import { attrHooks } from "./attribution-hooks.js";
16
+
17
+ import "./invariants.js";
18
+
19
+ import { disposeChildren, markDisposal, inheritId } from "./owner.js";
20
+
21
+ // The heap's per-node step. A tracked effect's heap visit is its compute
22
+ // phase — empty, like a user effect whose compute reads nothing — and hands
23
+ // the callback to the user queue. Routing the wake through the heap, rather
24
+ // than straight into the queue at notify time, is what orders the run after
25
+ // the commit regardless of which phase the write came from: a write in a
26
+ // render-effect callback stages its value for the next pass, but a wake pushed
27
+ // directly into the user queue ran in the SAME pass, read the old value, and
28
+ // nothing re-notified it when the value landed (#3291).
29
+ GlobalQueue._t = e => {
30
+ if (e.Pe === EFFECT_TRACKED) {
31
+ deleteFromHeap(e, queueFor(e));
32
+ e.Nt = true;
33
+ e.T.enqueue(EFFECT_USER, e.Et);
34
+ } else recompute(e);
35
+ };
36
+
37
+ GlobalQueue.It = disposeChildren;
38
+
39
+ let tracking = false;
40
+
41
+ /** @internal verdict-module glue */ function setPendingCheckActive(e) {
42
+ pendingCheckActive = e;
43
+ }
44
+
45
+ /** @internal verdict-module glue */ function setLatestReadActive(e) {
46
+ latestReadActive = e;
47
+ }
48
+
49
+ /** @internal verdict-module glue */ function setContextInternal(e) {
50
+ context = e;
51
+ }
52
+
53
+ let stale = false;
54
+
55
+ let pendingCheckActive = false;
56
+
57
+ let latestReadActive = false;
58
+
59
+ let context = null;
60
+
61
+ let currentOptimisticLane = null;
62
+
63
+ let snapshotCaptureActive = false;
64
+
65
+ let snapshotSources = null;
66
+
67
+ function ownerInSnapshotScope(e) {
68
+ while (e) {
69
+ if (e.St) return true;
70
+ e = e._parent;
71
+ }
72
+ return false;
73
+ }
74
+
75
+ function setSnapshotCapture(e) {
76
+ snapshotCaptureActive = e;
77
+ if (e && !snapshotSources) snapshotSources = new Set;
78
+ }
79
+
80
+ function markSnapshotScope(e) {
81
+ e.St = true;
82
+ }
83
+
84
+ function releaseSnapshotScope(e) {
85
+ e.St = false;
86
+ releaseSubtree(e);
87
+ schedule();
88
+ }
89
+
90
+ function releaseSubtree(e) {
91
+ let t = e.Ot;
92
+ while (t) {
93
+ if (t.St) {
94
+ t = t.At;
95
+ continue;
96
+ }
97
+ if (t.ht) {
98
+ const e = t;
99
+ e.C &= ~CONFIG_IN_SNAPSHOT_SCOPE;
100
+ if (e.ft & REACTIVE_SNAPSHOT_STALE) {
101
+ e.ft &= ~REACTIVE_SNAPSHOT_STALE;
102
+ e.ft |= REACTIVE_DIRTY;
103
+ if (dirtyQueue.Ct > e.Rt) dirtyQueue.Ct = e.Rt;
104
+ insertIntoHeap(e, dirtyQueue);
105
+ }
106
+ }
107
+ releaseSubtree(t);
108
+ t = t.At;
109
+ }
110
+ }
111
+
112
+ function clearSnapshots() {
113
+ if (snapshotSources) {
114
+ for (const e of snapshotSources) {
115
+ // The extension is a fixed-shape object with `_snapshotValue`
116
+ // pre-initialized to undefined (see ext()), and every reader tests
117
+ // `!== undefined` — assign, don't `delete`: deleting a field pushes the
118
+ // object to dictionary mode for every later read of every field.
119
+ const t = e.o;
120
+ if (t != null) t.Gt = undefined;
121
+ // StoreNode targets share one pre-initialized hidden class (see
122
+ // createStoreProxy) — same rule, and only when present so signal-node
123
+ // sources don't grow the field.
124
+ if (e[STORE_SNAPSHOT_PROPS] !== undefined) e[STORE_SNAPSHOT_PROPS] = undefined;
125
+ }
126
+ snapshotSources = null;
127
+ }
128
+ snapshotCaptureActive = false;
129
+ }
130
+
131
+ function recompute(e, t = false) {
132
+ // §12d: any recompute can clean a marked subscriber — invalidate skips.
133
+ bumpNotifyEpoch();
134
+ const n = e.Pe;
135
+ // Attribution hook: fired before this run touches the dep list — `_deps`
136
+ // still holds the previous run's links (the subscriptions that could have
137
+ // triggered this run, and the baseline for the engine's subscription diff).
138
+ let i = false;
139
+ if (attrHooks !== null) attrHooks.recomputeStart(e, t);
140
+ if (!t) {
141
+ // A stamped memo re-enters its hold: its value is that transaction's work.
142
+ // An effect's pass belongs to whatever dirtied it (A15 corollary: effects
143
+ // don't entangle parallel transactions); it joins its stamp only when the
144
+ // pass observes the held flight — queue notification (#3407).
145
+ if (e.Te && !n && activeTransition !== e.Te) globalQueue.initTransition(e.Te);
146
+ deleteFromHeap(e, queueFor(e));
147
+ if (e.o !== null) {
148
+ e.o.ce = null;
149
+ // Supersede is where an iterator flight dies (#3122): close it now.
150
+ // Its cleanup(close) registration may sit in a zombie-deferred
151
+ // disposal list that a held transition only drains when the
152
+ // SUPERSEDING flight settles — cancellation must not wait for the
153
+ // work that replaced it. Idempotent with the cleanup-channel close.
154
+ releaseFlightTeardown(e);
155
+ }
156
+ // Tracked effects run after finalizePureQueue, so dispose immediately
157
+ // instead of deferring. Children built by an uncommitted recompute
158
+ // (CONFIG_HELD_CHILDREN) die immediately too: no frame ever showed them.
159
+ // Everything else is the committed frame's and is deferred as zombies
160
+ // until this node's commit — a transaction-owned node included (#3404):
161
+ // a parked node's children predate the hold, and tearing them down when
162
+ // the source lands ran cleanups before the transaction's atomic reveal.
163
+ if (n === EFFECT_TRACKED || e.C & CONFIG_HELD_CHILDREN) disposeChildren(e); else if (e.Ot !== null || e.Ue !== null) {
164
+ markDisposal(e);
165
+ const t = ext(e);
166
+ t.Dt = e.Ue;
167
+ t.Pt = e.Ot;
168
+ e.Ue = null;
169
+ e.Ot = null;
170
+ e.Ft = 0;
171
+ } else ;
172
+ }
173
+ let l = !!(e.ft & REACTIVE_OPTIMISTIC_DIRTY);
174
+ // A derived override (lanes stage, #3479) is override-covered like a written
175
+ // one: a plain pass over it — its source superseded (A18) — stages the truth
176
+ // and supersedes the override through the sync twin below.
177
+ const u = (e.C & (CONFIG_OPTIMISTIC | CONFIG_DERIVED_OVERRIDE)) !== 0 && e.o?.Ne !== NOT_PENDING && e.o?.Ne !== undefined;
178
+ const o = !!(e.S & STATUS_UNINITIALIZED);
179
+ // Capture both error and pending status before the compute clears them.
180
+ // A conditional can drop its pending source and recover to an unchanged
181
+ // value, leaving blocked dependents outside that source’s settle walk.
182
+ const r = e.S & STATUS_ERROR ? e.o?._ : undefined;
183
+ const s = (e.S & STATUS_PENDING) !== 0;
184
+ const a = s ? e.o?.ut : undefined;
185
+ // Pending SOURCE-hood, captured before the compute clears status: a node
186
+ // whose own flight parked dependents self-registers in _pendingSources
187
+ // (notifyStatus, isSource). If this recompute supersedes that flight and
188
+ // settles synchronously, those dependents settle HERE — asyncWrite's
189
+ // settlePendingSource walk never runs for a landing that was preempted
190
+ // (#3181).
191
+ const c = e.o?.ut?.has(e);
192
+ // Re-ask classification lives in the verdict module; capture the flag before
193
+ // the recompute wipes _flags below.
194
+ const f = (e.ft & REACTIVE_REASK) !== 0;
195
+ // Captured before the compute clears it on a sync landing: if that landing
196
+ // is transition-held below, the window must stay open until the hold
197
+ // commits (commitPendingNode) — a closed window plus a held value reads as
198
+ // a pending frame to live observers of the verdict (#2990).
199
+ const _ = e.Se;
200
+ // Creation-time A29 (see enterStagedRead): a pass outside a flush that is
201
+ // served a live transaction's staged value records the transaction here
202
+ // and is staged INTO it below — "born held" — instead of committing.
203
+ const N = stagedEntry;
204
+ stagedEntry = null;
205
+ const d = context;
206
+ context = e;
207
+ e.Fe = null;
208
+ e.ye++;
209
+ e.ft = REACTIVE_RECOMPUTING_DEPS;
210
+ e.fe = clock;
211
+ let E = e._e === NOT_PENDING ? e.Ae : e._e;
212
+ let I = e.Rt;
213
+ let T = false;
214
+ let S = tracking;
215
+ let O = currentOptimisticLane;
216
+ tracking = true;
217
+ // A computed's fn establishes its OWN dependencies, so it must never run
218
+ // inside a latest() read window: read() short-circuits through the
219
+ // companion path before dependency linking, so a memo created (eagerly
220
+ // computed) inside latest(fn) came out permanently dependency-less (#2926).
221
+ // latestRead() already suspends the flag for its pull-recomputes; this
222
+ // covers creation-time computes and flushes that run inside the window.
223
+ const A = latestReadActive;
224
+ latestReadActive = false;
225
+ // A memo computes under its OWN lane posture, never the puller's (A31,
226
+ // #3442): its value is one shared slot every reader sees, so a pull from a
227
+ // lane-carrying reader (a probe effect on its companion lane pulling a sync
228
+ // memo) must not run it with that lane's read carve-outs — under a lane, a
229
+ // pending node on no lane serves its committed value instead of throwing,
230
+ // and the memo then published a stale "settled" value, dropped its
231
+ // pending status, and stopped holding its transaction. The branches below
232
+ // re-establish the posture the memo itself owns (OPT-dirty, or adopted
233
+ // through its deps). Effects keep the ambient lane: their runs are the
234
+ // lane's own view.
235
+ if (!n) currentOptimisticLane = null;
236
+ // Lane posture lives with the engine: OPTIMISTIC_DIRTY is only ever set by
237
+ // engine-driven paths, and _optimisticNodes is only pushed by
238
+ // _optimisticWrite, so the hook is installed whenever either gate holds.
239
+ if (l) {
240
+ const t = GlobalQueue.gt(e, true);
241
+ if (t) currentOptimisticLane = t;
242
+ // `false` = wake-only lane demotion: recompute plain so a mid-tick
243
+ // latest()/isPending() pull stages instead of direct-committing (#3009).
244
+ // The predicate lives with the engine (recomputeLane).
245
+ else if (t === false) l = false;
246
+ } else if (e.C & CONFIG_DERIVED_OVERRIDE) {
247
+ // Lanes stage (#3479): a pass over a live lane member carrying a derived
248
+ // override is the lane's pass whatever channel dirtied it (a boundary
249
+ // reset, an unrelated sync write) — its inputs serve the lane's view, so
250
+ // its result is the lane's and belongs in the override slot. Run plain,
251
+ // A18's sync twin below read that re-derived lane view as a differing
252
+ // truth (a fresh array), superseded the override and demoted the lane;
253
+ // the lane's next pass then dropped the staged "truth" and left the node
254
+ // flagged superseded with nothing to serve (fuzzer latest-1 #2481). A
255
+ // demoted node resolves no lane and stays plain: its pass IS the truth.
256
+ const t = GlobalQueue.gt(e, true);
257
+ if (t) {
258
+ l = true;
259
+ currentOptimisticLane = t;
260
+ }
261
+ } else if (activeTransition && !t && activeTransition.tn.length) {
262
+ // Lane adoption: parent-deeper-than-owned-child can run before its OPT-dirty
263
+ // child propagates. Walk deps once and inherit the OPT lane so this node
264
+ // recomputes under the right posture and propagates correctly.
265
+ const t = GlobalQueue.gt(e, false);
266
+ if (t) {
267
+ l = true;
268
+ currentOptimisticLane = t;
269
+ }
270
+ }
271
+ const C = n && n !== EFFECT_USER;
272
+ const p = stale;
273
+ if (C) stale = true;
274
+ // An effect recorded for this transaction's commit replay (it once read a
275
+ // node the transaction held and showed the committed value) and now
276
+ // recomputing UNDER the transaction sees its staged view: the value this
277
+ // run produces is applied by the commit itself, and the stale recording
278
+ // would publish the frame a second time. Drop it; the reads below re-record
279
+ // if they are served the committed view again (a lane's committed read).
280
+ if (n && activeTransition !== null && activeTransition.Ht.size) activeTransition.Ht.delete(e);
281
+ try {
282
+ if (!false && e.C & CONFIG_SYNC) {
283
+ E = e.ht(E);
284
+ if (e.o !== null) e.o.ce = null;
285
+ e.Se = false;
286
+ } else {
287
+ // Snapshot `_inFlight` so we can detect whether `_fn` self-registered an async
288
+ // subscription (e.g. `createProjection` calls `handleAsync` from inside its body
289
+ // with a setter callback). In that case, the outer `handleAsync` call below would
290
+ // clobber the fresh subscription, so we skip it and let the internally-registered
291
+ // iteration drive updates.
292
+ const t = e.o?.ce;
293
+ const n = e.ht(E);
294
+ const i = typeof n === "object" && n !== null;
295
+ const l = e.o?.ce !== t;
296
+ E = l || !i ? n : handleAsync(e, n);
297
+ if (!l && !i) {
298
+ if (e.o !== null) e.o.ce = null;
299
+ // A sync (non-object) return is the first real answer; async-shaped
300
+ // results clear inside handleAsync at their own landing points, and a
301
+ // self-registered flight (inFlightChanged — projections) clears when
302
+ // its internal handleAsync lands.
303
+ e.Se = false;
304
+ }
305
+ }
306
+ // On a status-free node clearStatus is a guaranteed no-op: every field
307
+ // its body gates on is either _statusFlags or lives in the cold
308
+ // extension — no extension, no status to clear. (_x from an unrelated
309
+ // installer just makes clearStatus a cheap re-verified no-op.)
310
+ // A node born held keeps STATUS_UNINITIALIZED until its transaction
311
+ // commits: it has no committed value, and read() holds its readers.
312
+ if (e.S !== 0 || e.o !== null) clearStatus(e, t && stagedEntry === null);
313
+ // _optimisticLane is only ever assigned by engine paths (CONFIG_HAS_LANE
314
+ // is their sticky presence mark).
315
+ if (e.C & CONFIG_HAS_LANE && e.o?.de) GlobalQueue.vt(e);
316
+ } catch (t) {
317
+ const n = t instanceof NotReadyError;
318
+ if (n && e.Se) {
319
+ // Loading window with an unready sync dependency: register for the
320
+ // source's settle (the settlePendingSource walk runs off
321
+ // _pendingSources + _blocked alone) but take NO read-visible pending
322
+ // status, no downstream propagation, no transition, no lane
323
+ // registration — the committed loading value keeps serving. If the
324
+ // node is currently errored the error stays the answer until this
325
+ // retry can actually run.
326
+ parkLoadingWindow(e, t);
327
+ } else {
328
+ // Track pending async in the lane (not the lane's source — it creates the lane
329
+ // but doesn't belong to it). Set lane BEFORE notifyStatus for downstream propagation.
330
+ if (n && currentOptimisticLane) GlobalQueue.kt(e);
331
+ let i = false;
332
+ if (n) {
333
+ ext(e).oe = true;
334
+ if (GlobalQueue.bt !== null) i = GlobalQueue.bt(e, f);
335
+ }
336
+ notifyStatus(e, n ? STATUS_PENDING : STATUS_ERROR, t, undefined, n ? e.o?.de : undefined);
337
+ // The replacement source is fully propagated now. If no new flight
338
+ // re-owned self, retire the superseded flight and its dependent copies.
339
+ if (n && c && !e.o?.ce) settlePendingSource(e);
340
+ // A re-park drops what the earlier pass carried (#3456): a source this
341
+ // pass no longer reaches — its branch switched, or a fresh flight
342
+ // replaced the inputs' pending with its own — stays copied onto
343
+ // dependents that reached it only through here, and its landing walk
344
+ // stops at this node (nothing left to retire) before it finds them. A
345
+ // dependent then waits forever on a flight it has no path to. The
346
+ // re-park twin of the unchanged-value recovery sweep below; dependents
347
+ // with another path keep the source (retryReaches).
348
+ if (n && a) for (const t of a) if (t !== e && !e.o?.ut?.has(t)) settlePendingSource(e, t);
349
+ if (i) GlobalQueue.k(e);
350
+ }
351
+ } finally {
352
+ tracking = S;
353
+ latestReadActive = A;
354
+ if (C) stale = p;
355
+ // Consume the missed-wake latch (#3037, set by insertSubs): a dep write
356
+ // landed beneath this pass on a link it had already validated. The wipe
357
+ // below must not key off DIRTY/CHECK — the read-time pull protocol
358
+ // (markNode(c) in read()) marks the running node as part of ordinary
359
+ // bookkeeping, and those marks are correctly discarded here.
360
+ T = (e.ft & REACTIVE_MISSED_WAKE) !== 0;
361
+ e.ft = REACTIVE_NONE | (t ? e.ft & REACTIVE_SNAPSHOT_STALE : 0);
362
+ context = d;
363
+ }
364
+ // The cast re-widens: TS narrowed `stagedEntry` to `null` at the reset
365
+ // above and does not invalidate that across the compute call that
366
+ // `enterStagedRead` runs under. No emitted code.
367
+ const R = stagedEntry;
368
+ stagedEntry = N;
369
+ if (!e.o?._) {
370
+ // Observe-tier fan-in (HUGE_FAN_IN): the validated prefix [_deps.._depsTail]
371
+ // IS this pass's distinct sources — count it here rather than per link. A
372
+ // begin/end bracket around the pass plus a per-link increment measured
373
+ // -5.8% on createRenderEffects:create1to1 (CodSpeed, dev tier) and cost
374
+ // several points of the shape wins elsewhere; this walk is a fraction of
375
+ // the reads that built the list and keeps no module state, so nested
376
+ // pulls need no save/restore. (The stale tail is trimmed at the end of
377
+ // this pass, or at its commit — see recompute's tail.)
378
+ {
379
+ let t = 0;
380
+ for (let n = e.ee; n !== null; n = n.te) {
381
+ t++;
382
+ if (n === e.Fe) break;
383
+ }
384
+ if (t >= GRAPH_SIZE_WARN_AT) noteFanIn(e, t);
385
+ }
386
+ // INV-11 (#3330): the equality gate compares against the slot this run
387
+ // publishes to. An override-covered node publishes the override; a lane
388
+ // recompute (OPT-dirty) direct-commits `_value` — the lane's own reveal
389
+ // schedule — so a transaction-held `_pendingValue` that already equals
390
+ // the new result is not "unchanged": the screen still shows `_value`.
391
+ // Only a transaction-staged run compares against `_pendingValue`.
392
+ const s = u ? unwrapOverride(e.o?.Ne) : l || e._e === NOT_PENDING ? e.Ae : e._e;
393
+ let f = false;
394
+ try {
395
+ f = !n && o || !e.Re || !e.Re(s, E);
396
+ } catch (t) {
397
+ // A throwing user comparator is an error of this node's computation.
398
+ // Route it through the same status path as a compute-phase throw so
399
+ // error boundaries contain it; otherwise it unwinds the scheduler
400
+ // flush, bypassing every boundary and wedging the queue (#2837).
401
+ notifyStatus(e, STATUS_ERROR, t);
402
+ }
403
+ // A committed derived change becomes a cause for this node's subscribers,
404
+ // chaining their attribution through this node to the root write.
405
+ if (attrHooks !== null) {
406
+ i = f && !e.o?._;
407
+ if (i && !n && !t) attrHooks.derivedChanged(e);
408
+ }
409
+ // Effects use `_equals: false` (no per-effect closure). The side effects that
410
+ // the equals closure used to perform — flagging the effect dirty and enqueueing
411
+ // its runner — happen here instead. `!create` matches the previous `initialized`
412
+ // gate: the explicit recompute(node, true) inside effect() does not enqueue, so
413
+ // effect() can call its runner synchronously for the first run.
414
+ if (n && f) {
415
+ e.Nt = !e.o?._;
416
+ // Reuse one bound runner per effect — runEffect no-ops on a stale
417
+ // `_modified`, so re-enqueueing the same function is harmless.
418
+ if (!t) {
419
+ e.T.enqueue(n, e.Ut ??= GlobalQueue.Lt.bind(null, e));
420
+ // Contested effect (#3322). Effects don't entangle transactions (a
421
+ // shared effect is not shared state), yet they have one value slot:
422
+ // when this write commits under a different transaction
423
+ // (`activeTransition`, null = mainline) than the one that produced the
424
+ // previous value (`_valueTransition`), that view is gone. Rather than
425
+ // merge the two, each commit re-derives the effect against its own
426
+ // committed world (Transition._contested, re-dirtied by
427
+ // finalizePureQueue ahead of the heap run). The previous owner always
428
+ // needs it if still live: its commit is silent (staging already
429
+ // notified) and the value it computed is gone. The new owner needs it
430
+ // too, for the same reason, unless it is mainline — mainline publishes
431
+ // what it computes. A previous owner that was mainline, or already
432
+ // committed, left nothing to protect.
433
+ let t = e.Vt;
434
+ if (t !== activeTransition) {
435
+ e.Vt = activeTransition;
436
+ if (t !== null && (t = currentTransition(t)) !== activeTransition && !t.yt) {
437
+ (t.xt ??= []).push(e);
438
+ if (activeTransition !== null) (activeTransition.xt ??= []).push(e);
439
+ }
440
+ }
441
+ }
442
+ }
443
+ if (e.o?._) ; else if (f) {
444
+ const i = u ? e.o?.Ne : undefined;
445
+ if (t && R === null ||
446
+ // Plain sync flush (no transition on either side) commits effect
447
+ // values directly — the pending round-trip (queuePendingNode +
448
+ // commitPendingNodes) exists to sequence transition reveals, and
449
+ // paying it per effect on the plain path is pure overhead.
450
+ // DIRECT_COMMIT effects (resolve/until) commit directly even under
451
+ // their own held transition: their applies deliver on a microtask,
452
+ // not the stashed queues, so a staged value would hand the immediate
453
+ // apply stale state — see CONFIG_DIRECT_COMMIT.
454
+ n && R === null && (activeTransition !== e.Te || activeTransition === null || e.C & CONFIG_DIRECT_COMMIT) || l) {
455
+ // Lanes stage (#3479): a lane pass on a memo publishes its speculative
456
+ // result as an OVERRIDE — `_value` stays the committed truth, so a
457
+ // reader off the lane (A17's committed view, #3460) sees a whole
458
+ // committed frame: the source's shadow and its derivations together,
459
+ // never a committed shadow beside a speculative memo. The lane's own
460
+ // readers and untracked reads see the override (A17); the revert
461
+ // drops it and re-derives (resolveOptimisticNodes). Effects keep the
462
+ // direct commit — their `_value` is a run result the lane's queues
463
+ // already sequence. Either way the lane pass drops any superseded
464
+ // older hold so its queued commit can't clobber the fresh frame: a
465
+ // hold staged on an earlier, lane-free pass of the SAME transaction
466
+ // is superseded — left in place, the commit published the older
467
+ // frame over the fresh one (#3377). A reversion pass (OPT-dirty with
468
+ // no lane — the override dropped) commits directly: it IS the truth.
469
+ if (l && !n && currentOptimisticLane !== null) GlobalQueue.ge(e, E, currentOptimisticLane); else e.Ae = E;
470
+ if (l) e._e = NOT_PENDING;
471
+ } else {
472
+ e._e = E;
473
+ if (R !== null) {
474
+ // Born held: the pass ran from mainline and derived from this
475
+ // transaction's staged world (enterStagedRead). Its value is the
476
+ // transaction's — staged into it directly, stamped, and committed
477
+ // with it; mainline's batch never sees it. A born-held effect
478
+ // skips its synchronous first run (effect()) and is replayed by
479
+ // the commit like a stale reader that showed the committed frame.
480
+ e.Te = R;
481
+ R.sn.push(e);
482
+ if (n) R.Ht.add(e);
483
+ }
484
+ // A window landing that gets held re-opens the window until the hold
485
+ // commits — the verdict's held-value branch is window-gated (#2990).
486
+ if (_) e.Se = true;
487
+ // A staged sync recompute is a write path like setSignal/asyncWrite,
488
+ // so sync derivations of held sources stay visible to isPending()/latest()
489
+ // (#2831). Both companion writes are transition-scoped (optimistic) and
490
+ // auto-revert/re-derive at commit. Not gated on an active transition:
491
+ // a plain flush can still become a hold after this recompute — an
492
+ // async memo downstream pends and the batch is adopted into a
493
+ // transaction (scheduler.enterTransition) — and nothing re-derives
494
+ // the companion at adoption, so a memo held that way read
495
+ // isPending() false while its held source read true (#3413).
496
+ if (e.C & CONFIG_HAS_COMPANIONS && GlobalQueue.De !== null) GlobalQueue.De(e, E);
497
+ }
498
+ // insertSubs only walks _subs (no scheduling of its own), so a
499
+ // subscriber-less node has nothing to notify.
500
+ if (e.u !== null && (!u || l || e.o?.Ne !== i)) insertSubs(e, l || u);
501
+ // A18 supersession, sync twin of asyncWrite's override branch (#3331):
502
+ // this pass published truth that differs from the override (the gate
503
+ // compared against it) into the transaction-held slot. Whether the
504
+ // source is this node's own async or an upstream node it derives from
505
+ // synchronously makes no difference — "the source recomputed". The
506
+ // override stays displayed until the commit; the graph moves to the
507
+ // staged truth now (plain channel, lane demoted). Ordering: "a new
508
+ // value from the source" postdates the override — an override written
509
+ // in this same tick (optimisticWrite stamps `_overrideTime`) is the
510
+ // newer intent over whatever this pass derives from the batch's staged
511
+ // inputs, and is not superseded by it.
512
+ else if (u && !l && e.o.Qt !== clock) GlobalQueue.Oe(e, E);
513
+ } else if (u) {
514
+ // Unchanged value (equals the override) recomputed while the override
515
+ // is active: _value may still be stale, so hold the authoritative value
516
+ // for commit on its own transition's schedule — invisibly (A17/A18).
517
+ if (e._e === NOT_PENDING) queuePendingNode(e);
518
+ e._e = E;
519
+ if (_) e.Se = true;
520
+ // see the held branch above (#2990)
521
+ // A confirmation after a supersession restores the override as the
522
+ // graph's value and notifies; a plain confirmation wakes only an
523
+ // authoritative-view reader (until()'s predicate, refresh()'s waiter)
524
+ // that observed this node past its override — "authoritative arrival
525
+ // equal to the override" is exactly the acknowledgment it waits for;
526
+ // A17 silence holds for every ordinary subscriber. Both live in the
527
+ // engine's supersedeOverride.
528
+ GlobalQueue.Oe(e, E);
529
+ } else if (e.Rt != I) {
530
+ for (let t = e.u; t !== null; t = t.ie) {
531
+ insertIntoHeapHeight(t.se, queueFor(t.se));
532
+ }
533
+ }
534
+ // Silent recovery: errored → unchanged value fires no notification, but
535
+ // dependents still holding the propagated error consumed their dirty flag
536
+ // in an errored run and may sit on stale commits (#2949). Changed-value
537
+ // recoveries ride insertSubs above; a comparator throw re-errored the node
538
+ // (el._x?._error re-set), so this only runs on a genuinely clean recovery.
539
+ if (!f && !e.o?._) {
540
+ if (r !== undefined) settleErroredDependents(e, r);
541
+ // Self-registration (this node's own superseded flight) is the #3181
542
+ // sweep's business below — retiring it here too would walk twice.
543
+ if (a) for (const t of a) if (t !== e) settlePendingSource(e, t);
544
+ }
545
+ // #3181: a synchronous settle supersedes the old landing callback, so
546
+ // recompute owns its pending-source sweep. An uninitialized node without
547
+ // a replacement source still has no truth to reveal and must stay parked.
548
+ if (c && !(e.S & (STATUS_PENDING | STATUS_UNINITIALIZED))) settlePendingSource(e);
549
+ }
550
+ // A REPORTER whose pass stopped reading a source it reported on (a gate
551
+ // closed) stops counting for the transaction waiting on it (A15 / #3426:
552
+ // the hold lasts while a live reporter observes the flight). Nothing else
553
+ // re-judges a parked transaction (see wokenTransitions; the disposal
554
+ // (#3372) and boundary (#3375) twins of this site), so the writes it held
555
+ // stayed staged for as long as the flight stayed up — forever, for one
556
+ // that never lands (fuzzer #3446 P1, spec O3). The event is "this pass
557
+ // dropped a dep" — deps past `_depsTail` (trimmed below, or kept by A30
558
+ // for a staged pass), or a pass that read nothing — not "recovered from
559
+ // pending": a reporter registered by the stale-reader carve-out
560
+ // (heldFromStale, an INITIALIZED source refetching) displays the committed
561
+ // value and is never pending (fuzzer case 79). Every parked transaction,
562
+ // not the reporter's stamp: the transaction waiting on it registered it
563
+ // without stamping it. One idle pass per parked transaction; done ones
564
+ // return at re-entry. Effects only — reporters register from render-effect
565
+ // notification (INV-3).
566
+ // (`_depsTail` was reset at the top of the pass; TS keeps that narrowing.)
567
+ const G = e.Fe;
568
+ if (n && (s && !(e.S & STATUS_PENDING) || (G === null ? e.ee !== null : G.te !== null))) wakeParked();
569
+ // Dependencies are the committed frame's until it is replaced (A30, #3410; the
570
+ // deps twin of the held children above): a pass that staged its value
571
+ // leaves the previous pass's tail linked for `commitPendingNode` to trim,
572
+ // so a write to a dependency the committed value still derives from
573
+ // reaches this node — and joins its hold if the stage is transaction-held
574
+ // by then (a plain flush decides nothing here: the transaction that holds
575
+ // the pass may open later in the same flush). A pass that published
576
+ // directly (a first pass, a lane's own reveal) trims now. An errored pass
577
+ // (a throw, NotReady included, or a comparator throw above) keeps its full
578
+ // list as before — `_depsTail` marks where it stopped — and the commit
579
+ // skips it by the same `_error`. An effect's frame is the run its value is
580
+ // applied by, not the value slot (#3438): a direct-committed pass that
581
+ // still owes a run (`_modified`) has not replaced what the last run
582
+ // published — the same flush may stash that run into a transaction it
583
+ // opens later — so its tail waits for `runEffect` to trim once the run
584
+ // applies. A pass that changed nothing replaced nothing either (#3469): the
585
+ // same flush may park with its inputs held, and the committed frame still
586
+ // derives from the tail — its trim waits on the flush's verdict (heldTrims).
587
+ // A tracked effect's pass IS its run (it bypasses the heap and runs after
588
+ // the commit): the frame is replaced, trim now.
589
+ if (!e.o?._ && e._e === NOT_PENDING && !(n && e.Nt)) {
590
+ if (t || l || n === EFFECT_TRACKED) trimStaleDeps(e); else if (e.Fe?.te ?? e.ee) heldTrims.push(e);
591
+ }
592
+ // Attribution hook: fired before the lane restore so `currentOptimisticLane`
593
+ // still reflects THIS run's posture. The facts distinguish an overlay
594
+ // recompute (optimistic lane, transition replay, transition-held commit)
595
+ // from a plain committed one — the engine must not blame overlay runs as
596
+ // waste or double-count them against plain aggregates.
597
+ if (attrHooks !== null) attrHooks.recomputeEnd(e, t, i, l || currentOptimisticLane !== null, activeTransition !== null || e.Te !== null, e._e !== NOT_PENDING);
598
+ currentOptimisticLane = O;
599
+ const D = e._e !== NOT_PENDING || e.o !== null && (e.o.Pt !== null || e.o.Dt !== null) || (e.S & (STATUS_PENDING | STATUS_UNINITIALIZED)) !== 0;
600
+ // Override-covered holds (hasOverride) always queue: their commit belongs
601
+ // to their own transition's schedule (A18 re-rule) and is unobservable
602
+ // under the override (A17). Revert no longer commits anything, so an
603
+ // unqueued covered hold would leak (INV-7) once the revert clears
604
+ // _transition.
605
+
606
+ // While a pass's result waits on a commit, its children (and `_disposal`)
607
+ // wait with it, and a re-run may tear them down immediately
608
+ // (CONFIG_HELD_CHILDREN, #3404). One exception: a transaction-owned effect
609
+ // recomputed mainline (contested, #3322) published its value directly — a
610
+ // `_pendingValue` left from an earlier held pass is that transaction's,
611
+ // not this one's — so this pass's children are the frame's, and any
612
+ // zombies deferred at the top are superseded on that same frame. Its
613
+ // commit rides the transaction, not this flush: release them here rather
614
+ // than let two generations render at once.
615
+ let h = D && (!t || R !== null || (e.S & STATUS_PENDING) !== 0);
616
+ if (h && (!e.Te || u)) queuePendingNode(e); else if (h && activeTransition === null && !(e.S & (STATUS_PENDING | STATUS_UNINITIALIZED))) {
617
+ h = false;
618
+ disposeChildren(e, false, true);
619
+ }
620
+ if (h) e.C |= CONFIG_HELD_CHILDREN; else e.C &= ~CONFIG_HELD_CHILDREN;
621
+ // (A born-held pass IS the transaction's staged view — nothing to refresh.)
622
+ if (e.Te && n && activeTransition !== e.Te && R === null) {
623
+ // The re-run refreshes the transaction's STAGED view (_pendingValue); the
624
+ // value this pass published in _value belongs to the run that just
625
+ // finished. Keep that ownership, or the effect phase parks a
626
+ // mainline-computed value with the transaction (#3412).
627
+ const t = e.Vt;
628
+ runInTransition(e.Te, () => recompute(e));
629
+ e.Vt = t;
630
+ }
631
+ // Missed-wake reschedule (see the finally above): values this pass read
632
+ // before the nested commit are stale, so run again now that the heap will
633
+ // accept the node. Equality gates stop same-value landings from cascading,
634
+ // and a re-run only latches again if another nested commit changes a dep
635
+ // beneath it — convergent unless deps genuinely keep changing.
636
+ if (T) {
637
+ enqueueSub(e);
638
+ schedule();
639
+ }
640
+ }
641
+
642
+ function updateIfNecessary(e) {
643
+ // Never re-enter a node that is currently computing: its dep bookkeeping
644
+ // (_depsTail/_depGen) is live, and a nested recompute would corrupt it.
645
+ // A mid-pass mark stays latched for recompute's own tail to reschedule
646
+ // (#3037); readers meanwhile serve the values the pass has so far.
647
+ // Never recompute a DISPOSED node either: recompute rewrites _flags and
648
+ // would resurrect it (#2983) — readers serve its last value.
649
+ if (e.ft & (REACTIVE_RECOMPUTING_DEPS | REACTIVE_DISPOSED)) return;
650
+ if (e.ft & REACTIVE_CHECK) {
651
+ for (let t = e.ee; t; t = t.te) {
652
+ const n = t.re;
653
+ const i = n.ne || n;
654
+ if (i.ht) {
655
+ updateIfNecessary(i);
656
+ }
657
+ if (e.ft & REACTIVE_DIRTY) {
658
+ break;
659
+ }
660
+ }
661
+ }
662
+ if (e.ft & (REACTIVE_DIRTY | REACTIVE_OPTIMISTIC_DIRTY) || e.o?._ && e.fe < clock && !e.o?.ce) {
663
+ recompute(e);
664
+ }
665
+ e.ft = e.ft & (REACTIVE_SNAPSHOT_STALE | REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT);
666
+ }
667
+
668
+ function computed(e, t) {
669
+ const n = t?.transparent ?? false;
670
+ // `in` (not `!== undefined`): an explicit `loadingValue: undefined` on a
671
+ // `T | undefined` node is a real commit #0. The typeof guard tolerates
672
+ // non-object option values that older call shapes force through `as any`.
673
+ const i = t !== null && typeof t === "object" && "loadingValue" in t;
674
+ // Two literals, one per tier, selected at build time (the observe flag is
675
+ // a literal after replacement; the untaken branch is dead code). The observe
676
+ // literal is the prod literal plus its `_name` slot — a slot in the
677
+ // boilerplate, because a post-construction `self._name = …` forces a
678
+ // hidden-class transition and an out-of-object property store on EVERY node
679
+ // (measured: the whole of the observe tier's creation overhead). Keep the
680
+ // two in sync — the dist artifact test pins observe's key set to prod's
681
+ // plus `_name`.
682
+ const l = {
683
+ id: inheritId(t, n, context),
684
+ C: (n ? CONFIG_TRANSPARENT : 0) | (t?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (!context || t?.lazy ? CONFIG_AUTO_DISPOSE : 0) | (t?.sync ? CONFIG_SYNC : 0) | (t?.q ? CONFIG_NO_SNAPSHOT : 0) | (snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
685
+ Re: t?.equals ?? isEqual,
686
+ Ue: null,
687
+ T: context?.T ?? globalQueue,
688
+ wt: context?.wt ?? defaultContext,
689
+ Ft: 0,
690
+ ht: e,
691
+ Ae: i ? t.loadingValue : undefined,
692
+ Rt: 0,
693
+ Wt: undefined,
694
+ Mt: null,
695
+ ee: null,
696
+ Fe: null,
697
+ ye: 0,
698
+ u: null,
699
+ qt: null,
700
+ _parent: context,
701
+ At: null,
702
+ Yt: null,
703
+ Ot: null,
704
+ ft: t?.lazy ? REACTIVE_LAZY : REACTIVE_NONE,
705
+ S: i ? 0 : STATUS_UNINITIALIZED,
706
+ fe: clock,
707
+ _e: NOT_PENDING,
708
+ Te: null,
709
+ Zt: -1,
710
+ Se: i,
711
+ o: null,
712
+ _name: t?.name ?? "computed"
713
+ };
714
+ if (t?.unobserved) ext(l).Kt = t.unobserved;
715
+ setupComputedNode(l, t);
716
+ return l;
717
+ }
718
+
719
+ /** Lazily allocate a node's cold extension (ONE shape for signals and
720
+ * computeds — `_x` access stays monomorphic). Installers write through
721
+ * this; hot paths read `el._x?._field` gated by the _config presence bits.
722
+ * Never call ext() just to store a field's default. */ function ext(e) {
723
+ return e.o ??= {
724
+ Ne: undefined,
725
+ jt: undefined,
726
+ Qt: 0,
727
+ Bt: NOT_PENDING,
728
+ zt: 0,
729
+ de: undefined,
730
+ he: undefined,
731
+ Ge: undefined,
732
+ nn: undefined,
733
+ t: 0,
734
+ ce: null,
735
+ ae: null,
736
+ _: undefined,
737
+ oe: undefined,
738
+ ut: undefined,
739
+ h: undefined,
740
+ Ee: false,
741
+ i: null,
742
+ Kt: undefined,
743
+ Gt: undefined,
744
+ Dt: null,
745
+ Pt: null,
746
+ Jt: undefined
747
+ };
748
+ }
749
+
750
+ /**
751
+ * Build an Effect node with all effect-specific fields baked into a single object literal,
752
+ * so V8 sees the full hidden class shape at construction time. Effects always run in lazy
753
+ * mode (recompute is called explicitly by `effect()`), so we hardcode the lazy bits and skip
754
+ * the auto-dispose CONFIG bit (effect() previously cleared it post-construction).
755
+ */ function createEffectNode(e, t, n, i, l) {
756
+ const u = l?.transparent ?? false;
757
+ // Prod and observe boilerplates — see computed() for why the observe tier
758
+ // gets its `_name` as a literal slot rather than a write after the fact.
759
+ // The default label is the node kind (tracked effects relabel their computed
760
+ // in trackedEffect); the wrappers in signals.ts no longer spread a name into
761
+ // the options to get it.
762
+ const o = {
763
+ id: inheritId(l, u, context),
764
+ C: (u ? CONFIG_TRANSPARENT : 0) | (l?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (l?.sync ? CONFIG_SYNC : 0) | (l?.Xt ?? 0) | (snapshotCaptureActive && ownerInSnapshotScope(context) ? CONFIG_IN_SNAPSHOT_SCOPE : 0),
765
+ Re: false,
766
+ Ue: null,
767
+ T: context?.T ?? globalQueue,
768
+ wt: context?.wt ?? defaultContext,
769
+ Ft: 0,
770
+ ht: e,
771
+ Ae: undefined,
772
+ Rt: 0,
773
+ Wt: undefined,
774
+ Mt: null,
775
+ ee: null,
776
+ Fe: null,
777
+ ye: 0,
778
+ u: null,
779
+ qt: null,
780
+ _parent: context,
781
+ At: null,
782
+ Yt: null,
783
+ Ot: null,
784
+ ft: REACTIVE_LAZY,
785
+ S: STATUS_UNINITIALIZED,
786
+ fe: clock,
787
+ _e: NOT_PENDING,
788
+ Te: null,
789
+ Zt: -1,
790
+ Se: false,
791
+ Nt: false,
792
+ $t: undefined,
793
+ ln: t,
794
+ un: n,
795
+ an: undefined,
796
+ Pe: i,
797
+ Vt: null,
798
+ o: null,
799
+ _name: l?.name ?? "effect"
800
+ };
801
+ // Effects dispatch status through the SHARED notifier (statusNotifierOf,
802
+ // keyed off _type) — storing it per node forced a full NodeExtension
803
+ // allocation on EVERY effect at creation (an alloc + 19 field stores,
804
+ // +23% effect creation, caught by the creation benches). Only genuinely
805
+ // per-node channels (boundaries) live on _x.
806
+ if (l?.unobserved) ext(o).Kt = l.unobserved;
807
+ setupComputedNode(o, lazyOptions);
808
+ return o;
809
+ }
810
+
811
+ /**
812
+ * The shared status notifier for effect nodes, installed once by effect.ts
813
+ * at module evaluation (`this`-dispatched — one function serves every
814
+ * effect, so nodes never store it). Boundary computeds keep their own
815
+ * per-node channel on `_x._notifyStatus`, which takes precedence.
816
+ */ let effectStatusNotify = null;
817
+
818
+ function setEffectStatusNotify(e) {
819
+ effectStatusNotify = e;
820
+ }
821
+
822
+ /** Resolve a node's status notifier: an own `_x` channel (boundaries) wins;
823
+ * effect nodes (`_type` — EFFECT_PURE is 0, and only effect literals carry
824
+ * the field) fall back to the shared notifier. Presence doubles as the
825
+ * "display consumer" membership test in the status walks, exactly as the
826
+ * per-node field did when every effect carried one. */ function statusNotifierOf(e) {
827
+ const t = e.o?.h;
828
+ if (t !== undefined) return t;
829
+ return e.Pe ? effectStatusNotify ?? undefined : undefined;
830
+ }
831
+
832
+ const lazyOptions = {
833
+ lazy: true
834
+ };
835
+
836
+ function setupComputedNode(e, t) {
837
+ e.Mt = e;
838
+ const n = context?.cn ? context.fn : context;
839
+ if (context) {
840
+ const t = context.Ot;
841
+ if (t === null) {
842
+ context.Ot = e;
843
+ } else {
844
+ e.At = t;
845
+ t.Yt = e;
846
+ context.Ot = e;
847
+ }
848
+ }
849
+ if (n) e.Rt = n.Rt + 1;
850
+ if (GlobalQueue._n !== null) GlobalQueue._n(e);
851
+ !t?.lazy && recompute(e, true);
852
+ if (snapshotCaptureActive && !t?.lazy) {
853
+ if (!(e.S & STATUS_PENDING) && !(e.C & CONFIG_NO_SNAPSHOT)) {
854
+ ext(e).Gt = e.Ae === undefined ? NO_SNAPSHOT : e.Ae;
855
+ e.C |= CONFIG_HAS_SNAPSHOT;
856
+ snapshotSources.add(e);
857
+ }
858
+ }
859
+ }
860
+
861
+ function signal(e, t, n = null) {
862
+ // Prod and observe boilerplates — see computed(). The observe literal adds
863
+ // `_name` and `_owner` (the creating owner, stamped by registerGraph for
864
+ // createSignal nodes so ownerPath can locate signal subjects; null here,
865
+ // and staying null on internal signals — one shape either way).
866
+ const i = {
867
+ Re: t?.equals ?? isEqual,
868
+ C: (t?.ownedWrite ? CONFIG_OWNED_WRITE : 0) | (t?.q ? CONFIG_NO_SNAPSHOT : 0),
869
+ Ae: e,
870
+ u: null,
871
+ qt: null,
872
+ fe: clock,
873
+ ne: n,
874
+ ue: n?.o?.i || null,
875
+ Nn: null,
876
+ _e: NOT_PENDING,
877
+ Te: null,
878
+ Zt: -1,
879
+ o: null,
880
+ _name: t?.name ?? "signal",
881
+ nt: null
882
+ };
883
+ if (t?.unobserved) ext(i).Kt = t.unobserved;
884
+ if (n) linkFirewallChild(n, i);
885
+ if (snapshotCaptureActive && !(i.C & CONFIG_NO_SNAPSHOT) && !((n?.S ?? 0) & STATUS_PENDING)) {
886
+ ext(i).Gt = e === undefined ? NO_SNAPSHOT : e;
887
+ i.C |= CONFIG_HAS_SNAPSHOT;
888
+ snapshotSources.add(i);
889
+ }
890
+ return i;
891
+ }
892
+
893
+ // ---------------------------------------------------------------------------
894
+ // SLOT SIGNALS (store leaves) — the create-floor diet. Store mounts
895
+ // materialize one signal per touched leaf (~13 × rows on dbmon), so per-node
896
+ // allocations are mount bytes: the generic path costs an options object, an
897
+ // equals closure, an unobserved closure, a NodeExtension to hold it, and
898
+ // three post-construction expandos (acc/px/pxv → hidden-class transitions).
899
+ // slotSignal bakes everything into ONE literal: `_host`/`_key` backrefs
900
+ // replace the closures (equals is a method call — `this` is the node; the
901
+ // unobserved sweep dispatches CONFIG_SLOT_NODE to one shared hook), and the
902
+ // store's wrap-cache fields are pre-shaped.
903
+ /** The shared slot-node unobserved handler — a live binding read directly by
904
+ * the sweep sites (no wrapper frame, no null check: a CONFIG_SLOT_NODE node
905
+ * existing implies the store module loaded and registered the hook). */ let slotUnobservedHook;
906
+
907
+ /** Install the shared slot-node unobserved handler (store module, once). */ function setSlotUnobserved(e) {
908
+ slotUnobservedHook = e;
909
+ }
910
+
911
+ /** Push a new node onto its firewall's child chain (the literal already
912
+ * points `_nextChild` at the old head). Doubly linked so a released leaf
913
+ * unlinks in O(1) — the chain is walked per mark of the projection and
914
+ * would otherwise grow by one node per leaf ever read (#3351). */ function linkFirewallChild(e, t) {
915
+ const n = t.ue;
916
+ if (n !== null) n.Nn = t;
917
+ ext(e).i = t;
918
+ e.C |= CONFIG_FW_CHILDREN;
919
+ }
920
+
921
+ /** Release a firewall child the store no longer addresses (unobserved sweep
922
+ * dropped it from its target's cache): unlink it from the chain so the
923
+ * projection stops retaining it and its last value. The node keeps its own
924
+ * `_nextChild` so a walk that is mid-chain on it still terminates. It also
925
+ * leaves `_companionChildren` (#3503): the companions themselves are
926
+ * permanent on the node, but the node is unreachable through the store, so
927
+ * the set would only retain it and its last value. */ function unlinkFirewallChild(e) {
928
+ const t = e;
929
+ const n = t.ne;
930
+ if (!n) return;
931
+ const i = t.Nn;
932
+ const l = t.ue;
933
+ if (i !== null) i.ue = l; else if (n.o.i === t) n.o.i = l;
934
+ if (l !== null) l.Nn = i;
935
+ t.Nn = null;
936
+ // #3503: the companion set is the last projection-side reference to a
937
+ // released leaf; leaving it there kept the leaf and its last value alive
938
+ // for the projection's lifetime after every latest()/isPending() reader
939
+ // was disposed.
940
+ n.o.Jt?.delete(t);
941
+ }
942
+
943
+ function slotSignal(e, t, n, i, l, u = null) {
944
+ // Prod and observe boilerplates — see computed(). The store relabels the
945
+ // observe slot (`store.<key>`) when the attribution engine is installed.
946
+ const o = {
947
+ Re: t,
948
+ C: CONFIG_OWNED_WRITE | CONFIG_SLOT_NODE,
949
+ Ae: e,
950
+ u: null,
951
+ qt: null,
952
+ fe: clock,
953
+ ne: u,
954
+ ue: u?.o?.i || null,
955
+ Nn: null,
956
+ _e: NOT_PENDING,
957
+ Te: null,
958
+ Zt: -1,
959
+ o: null,
960
+ dn: n,
961
+ En: i,
962
+ acc: l,
963
+ px: undefined,
964
+ pxv: undefined,
965
+ _name: "signal"
966
+ };
967
+ if (u) linkFirewallChild(u, o);
968
+ if (snapshotCaptureActive && !((u?.S ?? 0) & STATUS_PENDING)) {
969
+ ext(o).Gt = e === undefined ? NO_SNAPSHOT : e;
970
+ o.C |= CONFIG_HAS_SNAPSHOT;
971
+ snapshotSources.add(o);
972
+ }
973
+ return o;
974
+ }
975
+
976
+ function optimisticSignal(e, t) {
977
+ const n = signal(e, t);
978
+ ext(n).Ne = NOT_PENDING;
979
+ n.C |= CONFIG_OPTIMISTIC;
980
+ return n;
981
+ }
982
+
983
+ function optimisticComputed(e, t) {
984
+ const n = computed(e, t);
985
+ ext(n).Ne = NOT_PENDING;
986
+ n.C |= CONFIG_OPTIMISTIC;
987
+ return n;
988
+ }
989
+
990
+ function isEqual(e, t) {
991
+ return e === t;
992
+ }
993
+
994
+ /**
995
+ * Runs `fn` outside of any reactive tracking — reads inside `fn` will not
996
+ * subscribe the current scope. Returns whatever `fn` returns.
997
+ *
998
+ * Use `untrack` inside a memo or effect when you need to read a signal once
999
+ * without making the surrounding computation depend on its future changes.
1000
+ *
1001
+ * Pass a `strictReadLabel` string to enable a dev-mode warning: any reactive
1002
+ * read inside `fn` that isn't inside a nested tracking scope will log a
1003
+ * warning naming the label.
1004
+ *
1005
+ * @example
1006
+ * ```ts
1007
+ * createEffect(
1008
+ * () => trigger(), // tracks `trigger` only
1009
+ * () => {
1010
+ * const snapshot = untrack(() => state); // read once, untracked
1011
+ * log(snapshot);
1012
+ * }
1013
+ * );
1014
+ * ```
1015
+ */ function untrack(e, t) {
1016
+ if (GlobalQueue.In === null && !tracking && true) return e();
1017
+ const n = tracking;
1018
+ tracking = false;
1019
+ try {
1020
+ if (GlobalQueue.In !== null) return GlobalQueue.In(e);
1021
+ return e();
1022
+ } finally {
1023
+ tracking = n;
1024
+ }
1025
+ }
1026
+
1027
+ /**
1028
+ * Set while runtime bookkeeping evaluates a user accessor inside another
1029
+ * node's pass (a loading boundary's `on` key, read from `notify` while the
1030
+ * node that went pending is still recomputing). `context` is that node, but
1031
+ * the read is nobody's: the value is compared, never derived from, so the
1032
+ * untracked-pending re-run link (`read`, `!tracking`) must not be recorded on
1033
+ * it — it made the key's source a dependency of an unrelated async memo
1034
+ * (#3528: `isPending(m2)` through a memo in `on()` linked the memo into `m2`,
1035
+ * a cycle that re-derived `m2` on every pending mark and never converged).
1036
+ */ let spectating = false;
1037
+
1038
+ /**
1039
+ * Evaluates `fn` untracked and without recording a dependency for the
1040
+ * untracked-pending re-run rule on the current `context`. For bookkeeping
1041
+ * reads made mid-propagation on behalf of no node — see `spectating`.
1042
+ */ function spectate(e) {
1043
+ const t = spectating;
1044
+ spectating = true;
1045
+ try {
1046
+ return untrack(e);
1047
+ } finally {
1048
+ spectating = t;
1049
+ }
1050
+ }
1051
+
1052
+ /**
1053
+ * Bring a computed to a readable state: lazy/disposed nodes are (re)computed;
1054
+ * an isPending() probe (`refresh`) additionally pulls the node fully up to
1055
+ * date so its status flags reflect the current graph.
1056
+ */ function prepareComputed(e, t) {
1057
+ if (e.ft & REACTIVE_LAZY) {
1058
+ e.ft &= ~REACTIVE_LAZY;
1059
+ recompute(e, true);
1060
+ } else if (e.ft & REACTIVE_DISPOSED) {
1061
+ // Two disposal lifecycles share the flag (#3024). Observation-lifecycle
1062
+ // nodes (CONFIG_AUTO_DISPOSE) are dormant — torn down by unobserved()
1063
+ // when the last subscriber left — and reads reawaken them; that is the
1064
+ // pay-for-use contract. Owner-lifecycle nodes are dead: recomputing would
1065
+ // re-run user code in a torn-down tree (and discard manual writes on
1066
+ // derived-writable signals), so reads return the last committed value.
1067
+ if (e.C & CONFIG_AUTO_DISPOSE) recompute(e, true);
1068
+ } else if (t) {
1069
+ updateIfNecessary(e);
1070
+ }
1071
+ }
1072
+
1073
+ /**
1074
+ * Sentinel returned by readNodeFast when the plain-signal fast path does not
1075
+ * apply and the caller must fall back to the full read().
1076
+ */ const READ_SLOW = Symbol("read-slow");
1077
+
1078
+ /**
1079
+ * read()'s plain-signal fast path as a standalone entry for hot callers
1080
+ * (store traps). Safe to substitute for read() only because the bail
1081
+ * conditions mirror read()'s prelude and fast-path guard exactly: the
1082
+ * latestRead and pendingCheck windows run side-effectful hooks before the
1083
+ * fast path, `_fn` nodes need prepareComputed, and firewall / override /
1084
+ * snapshot / transition / lane / dev-strictRead state all take the full
1085
+ * resolution. Anything slow returns READ_SLOW; the caller then calls read().
1086
+ */
1087
+ /**
1088
+ * Wake only authoritative-view readers (until() predicates) subscribed to `el`.
1089
+ * The A17-silent ack paths — an authoritative arrival equal to the active
1090
+ * override — use this so the predicate re-evaluates without re-firing
1091
+ * ordinary subscribers whose visible (override) value did not change.
1092
+ * Pay-for-use: reached through GlobalQueue._notifyAuthoritativeObservers,
1093
+ * installed at first until() call — apps that never use until() shake it.
1094
+ */ function notifyAuthoritativeObservers(e) {
1095
+ for (let t = e.u; t !== null; t = t.ie) {
1096
+ const e = t.se;
1097
+ if (!(e.C & CONFIG_AUTHORITATIVE_READ)) continue;
1098
+ // Missed-wake latch (#3037), same contract as insertSubs: the reader may
1099
+ // itself have pulled this recompute (updateIfNecessary from its own
1100
+ // read), and the heap refuses RECOMPUTING nodes — latch so recompute's
1101
+ // tail reschedules it with the staged value visible.
1102
+ if (e.ft & REACTIVE_RECOMPUTING_DEPS && t.pe === e.ye && t !== e.Fe) e.ft |= REACTIVE_MISSED_WAKE;
1103
+ enqueueSub(e);
1104
+ }
1105
+ schedule();
1106
+ }
1107
+
1108
+ /** Installs the authoritative-reader wakeup hook. Idempotent; called by every
1109
+ * creator of a CONFIG_AUTHORITATIVE_READ computation — until() and refresh() —
1110
+ * before its first read (same late-binding contract as the optimistic engine;
1111
+ * the gating bit is only ever set by such a read, so the `!` call sites are
1112
+ * safe once every setter installs, #3303). */ function installAuthoritativeRead() {
1113
+ if (GlobalQueue.Tn === null) GlobalQueue.Tn = notifyAuthoritativeObservers;
1114
+ }
1115
+
1116
+ /**
1117
+ * Stale-reader term of the value selections below: a render effect reading a
1118
+ * node some OTHER live transaction has staged sees the committed value. The
1119
+ * commit is silent — the staging walk was the notification — so a reader
1120
+ * that linked AFTER that walk (an effect created during the hold, a store
1121
+ * key first read under it) would show the old value past the reveal: record
1122
+ * it for the transaction's commit replay (the `_gatedSubs` contract lanes
1123
+ * already use). An effect the transaction itself computed re-derives at its
1124
+ * commit on its own (parked run, or the contested re-derive, #3322) and is
1125
+ * not recorded — replaying it too would publish the frame twice.
1126
+ *
1127
+ * Flight twin (the pending-branch carve-out): the reader is served the
1128
+ * node's committed, pre-flight value and now observes that flight — A15:
1129
+ * async work observed by a reader settles as one unit with the writes that
1130
+ * asked it — so it joins the transaction's reporters for the node. The
1131
+ * reporter the transaction recorded when the flight started may be gone (a
1132
+ * keyed remount disposed it, #3374); a completion check that found no live
1133
+ * reporter committed the writes ahead of the answer, tearing the new
1134
+ * reader's frame (`Count: 1` beside `Details: 0`). Joins an entry the
1135
+ * transaction already holds; a flight nobody had observed yet has none (the
1136
+ * reader is its first observer — a conditional that just revealed it, #3458)
1137
+ * and is notified up the reader's own queue chain under that transaction,
1138
+ * the one sanctioned registration site (INV-3): a collecting boundary above
1139
+ * the reader consumes it as it would any pending, an unboundaried reader
1140
+ * opens the entry — and the transaction, judged complete on its other
1141
+ * flights, revealed the inputs beside the reader's pre-flight value
1142
+ * otherwise (`Count: 1 | A: 1` beside `B: 0`). A staged signal or a settled
1143
+ * node registers nothing. Every reporter dies with its reader
1144
+ * (reporterBlocksSource: the read linked it as a dep). The node's own entry
1145
+ * is the only one that can matter: a chain's intermediate memo is re-pulled
1146
+ * by the read (updateIfNecessary's retry) and enters the transaction, so the
1147
+ * reader holds through the normal path; a node with its own flight that is
1148
+ * also pending on an upstream re-ask blocks through that flight until it
1149
+ * lands, and its landing re-runs the reader into the normal path.
1150
+ */
1151
+ /** The replay half of the stale-of-foreign clause (A15 / A26): a stale reader
1152
+ * served the committed value because `txn` holds what it read re-runs at
1153
+ * txn's commit, when the value it was denied becomes the frame — unless its
1154
+ * own last value already came from that transaction. One registration for
1155
+ * the node path (heldFromStale) and the store's backing paths, which have
1156
+ * no node to carry the hold (heldFromReader, the adoption hold view). */ function recordStaleReplay(e, t) {
1157
+ const n = t.Vt;
1158
+ if (n == null || currentTransition(n) !== e) e.Ht.add(t);
1159
+ }
1160
+
1161
+ /**
1162
+ * The ownership relation (DESIGN-CONSOLIDATION §6, ruled 2026-09-17): is
1163
+ * `hold` part of the running pass's world? A plain reader's world is the
1164
+ * transaction it runs under, through merges. A lane reader's world is its
1165
+ * lane AND the transition that owns the lane — the one asymmetry between a
1166
+ * lane and a separate transaction (a lane sees what lands from its parent as
1167
+ * its own; a separate transaction would wait for the parent to settle) —
1168
+ * see `ownsLane` in lanes.ts, built on this. One relation for the
1169
+ * stale-of-foreign clause (heldFromStale), the lane arm (readsHeldCommitted)
1170
+ * and the store's backing holds (foreignHold); `serve` has no lane arm of
1171
+ * its own, the lane's extra visibility lives here.
1172
+ */ function ownsHold(e) {
1173
+ return activeTransition !== null && currentTransition(e) === currentTransition(activeTransition);
1174
+ }
1175
+
1176
+ function heldFromStale(e, t) {
1177
+ const n = e.Te;
1178
+ if (n === null || ownsHold(n)) return false;
1179
+ const i = currentTransition(n);
1180
+ recordStaleReplay(i, t);
1181
+ const l = i.ot.get(e);
1182
+ if (l) l.add(t); else if (e.S & STATUS_PENDING) runInTransition(i, () => t.T.notify(t, STATUS_PENDING, STATUS_PENDING, e.o._));
1183
+ return true;
1184
+ }
1185
+
1186
+ /**
1187
+ * A tracked computation about to be served a live transaction's staged value
1188
+ * derives from that transaction's world, so it enters the transaction and
1189
+ * this pass's result is held with it (A29, #3408). The write side (`setSignal`)
1190
+ * and a stamped node's recompute already enter; a reader that only now
1191
+ * starts reading the held node — a conditional memo whose branch flipped —
1192
+ * was the gap: it published a value derived from the staged world into the
1193
+ * mainline frame. Not for a probe (`isPending(() => x())` observes, it does
1194
+ * not derive) and a no-op for the ambient batch (`_transition` null) or the
1195
+ * transaction already active.
1196
+ */
1197
+ /** The transaction a pass running OUTSIDE a flush was served a staged value
1198
+ * from (A29, creation-time form). Inside a flush the pass enters through
1199
+ * initTransition; outside one — a memo or effect created from mainline code
1200
+ * while a hold is live — entering would leave `activeTransition` and the
1201
+ * batch pointed at the transaction for the rest of the synchronous block,
1202
+ * so an unrelated write made after the mount was held with someone else's
1203
+ * action. The entry is the pass's alone: recompute stages the node into the
1204
+ * transaction (born held) and mainline is never touched. */ let stagedEntry = null;
1205
+
1206
+ function enterStagedRead(e, t = e.Te) {
1207
+ if (!t || t === activeTransition || pendingCheckActive) return;
1208
+ // A companion (the latest() shadow, the isPending() verdict signal) is the
1209
+ // engine's mirror of the flushed world — reading it, or being it, is an
1210
+ // observation, not a derivation from the hold: latest(x) never enters x's
1211
+ // transaction, and the shadow's own pass never enters either (it would
1212
+ // flip activeTransition under the reader that pulled it). (`el` is null for
1213
+ // a store backing served under a hold — no node, the transaction is the
1214
+ // fold's.)
1215
+ if (e?.o?.nn || context?.o?.nn) return;
1216
+ // Verdict machinery (GlobalQueue._verdictPull: companion creation and the
1217
+ // latest()/isPending() pulls — the latest() shadow is created before it is
1218
+ // marked optimistic, so the bit alone cannot tell) and optimistic nodes
1219
+ // (own lane posture, A31) read staged truth by design; they keep the
1220
+ // entering path.
1221
+ // (`context` is non-null here: every caller selected a value for a reader.)
1222
+ const n = context;
1223
+ if (activeTransition === null && !globalQueue.Sn) {
1224
+ // Verdict pulls are observations, not derivations: a latest() /
1225
+ // isPending() call from mainline must never enter a transaction (it
1226
+ // would capture the rest of the caller's synchronous block).
1227
+ if (GlobalQueue.On) return;
1228
+ if (n.ft & REACTIVE_RECOMPUTING_DEPS && !(n.C & CONFIG_OPTIMISTIC) && (stagedEntry === null || stagedEntry === t)) {
1229
+ stagedEntry = t;
1230
+ return;
1231
+ }
1232
+ }
1233
+ globalQueue.initTransition(t);
1234
+ }
1235
+
1236
+ /**
1237
+ * Rule 1 (value selection), the full arm: does this reader see a STAGED
1238
+ * node's COMMITTED value? One implementation of the rule the fast paths
1239
+ * (readNodeFast, read's fast block) carry as their trivial ternary and that
1240
+ * every slow site — read's tail, the store's backing selection, the lane and
1241
+ * verdict arms — used to restate by hand (docs/DESIGN-CONSOLIDATION.md, move 3b). In order:
1242
+ * - no reader at all (an untracked read) — the committed frame;
1243
+ * - a reader under an optimistic lane the engine says reads committed
1244
+ * (laneReadsCommitted: another lane's hold, #3460);
1245
+ * - nothing staged;
1246
+ * - a children-forbidden reader (createTrackedEffect / onSettled: the frame,
1247
+ * never the graph — A32);
1248
+ * - a stale reader (render effect) of a FOREIGN transaction's staged write —
1249
+ * committed, no entanglement (heldFromStale registers the replay; a node
1250
+ * born held has no committed frame to fall back to, `noCommitted`);
1251
+ * - A17 for HELD truth (#3164, CONFIG_HELD_TRUTH): staged confirming truth —
1252
+ * fold-staged onto an armed family, or entangle-stolen by an awaited
1253
+ * until() — is masked from ordinary readers until its transaction's
1254
+ * reveal, the retaining transaction's own speculative recomputes included
1255
+ * (partial override coverage would otherwise compose override + staged
1256
+ * truth into a state no timeline contains). Authoritative readers
1257
+ * (until()'s predicate) and latest() see the staged truth — the tunnel that
1258
+ * keeps the hold deadlock-free.
1259
+ * False means the reader derives from the staged value and enters its
1260
+ * transaction (enterStagedRead, A29).
1261
+ */ function readerSeesCommitted(e, t, n, i) {
1262
+ return !!(!t || currentOptimisticLane !== null && GlobalQueue.An(e, n, t) || e._e === NOT_PENDING || t.C & CONFIG_CHILDREN_FORBIDDEN || stale && !i && heldFromStale(e, t) || e.C & CONFIG_HELD_TRUTH && !latestReadActive && !(t.C & CONFIG_AUTHORITATIVE_READ));
1263
+ }
1264
+
1265
+ /** A28 — set when a node is staged (queuePendingNode) or a held node rewritten
1266
+ * (stashHeldRewrite) OUTSIDE a flush; cleared when the next flush begins. The
1267
+ * read sites test this one module boolean instead of `globalQueue._running`:
1268
+ * inside a flush it is false and the A28 arm costs nothing; outside, only a
1269
+ * tick with unflushed writes pays the staged-node check. */ let unflushedStaged = false;
1270
+
1271
+ function markUnflushedStaged() {
1272
+ unflushedStaged = true;
1273
+ }
1274
+
1275
+ /** A28 — a write becomes visible at flush. Outside a flush, a node holding an
1276
+ * AMBIENT staged value (no transaction stamp) was written since the last
1277
+ * flush: ambient staging commits at flush end, so nothing else leaves a node
1278
+ * in this state; a stamped value is the flushed held world, which A28 says
1279
+ * latest() serves. Inside a flush the rule does not apply (A28 (4): promoted
1280
+ * within the round). Structural — no marker on the write path. */ function unflushed(e) {
1281
+ return unflushedValue(e) !== NOT_PENDING;
1282
+ }
1283
+
1284
+ /** The value an unflushed node serves — the committed value for an ambient
1285
+ * write, the flushed staged value for a rewrite of a held node — or
1286
+ * NOT_PENDING when nothing is unflushed. Exempt: owned-write nodes (A28 (4):
1287
+ * a write issued inside a recompute is promoted at that recompute's end —
1288
+ * boundary and loading machinery, until()'s internals, signals declared for
1289
+ * in-computation writes) and engine companions (the isPending() verdict
1290
+ * signal, the latest() shadow: the system's own writes, made at the source's
1291
+ * write to mirror it, installing eagerly — A28, A8). */ function unflushedValue(e, t = e.Ae) {
1292
+ if (globalQueue.Sn || e._e === NOT_PENDING || e.C & CONFIG_PROMOTED || e.o?.nn) return NOT_PENDING;
1293
+ // Ambient, or adopted by a transaction before any flush carried the staging
1294
+ // (CONFIG_ADOPTED_UNFLUSHED): nothing flushed is staged — the committed
1295
+ // value answers (the caller's notion of committed: a store node's backing).
1296
+ // A held node: unflushed only if rewritten since the last flush (stash).
1297
+ if (e.Te === null || e.C & CONFIG_ADOPTED_UNFLUSHED) return t;
1298
+ return e.o === null ? NOT_PENDING : e.o.Bt;
1299
+ }
1300
+
1301
+ /** Held nodes rewritten since the last flush (setSignal); the flush clears
1302
+ * their stash — from then on latest() answers with the rewrite. */ const unflushedRewrites = [];
1303
+
1304
+ /** Nodes written inside a creation-time recompute (CONFIG_PROMOTED). */ const promotedWrites = [];
1305
+
1306
+ /** A28 (5): an optimistic write becomes the ACTIVE override at the flush that
1307
+ * carries it. `_overrideTime` is stamped with `clock` at the write and `clock`
1308
+ * advances after every flush, so "this tick, outside a flush" is unflushed. */ function unflushedOverride(e) {
1309
+ // Companions are optimistic signals written by the engine (see unflushed).
1310
+ return !globalQueue.Sn && e.o?.Qt === clock && !e.o?.nn;
1311
+ }
1312
+
1313
+ /** Active optimistic override on an armed node (an armed slot idles at
1314
+ * NOT_PENDING; undefined = unarmed plain node). The writer's own channels —
1315
+ * the draft, `in`/keys inside the setter — compose on this regardless of
1316
+ * flush state. */ function hasActiveOverride(e) {
1317
+ const t = e.o;
1318
+ return t !== null && t.Ne !== undefined && t.Ne !== NOT_PENDING;
1319
+ }
1320
+
1321
+ /** The override a READER sees: installed, and carried by a flush (A28 (5) —
1322
+ * an optimistic write is a write; until its flush no reader sees it). One
1323
+ * implementation for read()'s override arm, the verdict channels
1324
+ * (latestRead, computePendingState) and the store's selection
1325
+ * (docs/DESIGN-CONSOLIDATION.md, move 3b). */ function visibleOverride(e) {
1326
+ return hasActiveOverride(e) && !unflushedOverride(e);
1327
+ }
1328
+
1329
+ /** A derivation served the committed value because of an unflushed write
1330
+ * (A28) must run again in the flush that carries it — the late-linker case
1331
+ * (#3337's reason to defer the walk): it linked after the write walked. */ function markLateLinker(e) {
1332
+ // The pass's own tail re-enqueues on this latch (recompute's finally) —
1333
+ // a direct enqueue here would be wiped by the pass's flag reset.
1334
+ e.ft |= REACTIVE_MISSED_WAKE;
1335
+ return true;
1336
+ }
1337
+
1338
+ /** Companion-bearing nodes written outside a flush (setSignal); the flush
1339
+ * that carries their writes re-syncs their companions (A28). */ const unflushedCompanions = [];
1340
+
1341
+ function resyncUnflushedCompanions() {
1342
+ unflushedStaged = false;
1343
+ // Length-guarded: the common flush has nothing here, and must allocate nothing.
1344
+ // Length-guarded: the common flush has nothing here and allocates nothing.
1345
+ if (unflushedRewrites.length !== 0) {
1346
+ for (const e of unflushedRewrites) e.o.Bt = NOT_PENDING;
1347
+ unflushedRewrites.length = 0;
1348
+ }
1349
+ if (promotedWrites.length !== 0) {
1350
+ for (const e of promotedWrites) e.C &= ~CONFIG_PROMOTED;
1351
+ promotedWrites.length = 0;
1352
+ }
1353
+ if (unflushedCompanions.length !== 0) {
1354
+ for (const e of unflushedCompanions) GlobalQueue.De(e, e._e !== NOT_PENDING ? e._e : e.Ae);
1355
+ unflushedCompanions.length = 0;
1356
+ }
1357
+ }
1358
+
1359
+ function readNodeFast(e) {
1360
+ if (latestReadActive || pendingCheckActive || e.ht || e.ne || e.o?.Ne !== undefined || e.o?.Gt !== undefined || activeTransition !== null || currentOptimisticLane !== null || snapshotCaptureActive ||
1361
+ // A28: a staged node read outside a flush may serve its committed value;
1362
+ // that arm lives on the slow path so this body stays inlinable.
1363
+ unflushedStaged && e._e !== NOT_PENDING || false) return READ_SLOW;
1364
+ let t = context;
1365
+ if (t?.cn) t = t.fn;
1366
+ if (t && tracking) link(e, t);
1367
+ // Children-forbidden readers (createTrackedEffect / onSettled callbacks) get
1368
+ // committed visibility: like the effect half of createEffect and event
1369
+ // handlers, effect-phase code never observes its own unsettled write — the
1370
+ // write lands in the same flush's continuation (#3006).
1371
+ // A stale reader (render effect) recomputing with no transaction active is
1372
+ // mainline: a write staged by a live transaction (`_transition` stamped —
1373
+ // ambient staging never is) stays masked until that transaction's reveal,
1374
+ // the same rule the slow path applies (#3322). Without it a zombie
1375
+ // recompute, or a commit-time re-derive of a contested effect, published
1376
+ // another transaction's uncommitted value.
1377
+ return !t || e._e === NOT_PENDING || t.C & CONFIG_CHILDREN_FORBIDDEN || stale && heldFromStale(e, t) ? e.Ae : (enterStagedRead(e),
1378
+ e._e);
1379
+ }
1380
+
1381
+ function read(e) {
1382
+ // Handle latest() mode: read from _latestValueComputed
1383
+ // Checked before isPending so that isPending(() => latest(x)) checks
1384
+ // the _pendingSignal of _latestValueComputed (async in flight) rather
1385
+ // than the original node (which stays "pending" while held in a transition).
1386
+ if (latestReadActive) return GlobalQueue.Cn(e);
1387
+ let t = context;
1388
+ if (t?.cn) t = t.fn;
1389
+ const n = e;
1390
+ const i = e.ne;
1391
+ const l = i || e;
1392
+ // Handle isPending() mode: collect pending state while preserving normal read semantics.
1393
+ // Probe mode is suspended while preparing the node so nested reads during a
1394
+ // recompute don't collect into the probe.
1395
+ if (pendingCheckActive) {
1396
+ GlobalQueue.pn(e, t, l, i);
1397
+ } else if (typeof n.ht === "function") {
1398
+ prepareComputed(e, false);
1399
+ }
1400
+ if (!n.ht && l === e && e.o?.Ne === undefined && e.o?.Gt === undefined && activeTransition === null && currentOptimisticLane === null && !snapshotCaptureActive && (!unflushedStaged || e._e === NOT_PENDING) && // A28, see readNodeFast
1401
+ true) {
1402
+ if (t && tracking) link(e, t);
1403
+ // Committed visibility for children-forbidden readers and for stale
1404
+ // readers of a foreign transaction's staged write — see readNodeFast.
1405
+ return !t || e._e === NOT_PENDING || t.C & CONFIG_CHILDREN_FORBIDDEN || stale && heldFromStale(e, t) ? e.Ae : (enterStagedRead(e),
1406
+ e._e);
1407
+ }
1408
+ if (t && tracking) {
1409
+ link(e, t, pendingCheckActive);
1410
+ if (l.ht) {
1411
+ const n = queueFor(e);
1412
+ if (l.Rt >= n.Ct) {
1413
+ markNode(t);
1414
+ markHeap(n);
1415
+ updateIfNecessary(l);
1416
+ }
1417
+ // Fresh-pull readers (awaitable refresh's waiter) recompute a dirty
1418
+ // source inline even when the height gate defers to the flush: the
1419
+ // waiter must park on the re-ask's window (or serve its sync answer),
1420
+ // never read the PRE-re-ask value as settled. Self-guarded: a clean
1421
+ // node no-ops and updateIfNecessary refuses disposed nodes (#2983) —
1422
+ // a dead target serves its last value, which is already quiescent.
1423
+ else if (t.C & CONFIG_FRESH_READ) updateIfNecessary(l);
1424
+ const i = l.Rt;
1425
+ // parent check is shallow, might need to be recursive
1426
+ if (i >= t.Rt && e._parent !== t) {
1427
+ t.Rt = i + 1;
1428
+ }
1429
+ }
1430
+ }
1431
+ if (l.S & STATUS_PENDING) {
1432
+ // A reader landing on a pending node throws — the reveal that discovered
1433
+ // the flight holds on it (A15: observed async settles as one unit) — with
1434
+ // one carve-out: a stale (render) reader of a node pending in some OTHER
1435
+ // transaction keeps showing the node's committed value, no entanglement
1436
+ // (parallel transactions; the reader is recorded for that transaction's
1437
+ // commit replay, `heldFromStale`). The carve-out is sound only while the
1438
+ // committed value is coherent with the visible frame, i.e. while the
1439
+ // flight's inputs are themselves unpublished: the stamp alone does not
1440
+ // say so (it is pending-node bookkeeping), so it is refused when the
1441
+ // inputs are on screen — committed by a batch that left the flight in
1442
+ // the air (CONFIG_INPUTS_PUBLISHED, #3305) or revealed through a lane
1443
+ // (optimistic / latest, #3334) — and the reader holds instead. An
1444
+ // UNINITIALIZED node has no committed value to show and holds too
1445
+ // (firewall-backed store reads always did; plain memos since the #3043
1446
+ // port): falling through served `undefined` as if settled and stranded
1447
+ // the reader outside both transactions, so it never re-ran.
1448
+ if (t && !(stale && !(l.S & STATUS_UNINITIALIZED) && !(l.C & CONFIG_INPUTS_PUBLISHED) && !(l.C & CONFIG_HAS_LANE && GlobalQueue.Rn(l)) && heldFromStale(l, t))) {
1449
+ // Per-lane suspension lives with the engine (a non-null lane implies it
1450
+ // is installed): under a lane, only same-lane pending async without an
1451
+ // active override throws — plus uninitialized sources regardless of
1452
+ // lane (#3276); that check rides laneSuspends so floor bundles don't
1453
+ // pay for it.
1454
+ if (currentOptimisticLane === null || GlobalQueue.Gn(l)) {
1455
+ // An untracked read of a pending node still re-runs its reader when
1456
+ // the node settles — unless nobody is reading (`spectating`, #3528)
1457
+ // or the reader is the node itself.
1458
+ if (!tracking && !spectating && e !== t) link(e, t);
1459
+ throw l.o?._;
1460
+ }
1461
+ } else if (!t && l.S & STATUS_UNINITIALIZED) {
1462
+ throw l.o?._;
1463
+ }
1464
+ }
1465
+ // `owner` is the computed itself, or the firewall behind a store node —
1466
+ // firewall-backed reads follow the same rules (memo parity, #2897 ruling):
1467
+ // an errored derive throws for every late reader instead of silently
1468
+ // serving node values (the seed, or last-good data after a failed refetch).
1469
+ if (l.ht && l.S & STATUS_ERROR) {
1470
+ // Only a genuine reactive re-read may retry an errored async source:
1471
+ // - tracking: owned/tracked scope only (never events / `untrack` / effect side-effect phase)
1472
+ // - !pendingCheckActive: an `isPending` probe observes the error, never refetches
1473
+ // - owner._time < clock: only on a later cycle than the one the error was found
1474
+ if (tracking && !pendingCheckActive && l.fe < clock) {
1475
+ recompute(l);
1476
+ return read(e);
1477
+ } else throw l.o?._;
1478
+ }
1479
+ if (snapshotCaptureActive && t && t.C & CONFIG_IN_SNAPSHOT_SCOPE) {
1480
+ const n = e.o?.Gt;
1481
+ if (n !== undefined) {
1482
+ const i = n === NO_SNAPSHOT ? undefined : n;
1483
+ const l = e._e !== NOT_PENDING ? e._e : e.Ae;
1484
+ if (l !== i) t.ft |= REACTIVE_SNAPSHOT_STALE;
1485
+ return i;
1486
+ }
1487
+ }
1488
+ const u = serve(e, t, l, e.Ae);
1489
+ if (!t && l === e && typeof n.ht === "function" && e.C & CONFIG_AUTO_DISPOSE && !(l.S & STATUS_PENDING) && !e.u &&
1490
+ // An untracked read served a visible override returned before this
1491
+ // sweep registration when the arm was inline; keep that.
1492
+ !visibleOverride(e)) {
1493
+ // Deferred, not inline (#3078): an inline unobserved() here made untracked
1494
+ // reads destructive — dispose on this read, full revival recompute on the
1495
+ // next — so consecutive reads could answer differently with no write in
1496
+ // between (the revival samples the ambient transition/lane context).
1497
+ // The sweep at flush finalization re-validates and reclaims; schedule()
1498
+ // guarantees that flush happens even if nothing else is queued.
1499
+ dormantNodes.add(e);
1500
+ schedule();
1501
+ }
1502
+ return u;
1503
+ }
1504
+
1505
+ /**
1506
+ * Rule 1, the one slow implementation (DESIGN-CONSOLIDATION move 3b, step
1507
+ * 6c): the value a reader `c` (null = untracked, no pass) is served from
1508
+ * `el`, whose committed value is `committed` — the node's own `_value` for
1509
+ * a signal or memo, the BACKING for a store property node (single-home rule,
1510
+ * O6: committed truth lives in the backing and a node's `_value` is never
1511
+ * served for one). Called by read()'s slow tail and by the store's untracked
1512
+ * node path (nodeValue); the fast paths (readNodeFast, read's fast block)
1513
+ * keep their trivial ternary by design (perf, see the doc). Arms, in order:
1514
+ * - the override (A17), routed through the engine for a tracked reader under
1515
+ * a lane or a supersession (A18), an authoritative reader marked instead;
1516
+ * - the lane entanglement gate (committed, recorded for replay);
1517
+ * - a node born held has nothing for an untracked reader (A19 exception 1);
1518
+ * - an unflushed write serves committed and re-runs the reader in the
1519
+ * carrying flush (A28);
1520
+ * - readerSeesCommitted, else the staged value and the transaction (A29).
1521
+ */ function serve(e, t, n, i) {
1522
+ if (hasActiveOverride(e)) {
1523
+ // A17: the override IS the value for every reader — except an authoritative
1524
+ // reader (until()'s predicate carries CONFIG_AUTHORITATIVE_READ): it must
1525
+ // observe independently-arriving truth, and serving it the caller's own
1526
+ // tentative write would trivially satisfy the predicate. The bit is checked
1527
+ // on the reading computation itself, so a shared computed the predicate
1528
+ // pulls recomputes as ITSELF (context = the memo, no bit) under the normal
1529
+ // view. Fall through to normal value selection (staged `_pendingValue` is
1530
+ // authoritative — optimism never lives there); the sticky mark makes the
1531
+ // A17-silent "landing equals override" paths notify this node's subs so
1532
+ // the reader re-runs when truth arrives.
1533
+ // A28 (5): an optimistic write written this tick, outside a flush, is not
1534
+ // yet the active override — fall through to the normal selection (the
1535
+ // authoritative mark below still applies: until() must wake on landing).
1536
+ if (!(t && t.C & CONFIG_AUTHORITATIVE_READ) && !unflushedOverride(e)) {
1537
+ // A tracked read of an override is the engine's selection (a lane or a
1538
+ // supersession implies the engine): a render effect OFF the override's
1539
+ // held lane sees the committed value (#3460, lanes mirror transitions);
1540
+ // a node whose own source answered with a DIFFERENT value hands a
1541
+ // tracked reader the staged truth (A18 supersession, #3331). Untracked
1542
+ // reads display the override.
1543
+ if (t && e.C & (CONFIG_HAS_LANE | CONFIG_OVERRIDE_SUPERSEDED)) return GlobalQueue.Dn(e, t);
1544
+ return unwrapOverride(e.o?.Ne);
1545
+ }
1546
+ e.C |= CONFIG_AUTHORITATIVE_OBSERVED;
1547
+ }
1548
+ // Entanglement gate: a reader recomputing under an optimistic lane that reads
1549
+ // a pending mid-transition write sees the committed value. Projection-store
1550
+ // manual writes use the firewall's manual-write flag to opt into this path.
1551
+ // Async drivers are not under an optimistic lane and so bypass this, reading
1552
+ // _pendingValue for correct fetching. The sub is recorded for replay at commit
1553
+ // so it re-runs with the new committed view. (Gate details live with the
1554
+ // engine — a non-null lane implies it is installed.)
1555
+ if (currentOptimisticLane !== null && activeTransition !== null && t !== null && GlobalQueue.hn(e, n, t)) {
1556
+ return i;
1557
+ }
1558
+ // In optimistic lane context, return _value for optimistic/lane-assigned signals
1559
+ // and for regular signals in stale mode (render effects). Non-stale readers (user
1560
+ // effects) see _pendingValue so that latest() and direct reads stay consistent.
1561
+ // (The lane-context clause lives with the engine.) Children-forbidden readers
1562
+ // (createTrackedEffect / onSettled callbacks) get committed visibility — see
1563
+ // readNodeFast (#3006).
1564
+ // A node born held (recompute) has a staged value and no committed one: a
1565
+ // stale reader cannot fall back to the committed frame, so it takes the
1566
+ // staged value and enters like a tracked reader (A29); an untracked reader
1567
+ // has nothing to serve and holds (A19 exception 1).
1568
+ const l = e._e !== NOT_PENDING && (e.S & STATUS_UNINITIALIZED) !== 0;
1569
+ if (l && !t) throw new NotReadyError(null);
1570
+ const u = t && unflushedStaged ? unflushedValue(e, i) : NOT_PENDING;
1571
+ if (u !== NOT_PENDING) {
1572
+ markLateLinker(t);
1573
+ if (pendingCheckActive) GlobalQueue.Pn(e, u);
1574
+ return u;
1575
+ }
1576
+ const o = readerSeesCommitted(e, t, n, l) ? i : (enterStagedRead(e), e._e);
1577
+ // Record that this isPending() probe observed the fresh pending value, so
1578
+ // the probe doesn't pair "pending" with the new value (#2831).
1579
+ if (pendingCheckActive) GlobalQueue.Pn(e, o);
1580
+ return o;
1581
+ }
1582
+
1583
+ /** A28 — a rewrite of a HELD node outside a flush keeps the staged value the
1584
+ * last flush left, for latest()/verdicts, until the next flush carries it
1585
+ * (stash, cleared at that flush). Cold: only stamped nodes reach here. */ function stashHeldRewrite(e) {
1586
+ if (globalQueue.Sn) return;
1587
+ const t = ext(e);
1588
+ if (t.Bt === NOT_PENDING) {
1589
+ t.Bt = e._e;
1590
+ unflushedRewrites.push(e);
1591
+ unflushedStaged = true;
1592
+ }
1593
+ }
1594
+
1595
+ /** A28 (4) — written inside a recompute that runs OUTSIDE a flush (a
1596
+ * creation-time compute): promoted at that pass's end, visible to the rest of
1597
+ * the block. Cold: only contextual writes reach here. */ function notePromotedWrite(e) {
1598
+ if (globalQueue.Sn || e.C & CONFIG_PROMOTED) return;
1599
+ e.C |= CONFIG_PROMOTED;
1600
+ promotedWrites.push(e);
1601
+ }
1602
+
1603
+ function setSignal(e, t) {
1604
+ // A write to a held node is a second proposal on a contested node (A34, #3494):
1605
+ // the writer's tick reveals with the hold, the same value or another. Inside
1606
+ // a flush the round enters now; from mainline the entry waits for the next
1607
+ // flush's start (batchJoins) — entering here left activeTransition set for
1608
+ // the rest of the caller's block, so a memo created after the write became
1609
+ // the transaction's instead of mainline's (A28, A29). Before the equality
1610
+ // gate below: repeating the held value proposes it too — and that repeat
1611
+ // leaves through the gate, so the join schedules its own flush here; left
1612
+ // for the next flush to find, it adopted an unrelated tick (#3519 review).
1613
+ if (e.Te && activeTransition !== e.Te) {
1614
+ if (globalQueue.Sn) globalQueue.initTransition(e.Te); else {
1615
+ batchJoins.push(e.Te);
1616
+ // dupes: a bare return in initTransition
1617
+ schedule();
1618
+ }
1619
+ }
1620
+ // The optimistic write path lives with the engine: only optimisticSignal /
1621
+ // optimisticComputed callers and optimistic store nodes carry an
1622
+ // _overrideValue slot (flagged by CONFIG_OPTIMISTIC — a masked read of the
1623
+ // always-present config instead of a missing-property probe), and every
1624
+ // module that installs one installs the engine first.
1625
+ if (e.C & CONFIG_OPTIMISTIC) {
1626
+ if (!projectionWriteActive) return GlobalQueue.mn(e, t);
1627
+ // An authoritative store landing on an override-covered node: the store
1628
+ // twin of asyncWrite's override branch, decided by the engine (#3331).
1629
+ const n = e.o?.Ne;
1630
+ if (n !== undefined && n !== NOT_PENDING) return GlobalQueue.Fn(e, t);
1631
+ }
1632
+ const n = e._e === NOT_PENDING ? e.Ae : e._e;
1633
+ if (typeof t === "function") t = t(n);
1634
+ // Uninitialized check first: the first commit has no previous value, so the
1635
+ // user comparator must not run against `undefined` (matches recompute).
1636
+ const i = !!(e.S & STATUS_UNINITIALIZED) || !e.Re || !e.Re(n, t);
1637
+ if (!i) return t;
1638
+ // Attribution hook: this committed write is where a re-run chain begins.
1639
+ if (attrHooks !== null) attrHooks.write(e, n, t);
1640
+ const l = e._e !== NOT_PENDING;
1641
+ if (!l) queuePendingNode(e);
1642
+ // A28 arms, gated on the loads the write already pays for (a plain ambient
1643
+ // rewrite outside a flush — the write-loop shape — costs `_transition` and
1644
+ // `context` here and nothing else; the arms themselves are cold helpers so
1645
+ // setSignal stays within every setter's inlining budget, ~300 B bytecode).
1646
+ else if (e.Te !== null) stashHeldRewrite(e);
1647
+ e._e = t;
1648
+ if (context !== null) notePromotedWrite(e);
1649
+ // syncCompanions only pokes _pendingSignal/_latestValueComputed — with
1650
+ // neither companion present the call is a guaranteed no-op (companions are
1651
+ // only ever created, never removed, and creating one installs the hook and
1652
+ // sets CONFIG_HAS_COMPANIONS — one masked read replaces two optional-field
1653
+ // probes on every write).
1654
+ if (e.C & CONFIG_HAS_COMPANIONS && GlobalQueue.De !== null) {
1655
+ GlobalQueue.De(e, t);
1656
+ // A28 (2): the verdict computed here is the PRE-flush one (an unflushed
1657
+ // write is not pending); the flush that carries the write re-syncs so
1658
+ // the companions mirror the flushed world. Only companion nodes pay.
1659
+ if (!globalQueue.Sn) unflushedCompanions.push(e);
1660
+ }
1661
+ // _time is a computed-only slot (§12e): writing it on a signal would fork
1662
+ // the lean shape. Every read site is computed-typed.
1663
+ if (e.ht !== undefined) e.fe = clock;
1664
+ // Staged-rewrite fast path (§12d): a re-write to a node whose subscribers
1665
+ // were already walked — and where nothing has recomputed or linked since
1666
+ // (epoch) — re-stages the value and stops. The walk is idempotent (subs
1667
+ // marked, heap entries flag-guarded, effects queued once); lane and reask
1668
+ // contexts change what a walk MEANS, so they always walk.
1669
+ if (l && e.Zt === notifyEpoch && currentOptimisticLane === null && !reaskArmed) return t;
1670
+ insertSubs(e);
1671
+ schedule();
1672
+ return t;
1673
+ }
1674
+
1675
+ /**
1676
+ * Suppresses automatic recomputation of `el` until the scheduler drains. Used
1677
+ * when a manual write should win over dependency changes queued in the same
1678
+ * tick. The MANUAL_WRITE flag is cleared by the pending-node drain; projection
1679
+ * computeds don't commit values, but they still need the same end-of-tick
1680
+ * cleanup point.
1681
+ */ function suppressComputedRecompute(e) {
1682
+ deleteFromHeap(e, queueFor(e));
1683
+ if (!(e.ft & REACTIVE_MANUAL_WRITE) && e._e === NOT_PENDING) {
1684
+ queuePendingNode(e);
1685
+ schedule();
1686
+ }
1687
+ e.ft = e.ft & -4 | REACTIVE_MANUAL_WRITE;
1688
+ e.gn = clock;
1689
+ }
1690
+
1691
+ /**
1692
+ * User-facing setter for the memo form of `createSignal(fn)`. Behaves like
1693
+ * `setSignal`, but also cancels any pending recompute of the memo so the
1694
+ * manual value wins over a value that would otherwise be produced by an
1695
+ * upstream change in the same tick.
1696
+ */ function setMemo(e, t) {
1697
+ const n = setSignal(e, t);
1698
+ suppressComputedRecompute(e);
1699
+ return n;
1700
+ }
1701
+
1702
+ /**
1703
+ * Executes `fn` with the given `owner` set as the current owner. Any reactive
1704
+ * primitives (`createSignal`, `createMemo`, `createEffect`, `onCleanup`,
1705
+ * `cleanup`, etc.) created inside `fn` are attached to that owner, so they
1706
+ * are disposed when the owner is disposed.
1707
+ *
1708
+ * The classic pattern: capture the current owner with `getOwner()` inside a
1709
+ * component, then re-enter it from a callback (event handler, async resolve,
1710
+ * setTimeout) so disposables created in the callback get cleaned up with the
1711
+ * component.
1712
+ *
1713
+ * @example
1714
+ * ```ts
1715
+ * function delayed<T>(ms: number, fn: () => T) {
1716
+ * const owner = getOwner();
1717
+ * setTimeout(() => runWithOwner(owner, fn), ms);
1718
+ * }
1719
+ * ```
1720
+ */ function runWithOwner(e, t) {
1721
+ const n = context;
1722
+ const i = tracking;
1723
+ context = e;
1724
+ tracking = false;
1725
+ try {
1726
+ return t();
1727
+ } finally {
1728
+ context = n;
1729
+ tracking = i;
1730
+ }
1731
+ }
1732
+
1733
+ function staleValues(e, t = true) {
1734
+ const n = stale;
1735
+ stale = t;
1736
+ try {
1737
+ return e();
1738
+ } finally {
1739
+ stale = n;
1740
+ }
1741
+ }
1742
+
1743
+ /**
1744
+ * Core marking half of `refresh()` (the public wrapper lives in signals.ts —
1745
+ * it validates the target, marks through here, then builds the quiescence
1746
+ * promise on the resolve()/until() effect machinery). Flags the node's next
1747
+ * recompute as a quiet re-ask and schedules it; no-ops for non-derived or
1748
+ * disposed targets and for same-tick manual writes.
1749
+ */ function markRefresh(e) {
1750
+ if (typeof e.ht === "function" && !(e.ft & REACTIVE_DISPOSED)) {
1751
+ if (e.ft & REACTIVE_MANUAL_WRITE) {
1752
+ // A manual write in the CURRENT tick wins over the refresh (#2692).
1753
+ // A mask stamped in an earlier tick only survives because a
1754
+ // transaction (action) is holding the pending drain open; there the
1755
+ // refresh is a later, explicit re-ask and lifts the mask — otherwise
1756
+ // any setStore early in an action silently swallows every refresh()
1757
+ // for the rest of the transaction (#3026).
1758
+ if (e.gn === clock) return;
1759
+ e.ft &= ~REACTIVE_MANUAL_WRITE;
1760
+ // The lift falls through to the re-ask classification below. The held
1761
+ // write's value change already rides the transaction; the refetch it
1762
+ // asks for is the same question with unchanged inputs. Skipping the
1763
+ // mark here classified that refetch as a NEW question, which pends
1764
+ // every leaf (3.1) — an action doing setStore + yield + refresh(store)
1765
+ // lit up every sibling row, and affects() could not narrow it (a mark
1766
+ // only turns pending on). Same-question motion stays silent (3.4);
1767
+ // the written slot and any declared mark carry the pending instead.
1768
+ }
1769
+ // A refresh with no value-change dirt already queued is a re-ask of the
1770
+ // same question: mark it so the recompute classifies any resulting
1771
+ // pending window as quiet (not pending). If the node is already dirty
1772
+ // from a real input change, the question changed — don't mark.
1773
+ // REACTIVE_IN_HEAP counts as dirt: insertSubs schedules subscribers by
1774
+ // heap insertion alone (no DIRTY/CHECK flag), so a same-batch value
1775
+ // change followed by refresh() must not be laundered into a quiet re-ask.
1776
+ if (!(e.ft & (REACTIVE_DIRTY | REACTIVE_CHECK | REACTIVE_IN_HEAP))) {
1777
+ e.ft |= REACTIVE_REASK;
1778
+ armReaskClear();
1779
+ }
1780
+ e.ft = e.ft & ~REACTIVE_CHECK | REACTIVE_DIRTY;
1781
+ // A refresh() self-invalidation is a root cause too — the target's next
1782
+ // run has no changed dep to point at, so it points here instead.
1783
+ if (attrHooks !== null) attrHooks.refreshed(e);
1784
+ insertIntoHeap(e, queueFor(e));
1785
+ schedule();
1786
+ }
1787
+ }
1788
+
1789
+ export { READ_SLOW, clearSnapshots, computed, context, createEffectNode, currentOptimisticLane, effectStatusNotify, enterStagedRead, ext, hasActiveOverride, installAuthoritativeRead, isEqual, latestReadActive, markLateLinker, markRefresh, markSnapshotScope, markUnflushedStaged, notifyAuthoritativeObservers, optimisticComputed, optimisticSignal, ownsHold, pendingCheckActive, prepareComputed, read, readNodeFast, readerSeesCommitted, recompute, recordStaleReplay, releaseSnapshotScope, resyncUnflushedCompanions, runWithOwner, serve, setContextInternal, setEffectStatusNotify, setLatestReadActive, setMemo, setPendingCheckActive, setSignal, setSlotUnobserved, setSnapshotCapture, signal, slotSignal, slotUnobservedHook, snapshotCaptureActive, snapshotSources, spectate, spectating, stale, staleValues, statusNotifierOf, suppressComputedRecompute, tracking, unflushed, unflushedCompanions, unflushedOverride, unflushedStaged, unflushedValue, unlinkFirewallChild, untrack, visibleOverride };