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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +1 -1
  2. package/dist/dev-shared.js +7138 -0
  3. package/dist/dev.attribution.js +3307 -0
  4. package/dist/dev.js +8076 -6692
  5. package/dist/observe/affects.js +129 -0
  6. package/dist/observe/attribution.js +7 -0
  7. package/dist/observe/boundaries.js +793 -0
  8. package/dist/observe/core/action.js +177 -0
  9. package/dist/observe/core/async.js +849 -0
  10. package/dist/observe/core/attribution-costs.js +66 -0
  11. package/dist/observe/core/attribution-feedback.js +280 -0
  12. package/dist/observe/core/attribution-hooks.js +83 -0
  13. package/dist/observe/core/attribution-queries.js +43 -0
  14. package/dist/observe/core/attribution.js +2904 -0
  15. package/dist/observe/core/constants.js +283 -0
  16. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  17. package/dist/observe/core/core.js +1999 -0
  18. package/dist/observe/core/dev.js +343 -0
  19. package/dist/observe/core/effect.js +200 -0
  20. package/dist/observe/core/error-hooks.js +71 -0
  21. package/dist/observe/core/error.js +80 -0
  22. package/dist/observe/core/external.js +98 -0
  23. package/dist/observe/core/graph.js +155 -0
  24. package/dist/observe/core/heap.js +147 -0
  25. package/dist/observe/core/invariants.js +45 -0
  26. package/dist/observe/core/lanes.js +205 -0
  27. package/dist/observe/core/optimistic.js +627 -0
  28. package/dist/observe/core/owner.js +353 -0
  29. package/dist/observe/core/scheduler.js +1547 -0
  30. package/dist/observe/core/verdict.js +674 -0
  31. package/dist/observe/index.js +59 -0
  32. package/dist/observe/map.js +484 -0
  33. package/dist/observe/signals.js +731 -0
  34. package/dist/observe/store/index.js +44 -0
  35. package/dist/observe/store/next/optimistic.js +717 -0
  36. package/dist/observe/store/next/projection.js +266 -0
  37. package/dist/observe/store/next/reconcile.js +375 -0
  38. package/dist/observe/store/next/store.js +2480 -0
  39. package/dist/observe/store/next/target.js +51 -0
  40. package/dist/observe/store/store.js +331 -0
  41. package/dist/observe/store/storePath.js +103 -0
  42. package/dist/observe/store/utils.js +1070 -0
  43. package/dist/prod/affects.js +10 -9
  44. package/dist/prod/attribution.js +45 -0
  45. package/dist/prod/boundaries.js +388 -178
  46. package/dist/prod/core/action.js +65 -37
  47. package/dist/prod/core/async.js +477 -208
  48. package/dist/prod/core/attribution-hooks.js +3 -0
  49. package/dist/prod/core/constants.js +186 -1
  50. package/dist/prod/core/context.js +10 -16
  51. package/dist/prod/core/core.js +1556 -415
  52. package/dist/prod/core/dev.js +18 -1
  53. package/dist/prod/core/effect.js +119 -79
  54. package/dist/prod/core/error-hooks.js +71 -0
  55. package/dist/prod/core/error.js +13 -1
  56. package/dist/prod/core/external.js +4 -4
  57. package/dist/prod/core/graph.js +105 -54
  58. package/dist/prod/core/heap.js +72 -65
  59. package/dist/prod/core/invariants.js +3 -2
  60. package/dist/prod/core/lanes.js +117 -52
  61. package/dist/prod/core/optimistic.js +474 -103
  62. package/dist/prod/core/owner.js +131 -84
  63. package/dist/prod/core/scheduler.js +1013 -248
  64. package/dist/prod/core/verdict.js +418 -113
  65. package/dist/prod/index.js +25 -13
  66. package/dist/prod/map.js +314 -151
  67. package/dist/prod/signals.js +382 -32
  68. package/dist/prod/store/index.js +38 -0
  69. package/dist/prod/store/next/optimistic.js +710 -0
  70. package/dist/prod/store/next/projection.js +257 -0
  71. package/dist/prod/store/next/reconcile.js +373 -0
  72. package/dist/prod/store/next/store.js +2356 -0
  73. package/dist/prod/store/next/target.js +51 -0
  74. package/dist/prod/store/store.js +129 -881
  75. package/dist/prod/store/utils.js +982 -242
  76. package/dist/types/attribution.d.ts +19 -0
  77. package/dist/types/attribution.prod.d.ts +22 -0
  78. package/dist/types/boundaries.d.ts +78 -5
  79. package/dist/types/core/action.d.ts +12 -5
  80. package/dist/types/core/async.d.ts +3 -1
  81. package/dist/types/core/attribution-costs.d.ts +35 -0
  82. package/dist/types/core/attribution-feedback.d.ts +133 -0
  83. package/dist/types/core/attribution-hooks.d.ts +304 -0
  84. package/dist/types/core/attribution-queries.d.ts +24 -0
  85. package/dist/types/core/attribution.d.ts +892 -0
  86. package/dist/types/core/constants.d.ts +179 -0
  87. package/dist/types/core/core.d.ts +305 -23
  88. package/dist/types/core/dev.d.ts +421 -8
  89. package/dist/types/core/effect.d.ts +8 -1
  90. package/dist/types/core/error-hooks.d.ts +71 -0
  91. package/dist/types/core/error.d.ts +9 -0
  92. package/dist/types/core/graph.d.ts +23 -0
  93. package/dist/types/core/heap.d.ts +5 -3
  94. package/dist/types/core/index.d.ts +6 -3
  95. package/dist/types/core/invariants.d.ts +5 -1
  96. package/dist/types/core/lanes.d.ts +51 -19
  97. package/dist/types/core/owner.d.ts +15 -3
  98. package/dist/types/core/scheduler.d.ts +252 -3
  99. package/dist/types/core/types.d.ts +124 -41
  100. package/dist/types/index.d.ts +18 -5
  101. package/dist/types/map.d.ts +2 -0
  102. package/dist/types/signals.d.ts +164 -13
  103. package/dist/types/store/index.d.ts +16 -5
  104. package/dist/types/store/next/optimistic.d.ts +25 -0
  105. package/dist/types/store/next/projection.d.ts +27 -0
  106. package/dist/types/store/next/reconcile.d.ts +10 -0
  107. package/dist/types/store/next/store.d.ts +143 -0
  108. package/dist/types/store/next/target.d.ts +196 -0
  109. package/dist/types/store/store.d.ts +46 -112
  110. package/dist/types/store/utils.d.ts +188 -40
  111. package/package.json +32 -26
  112. package/dist/node.cjs +0 -7938
  113. package/dist/prod/store/optimistic.js +0 -217
  114. package/dist/prod/store/projection.js +0 -231
  115. package/dist/prod/store/reconcile.js +0 -707
  116. package/dist/types/store/optimistic.d.ts +0 -45
  117. package/dist/types/store/projection.d.ts +0 -70
  118. package/dist/types/store/reconcile.d.ts +0 -46
  119. package/dist/types-cjs/affects.d.cts +0 -47
  120. package/dist/types-cjs/boundaries.d.cts +0 -175
  121. package/dist/types-cjs/core/action.d.cts +0 -64
  122. package/dist/types-cjs/core/async.d.cts +0 -21
  123. package/dist/types-cjs/core/constants.d.cts +0 -71
  124. package/dist/types-cjs/core/core.d.cts +0 -148
  125. package/dist/types-cjs/core/dev.d.cts +0 -64
  126. package/dist/types-cjs/core/effect.d.cts +0 -30
  127. package/dist/types-cjs/core/error.d.cts +0 -47
  128. package/dist/types-cjs/core/external.d.cts +0 -15
  129. package/dist/types-cjs/core/graph.d.cts +0 -5
  130. package/dist/types-cjs/core/heap.d.cts +0 -22
  131. package/dist/types-cjs/core/index.d.cts +0 -13
  132. package/dist/types-cjs/core/invariants.d.cts +0 -59
  133. package/dist/types-cjs/core/lanes.d.cts +0 -56
  134. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  135. package/dist/types-cjs/core/owner.d.cts +0 -124
  136. package/dist/types-cjs/core/scheduler.d.cts +0 -170
  137. package/dist/types-cjs/core/types.d.cts +0 -148
  138. package/dist/types-cjs/core/verdict.d.cts +0 -2
  139. package/dist/types-cjs/index.d.cts +0 -10
  140. package/dist/types-cjs/map.d.cts +0 -69
  141. package/dist/types-cjs/package.json +0 -3
  142. package/dist/types-cjs/signals.d.cts +0 -605
  143. package/dist/types-cjs/store/index.d.cts +0 -9
  144. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  145. package/dist/types-cjs/store/projection.d.cts +0 -70
  146. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  147. package/dist/types-cjs/store/store.d.cts +0 -213
  148. package/dist/types-cjs/store/storePath.d.cts +0 -58
  149. package/dist/types-cjs/store/utils.d.cts +0 -114
@@ -0,0 +1,1547 @@
1
+ import { EFFECT_RENDER, EFFECT_USER, STATUS_PENDING, CONFIG_ADOPTED_UNFLUSHED, NOT_PENDING, REACTIVE_MANUAL_WRITE, STATUS_UNINITIALIZED, REACTIVE_OPTIMISTIC_DIRTY, REACTIVE_IN_HEAP_HEIGHT, REACTIVE_DISPOSED, CONFIG_HELD_TRUTH, CONFIG_HAS_COMPANIONS, EFFECT_TRACKED, CONFIG_INPUTS_PUBLISHED, REACTIVE_ZOMBIE, CONFIG_LANE_FRAME, CONFIG_HAS_LANE, CONFIG_HAS_SNAPSHOT, REACTIVE_RECOMPUTING_DEPS, REACTIVE_MISSED_WAKE, CONFIG_IN_SNAPSHOT_SCOPE, REACTIVE_SNAPSHOT_STALE, CONFIG_SLOT_NODE, CONFIG_HELD_CHILDREN, REACTIVE_REASK, CONFIG_AUTHORITATIVE_READ } from "./constants.js";
2
+
3
+ import { attrHooks } from "./attribution-hooks.js";
4
+
5
+ import { resyncUnflushedCompanions, currentOptimisticLane, slotUnobservedHook, markUnflushedStaged, hasActiveOverride } from "./core.js";
6
+
7
+ import { DEV, GRAPH_SIZE_WARN_AT, noteFanOut } from "./dev.js";
8
+
9
+ import { NotReadyError } from "./error.js";
10
+
11
+ import { sweepDormant, trimStaleDeps } from "./graph.js";
12
+
13
+ import { runHeap, deleteFromHeap, enqueueSub } from "./heap.js";
14
+
15
+ import { activeLanes, assignOrMergeLane, findLane } from "./lanes.js";
16
+
17
+ export { getOrCreateLane, mergeLanes, resolveLane } from "./lanes.js";
18
+
19
+ import { devCheckFlushStart, devCheckActiveOverrides, devCensusCompanions, devCheckQuiescent } from "./invariants.js";
20
+
21
+ const transitions = new Set;
22
+
23
+ const dirtyQueue = {
24
+ eE: new Array(2e3).fill(undefined),
25
+ tE: false,
26
+ st: 0,
27
+ EE: 0
28
+ };
29
+
30
+ const zombieQueue = {
31
+ eE: new Array(2e3).fill(undefined),
32
+ tE: false,
33
+ st: 0,
34
+ EE: 0
35
+ };
36
+
37
+ /** runHeap callback that discards a queued zombie recompute instead of running
38
+ * it: unlink pure recompute entries; strip just the recompute bit from dirtied
39
+ * height-adjust entries so their height work still happens. A zombie dirtied
40
+ * through the lane channel (OPTIMISTIC_DIRTY — an override or a `latest()`
41
+ * companion) runs instead (#3444): a zombie renders mainline until the commit
42
+ * disposes it, and the lane's values ARE the mainline frame — the still-visible
43
+ * branch a held `Show` is removing showed the old `latest(count)` beside the
44
+ * new one outside. Its pass runs under the lane and its run lands on the
45
+ * lane's effect queue, so a held lane defers it exactly as it defers every
46
+ * other reader's. */ function cancelZombieRecompute(e) {
47
+ if (e.oe & REACTIVE_OPTIMISTIC_DIRTY && !laneZombie(e)) return GlobalQueue.nt(e);
48
+ if (e.oe & REACTIVE_IN_HEAP_HEIGHT) e.oe &= -140; else {
49
+ deleteFromHeap(e, zombieQueue);
50
+ e.oe &= -132;
51
+ }
52
+ }
53
+
54
+ /** A member of a parked LANE frame (CONFIG_LANE_FRAME on the owner whose pass
55
+ * parked it, #3662). The #3444 exception is for transaction zombies; a lane
56
+ * frame's member is retired by the run that carries the lane's values, so its
57
+ * lane-channel recompute is cancelled with the rest — run, it republished the
58
+ * retired frame under those values. Mainline writes still reach it (#3463). */ function laneZombie(e) {
59
+ let t = e;
60
+ while (t !== null && t.oe & REACTIVE_ZOMBIE) t = t._parent;
61
+ return t !== null && (t.C & CONFIG_LANE_FRAME) !== 0;
62
+ }
63
+
64
+ let clock = 0;
65
+
66
+ let activeTransition = null;
67
+
68
+ let scheduled = false;
69
+
70
+ let halted = false;
71
+
72
+ let haltNotified = false;
73
+
74
+ let syncDepth = 0;
75
+
76
+ let projectionWriteActive = false;
77
+
78
+ /** > 0 while an action's generator body is on the stack (the synchronous
79
+ * slice between yields). Maintained by action.ts around `it.next()`. */ let actionStepDepth = 0;
80
+
81
+ function enterActionStep() {
82
+ actionStepDepth++;
83
+ }
84
+
85
+ function exitActionStep() {
86
+ actionStepDepth--;
87
+ }
88
+
89
+ // Store property nodes whose last subscriber left while they carried state
90
+ // the backing cannot reconstruct — an optimistic override (overrides live on
91
+ // nodes, over a clone the setter discards) or a staged write. Releasing the
92
+ // slot then would drop the override: an optimistic store key read `0` the
93
+ // moment its only reader gated away while the action was live (S7). Swept
94
+ // after each flush — a node still without subs whose override and staging
95
+ // have resolved is released through the slot hook; one that regained a
96
+ // subscriber leaves the set.
97
+ const transientStoreNodes = new Set;
98
+
99
+ /** Slot hook's deferral: release this node when its carried state resolves. */ function deferSlotRelease(e) {
100
+ transientStoreNodes.add(e);
101
+ }
102
+
103
+ function canUseSimpleSyncFlush(e) {
104
+ const t = e.m;
105
+ return transitions.size === 0 && activeLanes.size === 0 && e.Xn.length === 0 && t.bn.length === 0 && t.A.length === 0 && t.En.size === 0 && transientStoreNodes.size === 0 && pendingRearms.size === 0;
106
+ }
107
+
108
+ function sweepTransientStoreNodes() {
109
+ if (transientStoreNodes.size === 0) return;
110
+ for (const e of transientStoreNodes) {
111
+ if (e.u !== null) {
112
+ transientStoreNodes.delete(e);
113
+ continue;
114
+ }
115
+ if (e._e !== NOT_PENDING) continue;
116
+ if (e.o?.we !== undefined && e.o?.we !== NOT_PENDING) continue;
117
+ // A live affects() mark keeps the node addressable: sweeping it would
118
+ // detach the refcount from the slot (a fresh probe would upsert a new,
119
+ // unmarked node for the same property).
120
+ if (e.o?.t) continue;
121
+ transientStoreNodes.delete(e);
122
+ if (e.C & CONFIG_SLOT_NODE) slotUnobservedHook(e); else e.o?.bt?.();
123
+ }
124
+ }
125
+
126
+ /**
127
+ * Toggles the dev-mode "must be inside a `<Loading>` boundary" enforcement
128
+ * window. Only `render()` calls this — wrapping the initial mount so that a
129
+ * top-level uncaught async read surfaces the diagnostic. Not part of the
130
+ * user-facing API.
131
+ *
132
+ * @internal
133
+ */ function enforceLoadingBoundary(e) {}
134
+
135
+ function setProjectionWriteActive(e) {
136
+ projectionWriteActive = e;
137
+ }
138
+
139
+ /**
140
+ * Ambient work IS a transaction: the global queue always carries one
141
+ * current-transaction-shaped batch (`globalQueue._batch`). With no transition
142
+ * active, registrations (pending commits, optimistic nodes, affects marks,
143
+ * optimistic stores) land in a plain ambient batch that the plain flush
144
+ * finalizes; when a transition initializes it adopts the ambient batch's
145
+ * contents and `_batch` becomes the transition itself, so later registrations
146
+ * land there directly — no per-field aliasing.
147
+ */ function createBatch() {
148
+ return {
149
+ Ge: clock,
150
+ In: [],
151
+ ae: new Map,
152
+ bn: [],
153
+ A: [],
154
+ En: new Set,
155
+ tt: [],
156
+ ei: {
157
+ ti: [ [], [] ],
158
+ Xn: []
159
+ },
160
+ Dt: false,
161
+ Tt: new Set,
162
+ ht: null
163
+ };
164
+ }
165
+
166
+ function mergeTransitionState(e, t) {
167
+ if (attrHooks !== null) attrHooks.transitionMerged(e, t);
168
+ t.Dt = e;
169
+ e.tt.push(...t.tt);
170
+ e.et ||= t.et;
171
+ for (const n of activeLanes) if (n.me === t) n.me = e;
172
+ if (t.bn.length) {
173
+ // Move (don't copy): the global queue's batch may still be the outgoing
174
+ // transition, and the adoption pass in initTransition would re-push its
175
+ // contents into the target — duplicating every entry.
176
+ e.bn.push(...t.bn);
177
+ t.bn.length = 0;
178
+ }
179
+ if (t.A.length) {
180
+ // Move (don't copy): the global queue's batch may still be the outgoing
181
+ // transition, and the adoption pass in initTransition would re-push its
182
+ // contents into the target — double-releasing every mark.
183
+ e.A.push(...t.A);
184
+ t.A.length = 0;
185
+ }
186
+ for (const n of t.En) e.En.add(n);
187
+ for (const [n, i] of t.ae) {
188
+ let t = e.ae.get(n);
189
+ if (!t) e.ae.set(n, t = new Set);
190
+ for (const e of i) t.add(e);
191
+ }
192
+ for (const n of t.Tt) e.Tt.add(n);
193
+ if (t.ht) (e.ht ??= []).push(...t.ht);
194
+ }
195
+
196
+ /**
197
+ * Flip-entanglement (#3164 follow-up): `until()` is a declaration of
198
+ * relatedness — the predicate names the condition that confirms the awaiting
199
+ * transaction. When the predicate settles truthy, every live foreign
200
+ * transition whose staged write it read IS the confirming event by the
201
+ * user's own definition, so it merges into the awaiting transaction and
202
+ * reveals at the joint settle — the cross-primitive twin of the family fold
203
+ * (a landing on an optimism-carrying family joins the retaining
204
+ * transaction). Non-flipping updates never pass through here: falsy
205
+ * evaluations don't entangle, so unrelated traffic on the watched sources
206
+ * reveals freely on its own schedule.
207
+ *
208
+ * Runs inside the predicate's compute (pure phase) — the confirming
209
+ * transition's stamps are still live and its commit decision hasn't run, so
210
+ * the merge lands before any reveal. Only the tree-shaken graphs that call
211
+ * `until()` retain this.
212
+ */ function entangleConfirmingTransitions(e, t) {
213
+ t = currentTransition(t);
214
+ if (t.Dt === true) return;
215
+ // The confirming evidence is a dep whose value is STAGED (pending,
216
+ // uncommitted) at flip evaluation — committed deps are public already and
217
+ // carry nothing to entangle. A staged dep lives in one of two carriers: a
218
+ // stamped transition, or the queue's current batch (ambient registrations
219
+ // don't stamp; "ambient work IS a transaction" — the batch is the
220
+ // carrier). The entangle STEALS the carrier's staged cargo — its pending
221
+ // nodes move (re-stamped) into the awaiting transaction and reveal at its
222
+ // settle — but never the carrier itself: its async reporters, actions,
223
+ // and stashes are its own future (a live stream's flight must not chain
224
+ // the awaiting transaction to landings that haven't happened; a merged
225
+ // reporter deadlocked exactly that way).
226
+ let n = false;
227
+ for (let i = e.Ee; i !== null; i = i.Ie) {
228
+ const r = i.De;
229
+ if (r._e !== NOT_PENDING) {
230
+ const e = r.me;
231
+ const i = e != null ? currentTransition(e) : null;
232
+ // Skip the awaiting transaction's own cargo (t === target: a
233
+ // fold-staged landing or a write the action itself issued — hold and
234
+ // reveal already correct) and dead carriers. Ambient-batch staging
235
+ // (t === null) must leave the batch NOW — it commits at this flush's
236
+ // end, which would reveal the confirmation under the live optimism
237
+ // it just confirmed.
238
+ const s = i === null ? currentBatch.In : i !== t && i.Dt !== true ? i.In : null;
239
+ if (s !== null) n = stealEntangledCargo(s, t) || n;
240
+ }
241
+ if (i === e.Je) break;
242
+ }
243
+ // The steal never activates the awaiting transaction: the predicate can
244
+ // flip inside another transaction's finalize heap, and adopting the queue
245
+ // batch there hands the stolen cargo to that finalize's commit sweep — a
246
+ // premature reveal at a foreign settle. Subscribers that computed against
247
+ // the pre-steal world were re-dirtied by the steal itself, so this
248
+ // flush's applies paint the mid-hold view (committed for lane and stale
249
+ // readers; a deriving reader is held with the cargo); the cargo commits
250
+ // at the awaiting transaction's own settle.
251
+ }
252
+
253
+ /** Move a confirming carrier's staged nodes into the awaiting transaction:
254
+ * re-stamp and arm the held-truth mask (override-covered nodes skip it —
255
+ * the override already hides their staged value per A17, and is usually
256
+ * the very optimism this confirmation settles); the mask's commit
257
+ * registers the settle-side post-revert wake. The carrier's array is
258
+ * emptied so its own commit point commits none of the stolen cargo.
259
+ *
260
+ * EFFECT subs of stolen nodes re-run: any that recomputed against the
261
+ * staging BEFORE the steal (the carrier's landing notified them as a plain
262
+ * write) hold a private result derived from the carrier's world — one
263
+ * that the next paint gate (stash-point lane run, a foreign flush's
264
+ * completion drain) would apply as the carrier's. Re-running them now that
265
+ * the cargo is the awaiting transaction's re-routes each by its posture in
266
+ * this same heap pass: a lane pass keeps committed (the mask), a stale
267
+ * render effect keeps committed and registers for the reveal's replay
268
+ * (stale-of-foreign), and a deriving user effect is served the truth and
269
+ * held with the transaction (A29). PURE computeds are deliberately NOT
270
+ * re-run: a staged value of theirs is itself stolen cargo — held with the
271
+ * transaction, so ordinary readers already serve their committed value —
272
+ * while re-running them would re-derive the OLD world and re-stage it over
273
+ * the held truth. The reveal re-notifies (commitPendingNodes), which is
274
+ * when they re-derive for real. */ function stealEntangledCargo(e, t) {
275
+ if (e === t.In || e.length === 0) return false;
276
+ for (let n = 0; n < e.length; n++) {
277
+ const i = e[n];
278
+ i.me = t;
279
+ t.In.push(i);
280
+ // Override-covered nodes stay silent AND unmasked: the override is the
281
+ // display (A17 — its staging never notified, its revert will), so their
282
+ // subs saw nothing and re-running one would break the silence with a
283
+ // duplicate fire of an unchanged view.
284
+ if (!hasActiveOverride(i)) {
285
+ i.C |= CONFIG_HELD_TRUTH;
286
+ for (let e = i.u; e !== null; e = e.Pe) {
287
+ const t = e.Ae;
288
+ if (t.He && !(t.C & CONFIG_AUTHORITATIVE_READ)) enqueueSub(t);
289
+ }
290
+ }
291
+ }
292
+ e.length = 0;
293
+ transitions.add(t);
294
+ return true;
295
+ }
296
+
297
+ /** `schedule()` armed `scheduled` but withheld the microtask because a
298
+ * projection draft was writing (see below). Consumed by `scheduleWithheld`. */ let withheld = false;
299
+
300
+ function schedule() {
301
+ if (halted) {
302
+ notifyHalted();
303
+ return;
304
+ }
305
+ if (scheduled) return;
306
+ scheduled = true;
307
+ if (!syncDepth && !globalQueue.$t) {
308
+ // A projection draft's writes withhold the microtask: a flight's landing
309
+ // drains them (asyncWrite's flush), and a drain BEFORE the landing tears
310
+ // the pre- and post-await halves of the run apart (createProjection.async
311
+ // "notifies only changed paths"). A draft write that no landing will
312
+ // follow re-arms through scheduleWithheld (proj R37).
313
+ withheld = projectionWriteActive;
314
+ if (!withheld) queueMicrotask(flush);
315
+ }
316
+ }
317
+
318
+ /** Arm the microtask `schedule()` withheld under projectionWriteActive. The
319
+ * projection draft calls this after a write made outside its run with no
320
+ * flight up (proj R37): nothing else will drain, and leaving `scheduled`
321
+ * armed with no microtask strands the whole scheduler — every later
322
+ * `schedule()` early-returns — until something calls `flush()` by hand.
323
+ * (`withheld` was set in the same synchronous slice as this call, so the
324
+ * syncDepth/_running gates it passed still hold; a stale mark left by a
325
+ * landing's own flush arms at worst one no-op drain.) */ function scheduleWithheld() {
326
+ if (withheld) {
327
+ withheld = false;
328
+ queueMicrotask(flush);
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Parked transactions whose reporter set changed without a write. A
334
+ * transaction completes when nothing live reports a flight it waits on, but
335
+ * the flush only judges the ACTIVE transaction: a parked one is re-entered by
336
+ * a stamped node's landing or an action's resume. A reporter that stops
337
+ * counting for another reason — its loading boundary flipped to the fallback
338
+ * (#3375), or it was disposed by ambient work (#3372) — is neither: the
339
+ * pruning in `reporterBlocksSource` would drop it at the next check, but no
340
+ * check comes, and the writes held with it stay staged. Such sites record the
341
+ * transaction here (deduped: one idle pass per transaction, however many
342
+ * reporters changed); the flush re-enters it on an otherwise idle pass, so
343
+ * the re-evaluation adopts no unrelated ambient work.
344
+ */ const wokenTransitions = [];
345
+
346
+ /** Wake every parked transaction — for a site that knows a reporter stopped
347
+ * counting but not whose (a boundary reset). */ function wakeParked() {
348
+ for (const e of transitions) wokenTransitions.includes(e) || wokenTransitions.push(e);
349
+ schedule();
350
+ }
351
+
352
+ /**
353
+ * Boundaries whose `on` dependencies notified this flush (#3540; a Set:
354
+ * many notifications, one re-arm). The notification arrives inside a pass,
355
+ * at the height of the `on` reads — before the readers the write put in
356
+ * flight are registered — so the re-arm waits for the heap and runs before
357
+ * the verdict (GlobalQueue.run → drainRearms), still under the write's
358
+ * transaction: the release is seen by the verdict that follows, and the
359
+ * staged fallback swap lands with the write's frame.
360
+ */ const pendingRearms = new Set;
361
+
362
+ function queueRearm(e) {
363
+ pendingRearms.add(e);
364
+ schedule();
365
+ }
366
+
367
+ /** The drain (see pendingRearms): each boundary decides for itself, from
368
+ * what is pending under it now, whether re-arming means its fallback or
369
+ * nothing. Snapshot first: a re-arm can queue another — a write it makes
370
+ * notifying an `on` that reads it — which is the next pass's. */ function drainRearms() {
371
+ const e = Array.from(pendingRearms);
372
+ pendingRearms.clear();
373
+ for (let t = 0; t < e.length; t++) e[t].se();
374
+ }
375
+
376
+ /** Transactions a mainline tick has PROPOSED against (A34, #3494): a write to a
377
+ * node one of them holds — the same value or another — is a second proposal
378
+ * on a contested node, and the tick reveals with the hold ("both are
379
+ * suggesting a value; if one finished before the other that would be odd").
380
+ * Entered at the next flush's start, where the ambient batch is adopted;
381
+ * never from the write itself, which left `activeTransition` set across the
382
+ * caller's block and made creation after the write the transaction's (A29). */ const batchJoins = [];
383
+
384
+ /**
385
+ * Permanently halts the reactive system. Called when a user error escapes
386
+ * every boundary — app state is undefined at that point, so scheduling stops
387
+ * entirely rather than limping along with a half-applied update.
388
+ */
389
+ /**
390
+ * The key a root owner carries its client error hook under (`render`'s
391
+ * `onError`) — registered, so a runtime writes it with no import of the hook
392
+ * module (core/error-hooks.ts) and no property mangling in the way. Defined
393
+ * HERE, not there: a runtime that only writes the key must not retain the
394
+ * hook machinery (pay-for-use).
395
+ */ const ROOT_ERROR_HOOK = Symbol.for("solid-js/root-error-hook");
396
+
397
+ function haltReactivity(e) {
398
+ if (halted) return;
399
+ halted = true;
400
+ let t = "[REACTIVITY_HALTED]";
401
+ // Surface the cause here too: callers rethrow it, but a creation-time throw
402
+ // unwinds through ancestor recomputes that convert it to status instead of
403
+ // surfacing it (#2884), so the rethrow alone cannot guarantee visibility.
404
+ // Where the platform has one, hand the cause to its uncaught-error channel
405
+ // (`reportError` → `error` event → window.onerror / error monitoring): a
406
+ // halt that only reaches console.error leaves a page that LOOKS alive with
407
+ // nothing an app or its telemetry can act on (#3338 — an uncaught throw
408
+ // during the hydration render). The rethrow may reach the top as well in
409
+ // the non-swallowed cases; a duplicate report beats a silent one.
410
+ const n = e !== undefined && globalThis.reportError;
411
+ n || e === undefined ? console.error(t) : console.error(t, e);
412
+ n && n(e);
413
+ }
414
+
415
+ // Logs on the first write after a halt so a frozen interaction is traceable.
416
+ function notifyHalted() {
417
+ if (haltNotified) return;
418
+ haltNotified = true;
419
+ console.error("[REACTIVITY_HALTED]");
420
+ }
421
+
422
+ /** @internal Test/dev-reload hook. Revives scheduling after a halt. */ function resetErrorHalt() {
423
+ halted = false;
424
+ haltNotified = false;
425
+ }
426
+
427
+ // Identifies one child-traversal pass in `Queue.run` so a rescan after the
428
+ // child list shifts can tell "already run this pass" from "still pending".
429
+ let queueRunToken = 0;
430
+
431
+ class Queue {
432
+ _parent=null;
433
+ ti=[ [], [] ];
434
+ Xn=[];
435
+ ni=0;
436
+ created=clock;
437
+ addChild(e) {
438
+ this.Xn.push(e);
439
+ e._parent = this;
440
+ }
441
+ removeChild(e) {
442
+ const t = this.Xn.indexOf(e);
443
+ if (t >= 0) {
444
+ this.Xn.splice(t, 1);
445
+ e._parent = null;
446
+ }
447
+ }
448
+ notify(e, t, n, i) {
449
+ if (this._parent) return this._parent.notify(e, t, n, i);
450
+ return false;
451
+ }
452
+ run(e) {
453
+ if (this.ti[e - 1].length) {
454
+ const t = this.ti[e - 1];
455
+ this.ti[e - 1] = [];
456
+ runQueue(t, e);
457
+ }
458
+ // Effects run here can dispose owners, and disposal removes queues from
459
+ // this list — the running child itself, an earlier sibling, or several at
460
+ // once. A plain index walk then skips whatever shifted into the cursor.
461
+ // Stamping each child before it runs makes the pass idempotent, so a shift
462
+ // can be recovered by rescanning from the front and every child still runs
463
+ // exactly once. Children appended mid-pass carry a stale stamp and run,
464
+ // matching the previous live-array behaviour.
465
+ const t = this.Xn;
466
+ const n = ++queueRunToken;
467
+ for (let i = 0; i < t.length; ) {
468
+ const r = t[i];
469
+ if (r.ni !== n) {
470
+ r.ni = n;
471
+ r.run?.(e);
472
+ if (t[i] !== r) {
473
+ i = 0;
474
+ continue;
475
+ }
476
+ }
477
+ i++;
478
+ }
479
+ }
480
+ enqueue(e, t) {
481
+ if (e) {
482
+ // Route to lane's effect queue if we're in an optimistic recomputation
483
+ if (currentOptimisticLane) {
484
+ const n = findLane(currentOptimisticLane);
485
+ n.It[e - 1].push(t);
486
+ } else {
487
+ this.ti[e - 1].push(t);
488
+ }
489
+ }
490
+ schedule();
491
+ }
492
+ stashQueues(e) {
493
+ // Attribution hook: the parking transition's lane effects have run; its
494
+ // queues are being stashed. Root call only (children recurse below).
495
+ if (attrHooks !== null && this === globalQueue) attrHooks.holdEnd();
496
+ e.ti[0].push(...this.ti[0]);
497
+ e.ti[1].push(...this.ti[1]);
498
+ this.ti = [ [], [] ];
499
+ for (let t = 0; t < this.Xn.length; t++) {
500
+ let n = this.Xn[t];
501
+ let i = e.Xn[t];
502
+ if (!i) {
503
+ i = {
504
+ ti: [ [], [] ],
505
+ Xn: []
506
+ };
507
+ e.Xn[t] = i;
508
+ }
509
+ n.stashQueues(i);
510
+ }
511
+ }
512
+ restoreQueues(e) {
513
+ this.ti[0].push(...e.ti[0]);
514
+ this.ti[1].push(...e.ti[1]);
515
+ for (let t = 0; t < e.Xn.length; t++) {
516
+ const n = e.Xn[t];
517
+ let i = this.Xn[t];
518
+ if (i) i.restoreQueues(n);
519
+ }
520
+ }
521
+ }
522
+
523
+ class GlobalQueue extends Queue {
524
+ $t=false;
525
+ // The current transaction-shaped batch: a plain ambient batch while no
526
+ // transition is active, the active transition itself after initTransition.
527
+ m=createBatch();
528
+ static nt;
529
+ static ut;
530
+ static Rt;
531
+ static ii=null;
532
+ // Store-side hook: drops a keyless affects() mark's identity scope when the
533
+ // carrier node's last registration releases (wired by store.ts, mirroring
534
+ // _clearOptimisticStore).
535
+ static p=null;
536
+ // affects()-side hooks (wired by affects.ts, mirroring _update): the mark
537
+ // engine — count/register/release — lives with the feature. Every call site
538
+ // is gated by state only that module creates, so `!` invocations are safe
539
+ // once the gate holds.
540
+ static G=null;
541
+ static M=null;
542
+ static j=null;
543
+ // External-source bridge (wired by enableExternalSource(); null while no
544
+ // config is active — including after _resetExternalSourceConfig()).
545
+ static Bt=null;
546
+ static Jt=null;
547
+ // Verdict-layer hooks (wired by verdict.ts when isPending()/latest() are
548
+ // imported; null in apps that never use them). Call sites either guard for
549
+ // null or sit behind state only the verdict layer can create (`!` is safe
550
+ // there: `_pendingSignal`/`_latestValueComputed` are only ever assigned by
551
+ // verdict.ts, and `pendingCheckActive`/`latestReadActive` only flip inside
552
+ // isPending()/latest()).
553
+ static Le=null;
554
+ static Ue=null;
555
+ static qe=null;
556
+ static Qn=null;
557
+ static An=null;
558
+ static Cn=null;
559
+ static Hn=null;
560
+ static At=null;
561
+ static k=null;
562
+ static ri=null;
563
+ // Re-asks probes whose verdict was provisionally suppressed by a fresh read
564
+ // of a held value, once the transaction gains an async blocker (#3028).
565
+ static si=null;
566
+ // Optimistic-engine hooks (wired by core/optimistic.ts via
567
+ // installOptimisticEngine(), called from verdict.ts / createOptimistic /
568
+ // createOptimisticStore — every module that can create optimistic state).
569
+ // Call sites are gated by state only the engine can create: an
570
+ // `_overrideValue` slot, a lane in `activeLanes`, an `_optimisticNodes`
571
+ // entry, or a non-null `currentOptimisticLane`, so `!` invocations are safe
572
+ // once the gate holds.
573
+ static Ln=null;
574
+ static Bn=null;
575
+ static Yn=null;
576
+ static Wn=null;
577
+ static Kn=null;
578
+ /** Patch-channel optimistic drain (next/patch.ts): optimistic emissions
579
+ * apply at lane-effect timing — visible in flight, unlike the regular
580
+ * effect queues an action stashes. Injected; null when unused. */
581
+ static Zn=null;
582
+ static Pn=null;
583
+ static Gn=null;
584
+ /** Is the node routed through a LIVE lane (`resolveLane`)? read()'s reveal
585
+ * carve-out asks before showing a foreign-held pending node's committed
586
+ * value: a lane-derived flight's inputs are already revealed through the
587
+ * lane (#3334). Gated on CONFIG_HAS_LANE, which only the engine sets. */
588
+ static Rn=null;
589
+ static On=null;
590
+ static _t=null;
591
+ static Ot=null;
592
+ /** Authoritative-view reader wakeup: installed by until() and refresh() before
593
+ * their first read. Call sites are gated by CONFIG_AUTHORITATIVE_OBSERVED, which
594
+ * only such a reader's carve-out read can set, so `!` invocations are safe once
595
+ * the gate holds (#3303). */
596
+ static Xt=null;
597
+ static St=null;
598
+ /** A18 supersession (#3331): own-source truth `value` landed under an active
599
+ * override. The engine decides whether the graph re-derives — the value
600
+ * differs from the override and is not a stale (older-action) answer (mark
601
+ * the node, demote its lane cascade, notify), or returns to it after an
602
+ * earlier differing arrival (clear the mark, notify) — and owns the
603
+ * authoritative-observer wake for a silent confirm. Installed with the
604
+ * optimistic engine; only reachable on a node that has an override. */
605
+ static Qe=null;
606
+ /** The flush's pre-verdict step (#3427): once the transaction's action
607
+ * bodies have all ended and nothing authoritative is left in flight, the
608
+ * engine supersedes every override still in force with the truth it
609
+ * reverts to, so the graph re-derives from it now, as the transaction's
610
+ * held work, instead of after the flights the overrides fed have landed.
611
+ * True when it superseded something: the caller re-runs the heap ahead of
612
+ * the verdict. The engine owns every gate (acted, actions drained, has
613
+ * overrides, no store edits, no authoritative flight); null without it. */
614
+ static zn=null;
615
+ /** read()'s value for a TRACKED reader of a superseded node (#3331): the
616
+ * staged truth, unless the reader is a stale (render) reader of another
617
+ * transaction — then the displayed override, as it keeps a foreign
618
+ * transaction's committed value over its staged write. */
619
+ /** A tracked read of an active override: the lane outside-view rule
620
+ * (#3460) and the A18 supersession selection (#3331) — see optimistic.ts. */
621
+ static Dn=null;
622
+ /** A lane pass's publish for a memo (#3479, lanes stage): the speculative
623
+ * result becomes a DERIVED override, `_value` stays committed — see
624
+ * optimistic.ts laneOverride. Set with the engine, which a lane implies. */
625
+ static je=null;
626
+ /** Verdict-layer recompute in progress (companion creation, latest()/
627
+ * isPending() pulls): never born held — see core.ts enterStagedRead. */
628
+ static Tn=false;
629
+ /** setSignal's authoritative (projection-write) landing on an override-
630
+ * covered node (#3331 store twin): stage the truth for its transaction's
631
+ * commit whatever its relation to the committed value — a landing equal to
632
+ * committed still differs from the override — then _supersedeOverride
633
+ * decides. Installed with the optimistic engine; only reachable on a node
634
+ * that has an override. */
635
+ static Vn=null;
636
+ static Jn=null;
637
+ flush() {
638
+ if (this.$t) return;
639
+ // Fast drain: nothing in flight but plain pending commits — no dirty
640
+ // computeds, no queued effects, no child queues, no transitions/lanes/
641
+ // optimistic state. Commit and go; anything a commit hook schedules
642
+ // (companion snaps, store folds notifying subs) re-arms `scheduled`
643
+ // below and the outer drain loop takes the full spine next round.
644
+ if (activeTransition === null && dirtyQueue.EE < dirtyQueue.st && this.ti[0].length === 0 && this.ti[1].length === 0 && this.Xn.length === 0 && !wokenTransitions.length && !batchJoins.length && // a join must drain in its own tick (#3519 review)
645
+ canUseSimpleSyncFlush(this)) {
646
+ this.$t = true;
647
+ try {
648
+ // A28: companions of nodes written since the last flush mirror the
649
+ // flushed world — re-synced inside the running window (the write is
650
+ // "flushed" from here on).
651
+ resyncUnflushedCompanions();
652
+ // Sweep first: unobserved() pulls swept nodes out of the dirty heap,
653
+ // so a dormant memo dirtied in the same tick is reclaimed instead of
654
+ // recomputed (matching the old inline dispose-on-read counts).
655
+ sweepDormant();
656
+ commitPendingNodes();
657
+ } finally {
658
+ this.$t = false;
659
+ }
660
+ clock++;
661
+ scheduled = dirtyQueue.EE >= dirtyQueue.st || this.ti[0].length !== 0 || this.ti[1].length !== 0 || this.m.In.length !== 0;
662
+ return;
663
+ }
664
+ this.$t = true;
665
+ resyncUnflushedCompanions();
666
+ // A28, see above
667
+ try {
668
+ // The tick proposed against a hold (#3494): adopt its batch into it.
669
+ // Inside the try: the adoption runs user comparators (the no-proposal
670
+ // drop), and a throw there must not leave `_running` set.
671
+ while (batchJoins.length) this.initTransition(batchJoins.pop());
672
+ if (false) ;
673
+ // Before runHeap for the same reason as the fast drain above; late
674
+ // subscribers (an effect reading a swept memo this flush) revive it,
675
+ // which is the pay-for-use contract.
676
+ sweepDormant();
677
+ runHeap(dirtyQueue, GlobalQueue.nt);
678
+ // The action bodies are over: the overrides they leave in force
679
+ // revert at this settle, and the correction is this transaction's
680
+ // held work — re-derived here, under it, ahead of the verdict — not a
681
+ // waterfall after the flights the overrides fed (#3427). After the
682
+ // heap, not before: a synchronous body's own writes (a refresh that
683
+ // puts an override node's source in flight) are judged applied.
684
+ if (activeTransition && GlobalQueue.zn?.(activeTransition)) runHeap(dirtyQueue, GlobalQueue.nt);
685
+ // Re-arm the boundaries whose `on` notified this pass (pendingRearms):
686
+ // after the heap — what the notification put in flight is registered —
687
+ // and before the verdict, under the transaction that carried it. The
688
+ // boundary releases its hold and stages its fallback swap with the
689
+ // frame; the heap re-runs so its output pass is staged too, ahead of
690
+ // the verdict that commits or parks it (#3540).
691
+ if (pendingRearms.size) {
692
+ drainRearms();
693
+ runHeap(dirtyQueue, GlobalQueue.nt);
694
+ }
695
+ if (activeTransition) {
696
+ // A boundary whose fallback read something not ready is judged before
697
+ // the verdict, under the transaction (boundaries.ts `_judgeHeld`,
698
+ // #3540): its output is pending on that read and holds the frame,
699
+ // and only a sweep re-runs it — the commit sweep, after the verdict
700
+ // its own read keeps parking. Ready, it stages `_disabled` false with
701
+ // the frame; the heap re-runs so the output drops the read ahead of
702
+ // the verdict.
703
+ if (this.Xn.length) {
704
+ checkBoundaryChildren(this, true);
705
+ if (dirtyQueue.EE >= dirtyQueue.st) runHeap(dirtyQueue, GlobalQueue.nt);
706
+ }
707
+ const e = transitionComplete(activeTransition);
708
+ if (!e) {
709
+ const e = activeTransition;
710
+ // Parked: the unchanged passes' inputs are held; their tails stay (A30).
711
+ heldTrims.length = 0;
712
+ // When the parking batch IS the transition, all of its writes commit
713
+ // only with it — every zombie recompute they queued would run against
714
+ // a world the zombie never displays (zombies render mainline until
715
+ // commit), so cancel them instead of running them. Only an ambient
716
+ // batch's mainline writes (the #2916 shape below) legitimately reach
717
+ // zombies here. Height-adjust entries still process normally: a
718
+ // dirtied one keeps its height flag and falls through to runHeap's
719
+ // adjustHeight path on the next pass of the bucket.
720
+ runHeap(zombieQueue, this.m === e ? cancelZombieRecompute : GlobalQueue.nt);
721
+ // Detach: the stashed transition keeps its batch; ambient work that
722
+ // follows lands in a fresh one. If the batch is already a separate
723
+ // ambient one — action done() restored activeTransition without
724
+ // adopting the batch, and an ordinary write landed there before
725
+ // the scheduled flush (#2916) — keep it: replacing it would strand
726
+ // its queued pending nodes with held _pendingValues forever.
727
+ if (this.m === e) currentBatch = this.m = createBatch();
728
+ // Run lane effects immediately (before stashing) - lanes with no pending async
729
+ if (activeLanes.size) {
730
+ GlobalQueue.Kn(EFFECT_RENDER);
731
+ GlobalQueue.Kn(EFFECT_USER);
732
+ }
733
+ this.stashQueues(e.ei);
734
+ clock++;
735
+ // A kept ambient batch may hold pending nodes (#2916): stay
736
+ // scheduled so the outer drain loop commits them via the plain
737
+ // flush path instead of leaving them until the next natural flush.
738
+ scheduled = dirtyQueue.EE >= dirtyQueue.st || this.m.In.length > 0;
739
+ reassignPendingTransition(e.In);
740
+ activeTransition = null;
741
+ finalizePureQueue(null, true);
742
+ return;
743
+ }
744
+ const t = activeTransition;
745
+ const n = this.m;
746
+ n !== t && n.In.push(...t.In);
747
+ this.restoreQueues(t.ei);
748
+ transitions.delete(t);
749
+ activeTransition = null;
750
+ reassignPendingTransition(n.In);
751
+ finalizePureQueue(t);
752
+ if (n === t) {
753
+ // Drop the dead Transition wrapper but keep its (drained) containers
754
+ // as the ambient batch — late registrations during finalization live
755
+ // there and must survive to the next flush.
756
+ const e = createBatch();
757
+ e.In = n.In;
758
+ e.bn = n.bn;
759
+ e.A = n.A;
760
+ e.En = n.En;
761
+ currentBatch = this.m = e;
762
+ }
763
+ } else {
764
+ if (canUseSimpleSyncFlush(this)) {
765
+ commitPendingNodes();
766
+ if (dirtyQueue.EE >= dirtyQueue.st) {
767
+ runHeap(dirtyQueue, GlobalQueue.nt);
768
+ commitPendingNodes();
769
+ }
770
+ } else {
771
+ // Parked transactions elsewhere: their owners' zombies render
772
+ // mainline until the commit that disposes them, so a mainline write
773
+ // reaches them here (#2916, #3463). Commit THIS flush's pending nodes
774
+ // first (#3546): a zombie whose owner commits now is disposed by that
775
+ // commit and never reruns — the same fate it has when no transaction
776
+ // is parked, where this queue is not run at all. Run before the
777
+ // commit, it reran and notified its owner through the previous
778
+ // pass's dependency tail (kept by A30 until the commit trims it),
779
+ // and the owner recomputed a second time with identical inputs,
780
+ // creating and disposing one more child per write. Only the zombies
781
+ // of actually parked owners survive the commit and rerun; the
782
+ // finalize's own commit picks up whatever those reruns stage.
783
+ if (transitions.size) {
784
+ commitPendingNodes();
785
+ runHeap(zombieQueue, GlobalQueue.nt);
786
+ }
787
+ finalizePureQueue();
788
+ }
789
+ }
790
+ clock++;
791
+ // Check if finalization added items to the heap (from optimistic reversion).
792
+ // Finalization may also have ENTERED a transaction (a commit hook, boundary
793
+ // sweep or recompute wrote a node it owns): effects computed under it
794
+ // since are its to apply, not this flush's — runEffect leaves them queued
795
+ // and the next pass parks them with it (#3319). Everything computed
796
+ // mainline applies now.
797
+ scheduled = dirtyQueue.EE >= dirtyQueue.st || activeTransition !== null;
798
+ // Run lane effects first (for ready lanes), then regular effects
799
+ activeLanes.size && GlobalQueue.Kn(EFFECT_RENDER);
800
+ this.run(EFFECT_RENDER);
801
+ activeLanes.size && GlobalQueue.Kn(EFFECT_USER);
802
+ this.run(EFFECT_USER);
803
+ if (false) ;
804
+ if (false && !scheduled && !activeTransition && transitions.size === 0 && activeLanes.size === 0) ;
805
+ if (false) ;
806
+ } finally {
807
+ // Re-enter a woken transaction (see wokenTransitions) only from an
808
+ // idle pass: entering adopts the ambient batch, and staged or dirty
809
+ // ambient work would be held behind flights it never read. `scheduled`
810
+ // is that test here — after the park exit as well as the normal one:
811
+ // it was recomputed from the heap this pass, every write since re-armed
812
+ // it, and optimistic ambient nodes reverted with the finalize — so a
813
+ // wake in a pass with work simply falls to the next. Entering re-arms
814
+ // it itself; a dead (completed) wake is a bare return in
815
+ // initTransition, and the loop moves on to the next.
816
+ while (!scheduled && !activeTransition && wokenTransitions.length) this.initTransition(wokenTransitions.pop());
817
+ this.$t = false;
818
+ }
819
+ }
820
+ notify(e, t, n, i) {
821
+ // Only track async if the boundary is propagating STATUS_PENDING (not caught by boundary)
822
+ if (t & STATUS_PENDING) {
823
+ if (n & STATUS_PENDING) {
824
+ // Callers pass either nothing or this node's own `_x._error`, so `??`
825
+ // is exact (a null error falls back to the same null).
826
+ const t = i ?? e.o?._;
827
+ // A visibility-only mark notification (the affects() boundary
828
+ // channel) updates display state on its way up but must be invisible
829
+ // to completion accounting BY CONSTRUCTION: it never registers a
830
+ // reporter and never counts toward the loading-boundary diagnostic.
831
+ if (t?.l) return true;
832
+ if (t) {
833
+ // A reveal can discover a flight started in an earlier flush. Hold
834
+ // the staged writes with that reader (A15), even if the reader is
835
+ // new. Fresh/reset loading boundaries consume pending before it
836
+ // reaches here. A reader already parked in a transition must not
837
+ // open a second one.
838
+ if (!activeTransition && !e.me && currentBatch.In.length) this.initTransition();
839
+ if (activeTransition) {
840
+ const n = t.source;
841
+ let i = activeTransition.ae.get(n);
842
+ if (!i) activeTransition.ae.set(n, i = new Set);
843
+ const r = i.size;
844
+ i.add(e);
845
+ if (i.size !== r) {
846
+ schedule();
847
+ GlobalQueue.si?.(activeTransition);
848
+ }
849
+ }
850
+ }
851
+ }
852
+ return true;
853
+ }
854
+ return false;
855
+ }
856
+ initTransition(e) {
857
+ if (e) {
858
+ e = currentTransition(e);
859
+ // A finished transaction cannot be re-entered: its state is committed
860
+ // or reverted, so "rejoining" it (A26) is meaningless and re-activating
861
+ // it spins the drain loop (#3140). The refusal must be a bare return —
862
+ // redirecting the caller to a fresh batch would re-arm the loop with a
863
+ // new transaction identity each pass. Stamps are cleared at commit, so
864
+ // this is a belt for paths that hand over a chased-dead reference
865
+ // (merged chains, async settles racing completion).
866
+ if (e.Dt === true || e === activeTransition) return;
867
+ }
868
+ if (!e && activeTransition && activeTransition.Ge === clock) return;
869
+ if (!activeTransition) {
870
+ activeTransition = e ?? createBatch();
871
+ } else if (e) {
872
+ const t = activeTransition;
873
+ mergeTransitionState(e, t);
874
+ // Effects the outgoing transaction parked belong to the surviving one
875
+ // now: back onto the live queue, where this flush parks them under
876
+ // `transition` or runs them at its completion. The outgoing stash is
877
+ // never read again — the transaction is dead (#3310).
878
+ this.restoreQueues(t.ei);
879
+ transitions.delete(t);
880
+ activeTransition = e;
881
+ }
882
+ transitions.add(activeTransition);
883
+ activeTransition.Ge = clock;
884
+ const t = this.m;
885
+ if (t !== activeTransition) {
886
+ // Adopt the ambient batch into the transaction, then make the
887
+ // transaction the batch so later registrations land there directly.
888
+ // Pending and optimistic nodes are re-stamped as the transaction's;
889
+ // marks don't hijack the node's _transition — a mark on a plain signal
890
+ // must not entangle unrelated writes to it; the same rule holds one hop
891
+ // downstream: propagation never queues pended subscribers as pending
892
+ // nodes, see propagateAffectsMark, #2893.
893
+ // Adopted outside a flush: the staging is still unflushed — the stamp
894
+ // must not make it read as held-and-carried (CONFIG_ADOPTED_UNFLUSHED;
895
+ // the carrying flush clears it in reassignPendingTransition).
896
+ const e = this.$t ? 0 : CONFIG_ADOPTED_UNFLUSHED;
897
+ for (let n = 0; n < t.In.length; n++) {
898
+ const i = t.In[n];
899
+ // A tick that nets to the committed value proposed nothing (A34, #3494):
900
+ // `setShow(false); setShow(true)` beside a write that opens a hold
901
+ // left `show` staged at its own value, stamped, pending to the
902
+ // verdict, and its next mainline write held by a flight it never
903
+ // derived from. Unstage it here — its subscribers were walked at the
904
+ // write and re-derive the same value. Writes only: a signal's staging
905
+ // is always one, a computed's only under REACTIVE_MANUAL_WRITE
906
+ // (`createSignal(fn)`'s setter, #3519 review) — otherwise it is its
907
+ // pass's result, which may equal an uninitialized `undefined` (a
908
+ // born-held first pass). `_equals: false` opts out. The unstaging is
909
+ // the commit's own path (commitPendingNode with nothing staged): the
910
+ // manual-write flag, companions and the rest are cleaned up as a
911
+ // commit would, and the node is stamped nowhere. Unstamped
912
+ // only: a node already a transaction's — arriving here as a parked
913
+ // batch folds into a merge — carries a FLUSHED proposal a later
914
+ // rewrite brought back to the committed value; it is held, not
915
+ // proposal-free. Dropped, it kept the dead stamp, and the next write
916
+ // to it queued under the merged transaction a value the commit then
917
+ // skipped as another's (fuzzer latest-2 #1470, S3).
918
+ if (i.me === null && i._e !== NOT_PENDING && (!i.Se || i.oe & REACTIVE_MANUAL_WRITE && !(i.S & STATUS_UNINITIALIZED)) && i.Fe && i.Fe(i.ce, i._e)) {
919
+ i._e = NOT_PENDING;
920
+ commitPendingNode(i);
921
+ continue;
922
+ }
923
+ i.me = activeTransition;
924
+ i.C |= e;
925
+ activeTransition.In.push(i);
926
+ }
927
+ for (let e = 0; e < t.bn.length; e++) {
928
+ const n = t.bn[e];
929
+ n.me = activeTransition;
930
+ activeTransition.bn.push(n);
931
+ }
932
+ if (t.A.length) activeTransition.A.push(...t.A);
933
+ for (const e of t.En) activeTransition.En.add(e);
934
+ // Gated readers recorded against the ambient batch move with it: their
935
+ // replay-at-commit now happens at the transaction's completion.
936
+ if (t.Tt.size) {
937
+ for (const e of t.Tt) activeTransition.Tt.add(e);
938
+ t.Tt.clear();
939
+ }
940
+ currentBatch = this.m = activeTransition;
941
+ }
942
+ for (const e of activeLanes) {
943
+ if (!e.me) e.me = activeTransition;
944
+ }
945
+ // A transaction's ambient window is one flush. Entering must therefore
946
+ // guarantee a flush: a transaction opened with no writes (an action whose
947
+ // first statements only await) otherwise leaves activeTransition and the
948
+ // adopted batch armed across the async gap, and the next unrelated work
949
+ // to arrive — an optimistic store's authoritative landing, a plain async
950
+ // settle — is adopted into a transaction it has nothing to do with
951
+ // (#3141). The scheduled flush parks the incomplete transaction through
952
+ // the normal machinery and detaches the ambient slots first.
953
+ schedule();
954
+ }
955
+ }
956
+
957
+ function queuePendingNode(e) {
958
+ currentBatch.In.push(e);
959
+ if (!globalQueue.$t) markUnflushedStaged();
960
+ // A28
961
+ }
962
+
963
+ // Sticky: flips true on the first refresh() ever (the only setter of
964
+ // REACTIVE_REASK) so the hot notification loop skips the per-subscriber flag
965
+ // clear entirely in apps that never refresh.
966
+ let reaskArmed = false;
967
+
968
+ /** §12d: bumped by every recompute and every new subscriber edge. A node's
969
+ * staged-rewrite skip is sound only while NOTHING recomputed or linked since
970
+ * its last notify — a mid-batch pull can clean a marked subscriber, and a
971
+ * skipped re-write would leave it stale. */ let notifyEpoch = 0;
972
+
973
+ function bumpNotifyEpoch() {
974
+ notifyEpoch++;
975
+ }
976
+
977
+ function armReaskClear() {
978
+ reaskArmed = true;
979
+ }
980
+
981
+ /** Provenance of the work currently running (A18 supersession, #3331): the
982
+ * invocation sequence of the action whose ambient window this is — set by
983
+ * action() for each slice; the flush that ends the window clears it — or,
984
+ * inside an async landing, the sequence captured when that flight was
985
+ * registered (asyncWrite sets it for the landing's synchronous propagation,
986
+ * so a sync recompute downstream of the landing — an optimistic wrapper over
987
+ * the async source — derives under the flight's provenance, and flights it
988
+ * registers inherit it). 0 is mainline: no action, always the current
989
+ * question. An override stamps this at its write (`_overrideStamp`); an
990
+ * answer whose flight an OLDER action issued is a stale question the user
991
+ * has since changed — it holds silently to commit instead of superseding. A
992
+ * slow source must not leak back in over a newer intent. Transactions merge,
993
+ * so the transition object cannot say WHICH action asked; this can. */ let origin = 0;
994
+
995
+ function setOrigin(e) {
996
+ const t = origin;
997
+ origin = e;
998
+ return t;
999
+ }
1000
+
1001
+ function insertSubs(e, t = false) {
1002
+ // §12d: stamp before walking — setSignal's staged-rewrite fast path skips
1003
+ // the next walk for this node while the epoch holds (marking is idempotent).
1004
+ e.Lt = notifyEpoch;
1005
+ // Get source lane: prefer node's own lane over current context
1006
+ // This is important for isPending signals which need their own lane to flush immediately
1007
+ // Presence bits gate the optional-slot probes (see constants.ts): one
1008
+ // masked read of the always-present _config instead of missing-property
1009
+ // lookups in the hottest notify loop. Bits are sticky — the field read
1010
+ // stays authoritative when a bit is set.
1011
+ const n = e.C;
1012
+ const i = (n & CONFIG_HAS_LANE ? e.o?.Ce : undefined) || currentOptimisticLane;
1013
+ const r = (n & CONFIG_HAS_SNAPSHOT) !== 0 && e.o?.ct !== undefined;
1014
+ const s = reaskArmed;
1015
+ // Observe-tier fan-out: this walk visits every subscriber edge anyway, so
1016
+ // the graph-size count is one local increment here and no field anywhere.
1017
+ let o = 0;
1018
+ for (let n = e.u; n !== null; n = n.Pe) {
1019
+ const e = n.Ae;
1020
+ o++;
1021
+ // A value-change notification is a new question for the subscriber: any
1022
+ // pending re-ask mark (refresh) it carried is superseded.
1023
+ if (s) e.oe &= ~REACTIVE_REASK;
1024
+ // Missed-wake latch (#3037): this write is landing while the subscriber
1025
+ // is mid-recompute (a nested pull committing beneath its reads), and the
1026
+ // heap refuses RECOMPUTING nodes. A gen-current link means the pass
1027
+ // already validated this dep — the value it read is now stale — so latch
1028
+ // for recompute's tail to reschedule. Untouched links need no latch (the
1029
+ // pass either re-reads them fresh or trims them), and neither does the
1030
+ // tail link: it is the read IN FLIGHT — read() links before it pulls, so
1031
+ // this very commit is what that read returns.
1032
+ if (e.oe & REACTIVE_RECOMPUTING_DEPS && n.Ze === e.We && n !== e.Je) e.oe |= REACTIVE_MISSED_WAKE;
1033
+ if (r && e.C & CONFIG_IN_SNAPSHOT_SCOPE) {
1034
+ e.oe |= REACTIVE_SNAPSHOT_STALE;
1035
+ continue;
1036
+ }
1037
+ if (t && i) {
1038
+ e.oe |= REACTIVE_OPTIMISTIC_DIRTY;
1039
+ assignOrMergeLane(e, i);
1040
+ } else if (t) {
1041
+ e.oe |= REACTIVE_OPTIMISTIC_DIRTY;
1042
+ // No source lane means reversion - clear subscriber's lane so effects go to regular queue
1043
+ if (e.o) e.o.Ce = undefined;
1044
+ }
1045
+ enqueueSub(e);
1046
+ }
1047
+ if (o >= GRAPH_SIZE_WARN_AT) noteFanOut(e, o);
1048
+ }
1049
+
1050
+ function commitPendingNode(e) {
1051
+ const t = e;
1052
+ if (!t.Se) {
1053
+ if (e._e !== NOT_PENDING) {
1054
+ e.ce = e._e;
1055
+ e._e = NOT_PENDING;
1056
+ }
1057
+ if (e.C & CONFIG_HAS_COMPANIONS) GlobalQueue.Qn(e);
1058
+ return;
1059
+ }
1060
+ if (e._e !== NOT_PENDING) {
1061
+ e.ce = e._e;
1062
+ e._e = NOT_PENDING;
1063
+ // A node born held (recompute) initializes at this commit.
1064
+ t.S &= ~STATUS_UNINITIALIZED;
1065
+ // Set _modified for effects, but not for tracked effects (they handle their own scheduling)
1066
+ if (e.He && e.He !== EFFECT_TRACKED) e.it = true;
1067
+ // A quiet re-ask classification preserved through a held landing dies
1068
+ // with the value commit — the commit IS the reveal (#3178). Gated on the
1069
+ // staged value: status propagation queues pending nodes whose windows
1070
+ // are still OPEN (no staged value), and their live classification must
1071
+ // survive this sweep.
1072
+ if (e.o) e.o.ve = false;
1073
+ }
1074
+ // The committed hold is the first observable answer for a loading-window
1075
+ // node — the window closes here, not at compute time (#2990). Unconditional
1076
+ // store to an always-present computed slot.
1077
+ t.ye = false;
1078
+ t.oe &= ~REACTIVE_MANUAL_WRITE;
1079
+ // The children this commit publishes are the frame's now (#3404) — and so
1080
+ // are the dependencies of the pass that produced the value: the previous
1081
+ // frame's tail goes (A30, #3410; `recompute` left it for a staged pass). Only
1082
+ // after a clean pass: `_error` is cleared by a clean pass or by the node's
1083
+ // own landing (whose pass was clean), so a set `_error` means the last pass
1084
+ // threw, kept its full list, and `_depsTail` marks where it stopped.
1085
+ if (t.o?._ == null) trimStaleDeps(t);
1086
+ // A LANE frame still parked here (#3662) rode a hold that stashed the run
1087
+ // that would have retired it: this commit applies that run, so it goes too.
1088
+ t.C &= -68157441;
1089
+ if (!(t.S & STATUS_PENDING)) t.S &= ~STATUS_UNINITIALIZED;
1090
+ // A flight this commit leaves in the air (unobserved, or observed only by
1091
+ // a boundary) now has PUBLISHED inputs: its committed value is stale
1092
+ // against the frame. read()'s reveal carve-out keys on the mark (#3305).
1093
+ else e.C |= CONFIG_INPUTS_PUBLISHED;
1094
+ if (t.o != null && (t.o.dt !== null || t.o.Et !== null)) GlobalQueue.ut(t, false, true);
1095
+ if (e.C & CONFIG_HAS_COMPANIONS) GlobalQueue.Qn(e);
1096
+ }
1097
+
1098
+ // Store commit hook (INTERNALS-STORE-STATE.md §3): installed by the store
1099
+ // module at init (same treeshakeable pattern as _resolveOptimistic /
1100
+ // _clearOptimisticStores). Folds committed store-node values into their
1101
+ // backing objects at the same moment pending values commit — the single
1102
+ // mutation point of the owned-raw model.
1103
+ let storeCommitHook = null;
1104
+
1105
+ function setStoreCommitHook(e) {
1106
+ storeCommitHook = e;
1107
+ }
1108
+
1109
+ /** Held truth committed this finalize, awaiting its post-revert wake (see
1110
+ * finalizePureQueue): the commit IS the reveal, but subscribers must not
1111
+ * re-derive until the settling transaction's optimistic overrides have
1112
+ * reverted — a commit-time wake recomputes them in the window where
1113
+ * confirming truth is committed and the override still displays, a torn
1114
+ * frame no timeline contains. */ const heldRevealed = [];
1115
+
1116
+ /** Unchanged passes with a stale dependency tail, waiting on this flush's
1117
+ * verdict (A30, #3469). A pass that changed nothing replaced nothing either —
1118
+ * and cannot know at its own tail whether the flush that ran it will park:
1119
+ * parked, its inputs are held and the committed frame still derives from the
1120
+ * tail (`b() ? b() : a()` computed `1` from the held `b`, equal to the `1` it
1121
+ * had from `a` — with `a` trimmed, the mainline `a = 2` never reached it).
1122
+ * Trimmed when the flush commits; dropped with a park, the tail stays linked
1123
+ * until a committing pass trims it (one spurious recompute at most). */ const heldTrims = [];
1124
+
1125
+ function commitPendingNodes() {
1126
+ while (heldTrims.length) trimStaleDeps(heldTrims.pop());
1127
+ const e = currentBatch.In;
1128
+ for (let t = 0; t < e.length; t++) {
1129
+ const n = e[t];
1130
+ commitPendingNode(n);
1131
+ // The stamp dies with the commit (#3143) — symmetric with
1132
+ // resolveOptimisticNodes clearing optimistic stamps. A stamp outliving
1133
+ // its transaction let any later write (even a value-equal no-op, which
1134
+ // re-opens before the equality bail) resurrect the finished transaction;
1135
+ // a boundary flag rewritten every finalize pass then spun the drain loop
1136
+ // forever (#3140). The held-truth mark dies the same death — the commit
1137
+ // IS the reveal — but its wake defers to the post-revert pass: ordinary
1138
+ // subscribers were masked to committed all hold (some re-derived against
1139
+ // that old view and cached it), and commits are otherwise silent
1140
+ // (staging already notified), so without a wake they'd hold the old
1141
+ // world forever.
1142
+ n.me = null;
1143
+ if (n.C & CONFIG_HELD_TRUTH) {
1144
+ n.C &= ~CONFIG_HELD_TRUTH;
1145
+ heldRevealed.push(n);
1146
+ }
1147
+ }
1148
+ e.length = 0;
1149
+ storeCommitHook?.();
1150
+ }
1151
+
1152
+ function finalizePureQueue(e = null, t = false) {
1153
+ // For incomplete transitions, skip pending resolution and optimistic reversion
1154
+ // For completing transitions or no-transition, resolve pending and revert optimistic
1155
+ const n = currentBatch;
1156
+ const i = !t;
1157
+ if (i) commitPendingNodes();
1158
+ // A parked finalize sweeps nothing: the boundaries' staged swaps are the
1159
+ // transaction's, and a boundary whose own output parks the verdict was
1160
+ // judged under it in run(), ahead of the verdict (#3540).
1161
+ if (!t && globalQueue.Xn.length) checkBoundaryChildren(globalQueue);
1162
+ // Contested effects (#3322) re-derive from the world this commit just
1163
+ // produced. Ahead of the heap run — not the post-heap gated replay — so
1164
+ // the recompute and the effect phase land in this same pass and the value
1165
+ // the other transaction wrote into the slot is never published.
1166
+ // (No clear: a completed transition is never finalized again.)
1167
+ // A transaction whose settle reverts optimism re-derives them post-revert
1168
+ // instead (below, with the gated replay): between commitPendingNodes and
1169
+ // _resolveOptimistic the truth is committed but the overrides still
1170
+ // display, and a re-derive here would compose the two — the #3164 tear,
1171
+ // one window later. The slot meanwhile holds the frame that is on screen.
1172
+ const r = e?.ht;
1173
+ const s = i && (e ?? n).bn.length !== 0;
1174
+ if (r && !s) for (const e of r) if (!(e.oe & REACTIVE_DISPOSED)) enqueueSub(e);
1175
+ const o = dirtyQueue.EE >= dirtyQueue.st;
1176
+ if (o) runHeap(dirtyQueue, GlobalQueue.nt);
1177
+ if (i) {
1178
+ // Boundary checks, commit hooks and recomputes can enter a transaction,
1179
+ // which adopts the batch this finalize was settling: nothing batch-derived
1180
+ // may be committed or reverted here — the entered transaction owns it now
1181
+ // (#3319). A completing transaction's OWN containers are a different
1182
+ // matter: when the ambient batch was separate from it (the #2916 shape),
1183
+ // adoption never touched them and it must still settle them; when the
1184
+ // batch WAS the completing transaction, adoption re-stamped its contents
1185
+ // into the entered one and there is nothing left to settle.
1186
+ if (currentBatch !== n) {
1187
+ if (e === null || e === n) return;
1188
+ } else if (o) commitPendingNodes();
1189
+ // The settling batch: the completing transaction's, or the ambient one.
1190
+ const t = e ?? n;
1191
+ // Optimistic reversion: a non-empty batch means _optimisticWrite ran,
1192
+ // which installed the engine's hooks.
1193
+ if (t.bn.length) GlobalQueue.Bn(t.bn);
1194
+ if (r && s) {
1195
+ for (const e of r) if (!(e.oe & REACTIVE_DISPOSED)) enqueueSub(e);
1196
+ schedule();
1197
+ }
1198
+ // Replay entanglement: subs recorded by the read-time gate get rescheduled
1199
+ // so they re-run with the now-committed values visible. The ambient batch
1200
+ // replays too — laneReadsCommitted records readers whose committed-view
1201
+ // read hid a same-tick plain write that just committed above (#2963).
1202
+ if (t.Tt.size) {
1203
+ for (const e of t.Tt) {
1204
+ if (e.oe & REACTIVE_DISPOSED) continue;
1205
+ enqueueSub(e);
1206
+ }
1207
+ t.Tt.clear();
1208
+ // A completing transition keeps the outer flush loop alive by itself;
1209
+ // the ambient batch needs the re-arm or the replay sits in the heap
1210
+ // until the next unrelated write.
1211
+ schedule();
1212
+ }
1213
+ // Declared motion ends with the transaction: settle (or plain flush end
1214
+ // for ambient marks) releases each registration's refcount. A non-empty
1215
+ // batch means registerAffectsMark ran, which installed the hook. Marks
1216
+ // held boundary display state through the visual channel, and their
1217
+ // release is the display-state update point — re-run the boundary sweep
1218
+ // (the earlier sweep above ran while the marks were still live).
1219
+ if (t.A.length) {
1220
+ GlobalQueue.G(t.A);
1221
+ if (globalQueue.Xn.length) checkBoundaryChildren(globalQueue);
1222
+ }
1223
+ // A non-empty set means trackOptimisticStore ran, which installed the
1224
+ // hook; the hook iterates, clears, and schedules (keeping the loop out of
1225
+ // core lets esbuild shake it — rollup already folds the null guard). The
1226
+ // completing transition scopes the clear to its own layer keys (#2899).
1227
+ if (t.En.size) GlobalQueue.ii(t.En, e);
1228
+ // Held-truth reveal wake (#3164), post-revert by construction: this
1229
+ // finalize committed confirming truth whose subscribers were masked all
1230
+ // hold — some re-derived against the committed view (the staging, or a
1231
+ // confirming carrier's landing, notified them as a plain write) and
1232
+ // cached it, and stash-restored applies may carry those torn values.
1233
+ // Waking and recomputing HERE — after _resolveOptimistic and the store
1234
+ // clears above — means every apply paints the settled view; a wake at
1235
+ // commit time would recompute them in the window where truth is
1236
+ // committed but the settling transaction's overrides still display.
1237
+ if (heldRevealed.length !== 0) {
1238
+ while (heldRevealed.length) insertSubs(heldRevealed.pop());
1239
+ if (dirtyQueue.EE >= dirtyQueue.st) {
1240
+ runHeap(dirtyQueue, GlobalQueue.nt);
1241
+ commitPendingNodes();
1242
+ }
1243
+ }
1244
+ sweepTransientStoreNodes();
1245
+ // Lanes only enter activeLanes through the engine's getOrCreateLane.
1246
+ if (activeLanes.size) GlobalQueue.Wn(e);
1247
+ }
1248
+ }
1249
+
1250
+ /** The boundary sweep: the commit's (`_checkSources`), or — `held`, before
1251
+ * the verdict (#3540) — the one for a collecting boundary whose output is
1252
+ * pending on its fallback's read (`_judgeHeld`). */ function checkBoundaryChildren(e, t) {
1253
+ for (const n of e.Xn) {
1254
+ t ? n.Re?.() : n.Te?.();
1255
+ checkBoundaryChildren(n, t);
1256
+ }
1257
+ }
1258
+
1259
+ /**
1260
+ * Count of live `affects()` registrations across the system (including
1261
+ * store-scope inherited marks). Gates the read-path mark check in `read()` so
1262
+ * graphs that never use the feature pay one integer compare.
1263
+ */ let activeAffectsMarks = 0;
1264
+
1265
+ /**
1266
+ * Counter mutation seam for the mark engine in affects.ts: an imported `let`
1267
+ * binding is read-only, and the read-path gate above must stay a plain module
1268
+ * variable so `read()` pays one integer compare, not a function call.
1269
+ *
1270
+ * @internal
1271
+ */ function shiftAffectsMarks(e) {
1272
+ activeAffectsMarks += e;
1273
+ }
1274
+
1275
+ function reassignPendingTransition(e) {
1276
+ for (let t = 0; t < e.length; t++) {
1277
+ e[t].me = activeTransition;
1278
+ e[t].C &= ~CONFIG_ADOPTED_UNFLUSHED;
1279
+ // this flush carried it
1280
+ }
1281
+ }
1282
+
1283
+ const globalQueue = new GlobalQueue;
1284
+
1285
+ // Hot-path mirror of `globalQueue._batch`: `queuePendingNode` runs once per
1286
+ // staged write and `commitPendingNodes` once per flush, and the extra
1287
+ // property hop through `_batch` was a measured instruction-count regression
1288
+ // (CodSpeed update1to1, PR #2905). The field stays authoritative for
1289
+ // cross-module readers; every `_batch` assignment updates both.
1290
+ let currentBatch = globalQueue.m;
1291
+
1292
+ function flush(e) {
1293
+ // Inside an action body the drain is incoherent (#3333): the action's
1294
+ // writes are held by its transaction until it settles, so a drain can't
1295
+ // reveal them — and the loop below only exits once `activeTransition` is
1296
+ // null, so it would PARK the transaction mid-slice and every write after it
1297
+ // in the body would land as a plain, committed write. The reporter's
1298
+ // "leading flush()" workaround was exactly that leak. Prod: run `fn` if
1299
+ // given (its writes stay in the transaction) and skip the drain.
1300
+ if (actionStepDepth > 0) {
1301
+ return e ? e() : undefined;
1302
+ }
1303
+ if (e) {
1304
+ syncDepth++;
1305
+ try {
1306
+ return e();
1307
+ } finally {
1308
+ // Decrement even if the drain throws (a throwing effect): a leaked
1309
+ // syncDepth would stop `schedule()` from ever queuing a microtask again.
1310
+ try {
1311
+ flush();
1312
+ } finally {
1313
+ syncDepth--;
1314
+ }
1315
+ }
1316
+ }
1317
+ if (globalQueue.$t) {
1318
+ return;
1319
+ }
1320
+ if (halted) return;
1321
+ // Attribution: whether this call drained anything, so `flushEnd` fires once
1322
+ // per real drain and never for a no-op call. The declaration is dead in
1323
+ // prod (its only write is behind true) and rollup drops it.
1324
+ let t = false;
1325
+ // The drain's opening instant, under the loop's own condition so it fires
1326
+ // exactly when `flushEnd` below will. Outside every try (see the rule in
1327
+ // attribution-hooks.ts).
1328
+ if (attrHooks !== null && (scheduled || activeTransition)) attrHooks.flushStart();
1329
+ // `flush()` is an explicit drain point, so it must also process an active
1330
+ // transition even if no microtask was scheduled for it yet.
1331
+ while (scheduled || activeTransition) {
1332
+ globalQueue.flush();
1333
+ t = true;
1334
+ }
1335
+ // Provenance ends with the drain: every ambient window (an action's first
1336
+ // slice, a landing's propagation) runs to this flush.
1337
+ origin = 0;
1338
+ // Outside every try in this function (see the rule in attribution-hooks.ts):
1339
+ // the drain loop above is the one place all scheduled work funnels through,
1340
+ // so this is the "committed and effects ran, or parked" instant for
1341
+ // everything the loop processed.
1342
+ if (t && attrHooks !== null) attrHooks.flushEnd();
1343
+ }
1344
+
1345
+ function runQueue(e, t) {
1346
+ for (let n = 0; n < e.length; n++) e[n](t);
1347
+ }
1348
+
1349
+ /** Does `reporter` still hold the transaction waiting on `source` — live,
1350
+ * routed to no collecting loading boundary, and deriving from the source in
1351
+ * its current pass? The verdict's per-reporter test (sourceObserved), also
1352
+ * a boundary re-arm's (boundaries.ts `_rearm` runs before the verdict prunes
1353
+ * registrations that stopped counting). */ function reporterBlocksSource(e, t, n) {
1354
+ const i = e.oe;
1355
+ if (i & REACTIVE_DISPOSED) return false;
1356
+ // A zombie renders until the commit that disposes it (#3463): while its
1357
+ // removal is staged in a live transaction it is still on screen, and what
1358
+ // it displays must stay consistent with the frame — a held `Show`'s
1359
+ // `Details: 0` beside the lane's `Value: 1` otherwise. Its say is moot for
1360
+ // the verdict of the transaction that stages the removal (`verdict`): done,
1361
+ // and the commit disposes it; not done, and it stays parked regardless. A
1362
+ // zombie whose removal commits this flush (owner's pass not held) is dead.
1363
+ // The owner is stamped when the flush parks; held in this flush, its
1364
+ // staging transaction is the active one.
1365
+ if (i & REACTIVE_ZOMBIE) {
1366
+ let t = e;
1367
+ while (t && t.oe & REACTIVE_ZOMBIE) t = t._parent;
1368
+ let i = t && (t.me || (t.C & CONFIG_HELD_CHILDREN ? activeTransition : null));
1369
+ // A LANE frame's member (#3662) is displayed until its owner's run
1370
+ // applies, and the lane's transaction is what applies it (its completion
1371
+ // runs the lane's queue): moot for that verdict, live for every other.
1372
+ if (!i && t && t.C & CONFIG_LANE_FRAME && t.o?.Ce) i = findLane(t.o.Ce).me;
1373
+ if (!i || (i = currentTransition(i)).Dt === true || i === n) return false;
1374
+ }
1375
+ // Fallback-caught async holds nothing. A collecting loading boundary
1376
+ // consumes the notification, so a reader under a fallback never registers —
1377
+ // but a reader registered while its boundary showed content stays
1378
+ // registered when the boundary's `on` later changes and it flips to the
1379
+ // fallback. The reader is behind the fallback now; if nothing outside the
1380
+ // boundary consumes the flight, the hold is over (A33, ruled 2026-09-12, #3375).
1381
+ for (let t = e.T; t; t = t._parent) if (t.te & STATUS_PENDING && !t.H) return false;
1382
+ // "Still derives from the source" is a question about THIS pass's reads:
1383
+ // the deps up to `_depsTail`. Past it lie the committed frame's — kept
1384
+ // linked by A30 until the commit trims them (a staged pass, an errored
1385
+ // one). Reading them here made a reporter whose pass had stopped reading
1386
+ // the source (a gate closed in the same flush as the write) look live, and
1387
+ // the hold it kept was the commit that would have trimmed the dep that
1388
+ // kept it (spec O3, same-flush form; fuzzer #3446 P1 cases 21/79). A
1389
+ // trimmed list ends at `_depsTail`, so the bound is free there; a pass
1390
+ // that read nothing has a null tail and derives from nothing.
1391
+ // The registration is trusted: a pending mark rides only this pass's links
1392
+ // (notifyStatus skips the kept tail), so a registered reporter read the
1393
+ // source, or threw on it.
1394
+ if (e.o?.ue?.has(t)) return true;
1395
+ const r = e.Je;
1396
+ for (let n = r === null ? null : e.Ee; n; n = n === r ? null : n.Ie) {
1397
+ let e = n.De;
1398
+ while (e) {
1399
+ // Or through a memo pending on the flight (#3494): a stale reader
1400
+ // served a held memo's committed value never turned pending itself, so
1401
+ // its only trace of the flight is the memo between them — `copy` of
1402
+ // `details`. Judged dead, its transaction released `count=1` beside
1403
+ // the `Copy: 0` it displays. `_pendingSources` is transitive, so one
1404
+ // hop covers any depth.
1405
+ if (e === t || e.Ne === t || e.o?.ue?.has(t)) return true;
1406
+ e = e.o?.$n;
1407
+ }
1408
+ }
1409
+ return !!(e.S & STATUS_PENDING && e.o?._ instanceof NotReadyError && e.o?._.source === t);
1410
+ }
1411
+
1412
+ /**
1413
+ * Does a live reporter of `transition` still observe `source` pending? Dead
1414
+ * reporters (disposed, behind a fallback, no longer reading the source) are
1415
+ * pruned as they are found, and the source's entry with them. Shared by the
1416
+ * settle verdict and the lane's hold check (`waitingTransition`): a live
1417
+ * action parks its transaction without a verdict, so this prune is the only
1418
+ * one an optimistic lane whose last async reader unmounted mid-action ever
1419
+ * gets — without it the lane held on the dead reporter's registration until
1420
+ * the flight it no longer observed landed (#3426).
1421
+ */ function sourceObserved(e, t, n) {
1422
+ const i = e.ae.get(t);
1423
+ let r = false;
1424
+ for (const e of i ?? []) {
1425
+ if (reporterBlocksSource(e, t, n)) return true;
1426
+ // A zombie the verdict passes over is kept, not pruned (#3463): moot for
1427
+ // this verdict, it still holds a lane's reveal while the transaction
1428
+ // stays parked on something else.
1429
+ if (n && e.oe & REACTIVE_ZOMBIE) r = true; else i.delete(e);
1430
+ }
1431
+ if (!r) e.ae.delete(t);
1432
+ return false;
1433
+ }
1434
+
1435
+ function transitionComplete(e) {
1436
+ if (e.Dt) return true;
1437
+ if (e.tt.length) {
1438
+ // A live action parks the transaction regardless of async state.
1439
+ if (attrHooks !== null) attrHooks.holdStart(e);
1440
+ return false;
1441
+ }
1442
+ let t = true;
1443
+ for (const n of e.ae.keys()) {
1444
+ // The source blocks while its OWN flight is up — the self entry in its
1445
+ // pending sources (added by notifyStatus's source path, with status;
1446
+ // retired by the landing and the supersede sweep, so it implies
1447
+ // STATUS_PENDING). `_error.source` is not that test: propagation from an
1448
+ // input that went pending later overwrites it with the input (#3375 — a
1449
+ // boundary-consumed load re-asked under a held derivation), and the
1450
+ // still-flying source read as settled, committing the writes it was
1451
+ // asked with ahead of its answer.
1452
+ // Not the self entry alone: a source whose own flight an upstream re-ask
1453
+ // superseded is still pending — on that re-ask (#3462). Its reader cannot
1454
+ // render until the chain lands, and the landing folds this transaction in
1455
+ // (enterWaiting). Judged complete instead, a re-entry between the two (a
1456
+ // repeated write to a held signal) committed the held writes beside the
1457
+ // reader's stale frame.
1458
+ if (sourceObserved(e, n, e) && n.o?.ue?.size) {
1459
+ t = false;
1460
+ break;
1461
+ }
1462
+ }
1463
+ // Override blockage lives with the engine (absent hook = "no optimistic
1464
+ // blockage"); the hook's loops over _optimisticNodes/_optimisticStores are
1465
+ // no-ops when the transition holds neither, so no pre-check is needed.
1466
+ if (t && GlobalQueue.Yn?.(e)) t = false;
1467
+ // Attribution hook: this verdict is the fork between settling (held writes
1468
+ // commit next — `_pendingNodes` still lists them) and parking (the flush
1469
+ // runs the lane effects, then stashes; `holdEnd` fires from stashQueues).
1470
+ // Fired here rather than at flush()'s call site because that site is inside
1471
+ // a `try` (see the rule in attribution-hooks.ts).
1472
+ if (attrHooks !== null) t ? attrHooks.transitionSettled(e) : attrHooks.holdStart(e);
1473
+ t && (e.Dt = true);
1474
+ return t;
1475
+ }
1476
+
1477
+ /** A fresh, unentered transaction (#3146): the optimistic store's truth
1478
+ * flight DECLARES an owned transaction instead of relying on whatever the
1479
+ * ambient adoption machinery stamped on its firewall. Activate it with
1480
+ * initTransition; it is a plain batch until then. */ function createTransition() {
1481
+ return createBatch();
1482
+ }
1483
+
1484
+ function currentTransition(e) {
1485
+ while (e.Dt && typeof e.Dt === "object") e = e.Dt;
1486
+ return e;
1487
+ }
1488
+
1489
+ /**
1490
+ * The live transition blocked on `source` — the one whose render reader
1491
+ * observed it pending (INV-3 records the observation in whichever transaction
1492
+ * was active when the reader was notified). The observation is a fact about
1493
+ * the node, so a hold check must not assume it was recorded in the transaction
1494
+ * it happens to hold — lanes merge across transactions (#2912), and a merged
1495
+ * root's transaction knows nothing of the async its members' transactions
1496
+ * observed (#3335). Null when nobody is waiting — a registration whose every
1497
+ * reporter has since died is nobody (#3426).
1498
+ */ function waitingTransition(e) {
1499
+ for (const t of transitions) if (sourceObserved(t, e)) return t;
1500
+ return null;
1501
+ }
1502
+
1503
+ /** A landing enters EVERY parked transaction still waiting on `source`, folding
1504
+ * them into the active one (A15: each reveal that discovered the flight
1505
+ * completes at its landing). The fold used to happen as the waiters' stamped
1506
+ * readers recomputed under the landing — recompute re-entering an effect's
1507
+ * stamp — which also folded in writes those readers merely shared a hole
1508
+ * with (#3407); effects no longer re-enter, so the landing folds explicitly.
1509
+ * Live iteration is safe: a merge deletes the outgoing (active) entry and
1510
+ * re-adds the visited one. */ function enterWaiting(e) {
1511
+ for (const t of transitions) if (sourceObserved(t, e)) globalQueue.initTransition(t);
1512
+ }
1513
+
1514
+ function runInTransition(e, t) {
1515
+ const n = activeTransition;
1516
+ try {
1517
+ activeTransition = currentTransition(e);
1518
+ return t();
1519
+ } finally {
1520
+ activeTransition = n;
1521
+ }
1522
+ }
1523
+
1524
+ /** Run `fn` with `transition` as BOTH the ambient transaction and the
1525
+ * registration batch, restoring both after. runInTransition alone is not
1526
+ * enough for code that WRITES on behalf of a transaction from inside someone
1527
+ * else's window (optimistic replay re-arming a still-open action's edits
1528
+ * during a landing commit, #3123): registrations route through the queue's
1529
+ * batch pointer, and a bare activeTransition swap leaves them in the ambient
1530
+ * batch — a plain batch "completes" at the next flush and reverts optimistic
1531
+ * registrations that were supposed to live with the transaction.
1532
+ * initTransition is the wrong tool here: it MERGES the currently ambient
1533
+ * transaction into the target, entangling whatever the interrupted window
1534
+ * belonged to. */ function runAsTransitionBatch(e, t) {
1535
+ const n = activeTransition;
1536
+ const i = globalQueue.m;
1537
+ try {
1538
+ activeTransition = currentTransition(e);
1539
+ currentBatch = globalQueue.m = activeTransition;
1540
+ return t();
1541
+ } finally {
1542
+ activeTransition = n;
1543
+ currentBatch = globalQueue.m = i;
1544
+ }
1545
+ }
1546
+
1547
+ export { GlobalQueue, Queue, ROOT_ERROR_HOOK, actionStepDepth, activeAffectsMarks, activeLanes, activeTransition, armReaskClear, assignOrMergeLane, batchJoins, bumpNotifyEpoch, clock, createTransition, currentTransition, deferSlotRelease, dirtyQueue, enforceLoadingBoundary, entangleConfirmingTransitions, enterActionStep, enterWaiting, exitActionStep, finalizePureQueue, findLane, flush, globalQueue, haltReactivity, hasActiveOverride, heldTrims, insertSubs, notifyEpoch, origin, pendingRearms, projectionWriteActive, queuePendingNode, queueRearm, reaskArmed, reporterBlocksSource, resetErrorHalt, runAsTransitionBatch, runInTransition, schedule, scheduleWithheld, setOrigin, setProjectionWriteActive, setStoreCommitHook, shiftAffectsMarks, sourceObserved, storeCommitHook, transitions, waitingTransition, wakeParked, wokenTransitions, zombieQueue };