@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
@@ -1,14 +1,14 @@
1
- import { NOT_PENDING, unwrapOverride, STATUS_UNINITIALIZED, REACTIVE_DIRTY, REACTIVE_CHECK, CONFIG_HAS_LANE, OVERRIDE_UNDEFINED, STATUS_PENDING, EFFECT_RENDER, REACTIVE_MANUAL_WRITE, REACTIVE_OPTIMISTIC_DIRTY, EFFECT_USER } from "./constants.js";
1
+ import { NOT_PENDING, unwrapOverride, STATUS_UNINITIALIZED, REACTIVE_DIRTY, REACTIVE_CHECK, CONFIG_HAS_LANE, OVERRIDE_UNDEFINED, STATUS_PENDING, CONFIG_DERIVED_OVERRIDE, CONFIG_OPTIMISTIC, CONFIG_OVERRIDE_SUPERSEDED, EFFECT_RENDER, CONFIG_AUTHORITATIVE_OBSERVED, REACTIVE_MANUAL_WRITE, REACTIVE_OPTIMISTIC_DIRTY, LANE_RUN, EFFECT_USER } from "./constants.js";
2
2
 
3
- import { ext, latestReadActive, currentOptimisticLane, stale } from "./core.js";
3
+ import { ext, hasActiveOverride, stale, enterStagedRead, latestReadActive, currentOptimisticLane } from "./core.js";
4
4
 
5
5
  import { NotReadyError } from "./error.js";
6
6
 
7
7
  import "./invariants.js";
8
8
 
9
- import { resolveTransition, getOrCreateLane, hasActiveOverride, activeLanes, signalLanes, laneHeld, findLane, resolveLane, assignOrMergeLane } from "./lanes.js";
9
+ import { resolveTransition, getOrCreateLane, activeLanes, signalLanes, laneHeld, findLane, resolveLane, readsHeldCommitted, assignOrMergeLane } from "./lanes.js";
10
10
 
11
- import { GlobalQueue, activeTransition, globalQueue, clock, insertSubs, schedule } from "./scheduler.js";
11
+ import { GlobalQueue, activeTransition, globalQueue, origin, clock, insertSubs, schedule, sourceObserved, currentTransition, queuePendingNode } from "./scheduler.js";
12
12
 
13
13
  /**
14
14
  * The optimistic write engine, moved out of core.ts/scheduler.ts. Everything
@@ -24,60 +24,122 @@ import { GlobalQueue, activeTransition, globalQueue, clock, insertSubs, schedule
24
24
  * once the gate holds — the same late-binding contract as verdict.ts.
25
25
  */
26
26
  /** The optimistic half of setSignal, fired when `_overrideValue !== undefined`. */ function optimisticWrite(e, n) {
27
- const t = e.o?.Pe !== NOT_PENDING;
28
- const i = t ? unwrapOverride(e.o?.Pe) : e.be;
29
- if (typeof n === "function") n = n(i);
30
- const u = !!(e.S & STATUS_UNINITIALIZED) ||
27
+ const i = e.o?.Ce !== NOT_PENDING;
28
+ const t = i ? unwrapOverride(e.o?.Ce) : e.Qe;
29
+ if (typeof n === "function") n = n(t);
30
+ const r = !!(e.S & STATUS_UNINITIALIZED) ||
31
31
  // A dirty node's _value is stale (its queued recompute hasn't run — e.g.
32
32
  // a latest() shadow marked by the previous landing's companion snap), so
33
33
  // equality against it must not swallow the write. Without this, a sync
34
34
  // push returning the shadow to that stale value was dropped, the snap
35
35
  // recompute then committed the parent's old value, and the banner showed
36
36
  // the previous transition's target (#3041 follow-up).
37
- !!((e.ie ?? 0) & (REACTIVE_DIRTY | REACTIVE_CHECK)) || !e.pe || !e.pe(i, n);
38
- if (!u) {
37
+ !!((e.ue ?? 0) & (REACTIVE_DIRTY | REACTIVE_CHECK)) || !e.Fe || !e.Fe(t, n);
38
+ if (!r) {
39
39
  // Same-value write with an active override still entangles the current
40
- // action's transition — the hold must outlast all overlapping actions.
41
- if (t) {
40
+ // action's transition — the hold must outlast all overlapping actions
41
+ // and renews the override's PROVENANCE: the newer action re-asks the
42
+ // question, so an older action's answer arriving later is stale to it
43
+ // too (#3331; a same-value re-prediction otherwise let the first
44
+ // action's slow source supersede and restart the downstream flight).
45
+ if (i) {
42
46
  const n = resolveTransition(e);
43
47
  if (n && activeTransition !== n) globalQueue.initTransition(n);
48
+ if (origin > e.o.vt) e.o.vt = origin;
44
49
  }
45
50
  return n;
46
51
  }
47
- if (t) globalQueue.initTransition(resolveTransition(e));
52
+ if (i) globalQueue.initTransition(resolveTransition(e));
48
53
  // No revert target is stashed: while the override is active every reader
49
54
  // sees it (A17), so authoritative arrivals commit silently into _value and
50
55
  // reverting is just dropping the override — _value is already correct.
51
- else globalQueue.m.Xe.push(e);
56
+ else globalQueue.m.rt.push(e);
52
57
  // Stamp ownership on the node (post-merge, so entangled writers share the
53
58
  // joint root). resolveTransition prefers this over the lane's _transition,
54
59
  // which a shared subscriber can merge across transactions (#2912).
55
- ext(e).Tt = activeTransition;
56
- const r = getOrCreateLane(e);
57
- ext(e).$e = r;
58
- e.T |= CONFIG_HAS_LANE;
60
+ ext(e).Ft = activeTransition;
61
+ ext(e).Ct = clock;
62
+ // Provenance: the action asking. An answer an OLDER action's flight brings
63
+ // back is a stale question and holds silently to commit (#3331).
64
+ ext(e).vt = origin;
65
+ const u = getOrCreateLane(e);
66
+ ext(e).Ue = u;
67
+ // A fresh override re-masks: whatever truth is staged, this write is the
68
+ // value for the graph again until the source answers it (#3331).
69
+ e.T = (e.T | CONFIG_HAS_LANE) & -8912897;
59
70
  // Literal undefined must not land raw: the slot doubles as the optimistic
60
71
  // brand, and erasing it makes the write invisible and routes follow-up
61
72
  // writes off the optimistic path into permanent commits (#2898).
62
- ext(e).Pe = n === undefined ? OVERRIDE_UNDEFINED : n;
73
+ ext(e).Ce = n === undefined ? OVERRIDE_UNDEFINED : n;
63
74
  // syncCompanions only pokes _pendingSignal/_latestValueComputed — with
64
75
  // neither companion present the call is a guaranteed no-op.
65
- (e.o?.ye !== undefined || e.o?.Ce !== undefined) && GlobalQueue.Ue !== null && GlobalQueue.Ue(e, n);
66
- if (e.oe !== undefined) e.Te = clock;
76
+ (e.o?.je !== undefined || e.o?.xe !== undefined) && GlobalQueue.me !== null && GlobalQueue.me(e, n);
77
+ if (e.ce !== undefined) e.Pe = clock;
67
78
  // §12e: computed-only slot
68
79
  insertSubs(e, true);
69
80
  schedule();
70
81
  return n;
71
82
  }
72
83
 
84
+ /**
85
+ * Lanes stage (#3479): a lane pass's publish for a memo. An optimistic
86
+ * derivation is an override — the speculative result lives in the override
87
+ * slot, `_value` stays the committed truth. The whole optimistic frame is then
88
+ * in one place: the lane's readers and untracked reads see it (A17), a render
89
+ * effect off the held lane sees the committed frame whole (readsHeldCommitted,
90
+ * #3460) — the source's shadow AND its derivations — where a speculative
91
+ * `_value` beside a committed shadow tore it. The node joins the
92
+ * transaction's optimistic nodes on its first speculative publish; the revert
93
+ * drops the override and re-derives it from the truth (a derived override has
94
+ * no truth of its own — see resolveOptimisticNodes, endOptimism).
95
+ */ function laneOverride(e, n, i) {
96
+ // The wake-only channel (#3009, see recomputeLane): a plain write to a
97
+ // latest()-tracked source rides a companion-sourced lane with no
98
+ // transaction on either side only to wake the verdict companions. Nothing
99
+ // is speculative — the pass commits directly, as any plain write does.
100
+ i = findLane(i);
101
+ if (!i.Ge && !activeTransition && i.an.o?.Ht !== undefined) {
102
+ e.Qe = n;
103
+ return;
104
+ }
105
+ if (!hasActiveOverride(e)) {
106
+ // It reverts with the lane's transaction (a landing runs outside any
107
+ // flush, where the ambient batch would revert it at its own end); an
108
+ // orphan lane's falls to the batch, adopted with it (initTransition) as a
109
+ // write's is. No `_overrideOwner`: a derived override is a plain member,
110
+ // its transaction its lane's (resolveTransition), and it merges lanes
111
+ // through itself as any shared reader does (assignOrMergeLane). No
112
+ // provenance stamp either: not an intent, any truth supersedes it.
113
+ (i.Ge ? currentTransition(i.Ge) : globalQueue.m).rt.push(e);
114
+ }
115
+ // A lane pass's output is a derivation — also over a WRITTEN guess it
116
+ // corrects (a `createOptimistic(fn)` re-derived from fresh upstream data):
117
+ // the guess is gone, the slot holds fn's answer, and the revert promotes it
118
+ // rather than dropping to a stale `_value` and re-asking downstream (the
119
+ // next user write re-arms the guess: optimisticWrite clears the bit). No
120
+ // `_overrideTime` stamp: that marks a user WRITE unflushed until the flush
121
+ // that carries it (A28) and shields it from same-tick supersession — a pass's
122
+ // result is neither (a pulled ownerless memo publishes outside any flush).
123
+ // A fresh lane frame ends a supersession in force: the pass just dropped
124
+ // the staged truth it pointed at (recompute, INV-11 corollary) — left set,
125
+ // the flag served a `_value` never committed (fuzzer latest-1 #2481).
126
+ e.T = (e.T | CONFIG_DERIVED_OVERRIDE) & ~CONFIG_OVERRIDE_SUPERSEDED;
127
+ e.o.Ce = n === undefined ? OVERRIDE_UNDEFINED : n;
128
+ }
129
+
73
130
  /**
74
131
  * transitionComplete's override blockage: a settling transition stays open
75
132
  * while one of its optimistic nodes holds an active override that is still
76
- * pending on real (non-affects-sentinel) async.
133
+ * pending on real (non-affects-sentinel) async. A derived override's flight is
134
+ * the lane's own work, never authoritative — it does not hold the settle.
135
+ * Neither is a companion's (#3494): the `latest()` shadow backfilled under the
136
+ * owner's transaction (A28 (3)) is an observation of the flight, and a
137
+ * mainline `latest(details)` after the flight's last reader unmounted held the
138
+ * released write until the orphaned request landed.
77
139
  */ function transitionBlocked(e) {
78
- for (let n = 0; n < e.Xe.length; n++) {
79
- const t = e.Xe[n];
80
- if (hasActiveOverride(t) && "S" in t && t.S & STATUS_PENDING && t.o?._ instanceof NotReadyError) {
140
+ for (let n = 0; n < e.rt.length; n++) {
141
+ const i = e.rt[n];
142
+ if (!(i.T & CONFIG_DERIVED_OVERRIDE) && i.o?.Ht === undefined && hasActiveOverride(i) && "S" in i && i.S & STATUS_PENDING && i.o?._ instanceof NotReadyError) {
81
143
  return true;
82
144
  }
83
145
  }
@@ -89,33 +151,226 @@ function resolveOptimisticNodes(e) {
89
151
  // notifications) may push fresh optimistic nodes; only this batch settles
90
152
  // now, so iterate a fixed window and splice it out at the end.
91
153
  const n = e.length;
92
- for (let t = 0; t < n; t++) {
93
- const n = e[t];
94
- if (n.o !== null) n.o.$e = undefined;
154
+ for (let i = 0; i < n; i++) {
155
+ const n = e[i];
156
+ if (n.o !== null) n.o.Ue = undefined;
95
157
  // Revert is a pure drop: there is no revert target to commit —
96
158
  // override-covered authoritative values hold in _pendingValue and
97
159
  // elevate on their OWN transition's schedule (A18 as re-ruled 2026-07-07).
98
160
  if (!(n.S & STATUS_PENDING)) n.S &= ~STATUS_UNINITIALIZED;
99
- const i = n.o?.Pe;
100
- ext(n).Pe = NOT_PENDING;
101
- if (i !== NOT_PENDING && n.be !== unwrapOverride(i)) insertSubs(n, true);
102
- n.Ae = null;
103
- if (n.o !== null) n.o.Tt = null;
161
+ const t = n.o?.Ce;
162
+ // A derived override (lanes stage, #3479) has no truth of its own: the
163
+ // slot disarms the memo is plain again — and the override PROMOTES to
164
+ // `_value`. Not superseded, nothing it derives from told it otherwise
165
+ // (a source override that reverts to a differing truth dirties it just
166
+ // above — sources join this list before their derivations — and its
167
+ // recompute then replaces the promotion), so by the graph's invariant
168
+ // the override IS what a recompute from the truth yields. Re-deriving
169
+ // instead re-asked an async member's flight and held the transaction on
170
+ // it — a waterfall after the reveal.
171
+ const r = n.T & CONFIG_DERIVED_OVERRIDE;
172
+ ext(n).Ce = r && !(n.T & CONFIG_OPTIMISTIC) ? undefined : NOT_PENDING;
173
+ // A superseded override's subscribers already re-derived from the truth
174
+ // when it arrived (#3331) — the drop changes nothing they read. Everyone
175
+ // else learns of the correction here: this drop IS their notification.
176
+ const u = (n.T & CONFIG_OVERRIDE_SUPERSEDED) !== 0;
177
+ n.T &= -8912897;
178
+ if (!u && t !== NOT_PENDING && n.Qe !== unwrapOverride(t)) {
179
+ if (r) n.Qe = unwrapOverride(t); else insertSubs(n, true);
180
+ }
181
+ n.Ge = null;
182
+ if (n.o !== null) n.o.Ft = null;
104
183
  }
105
184
  // Settlement checkpoint (#2838): companions caught in this batch (or owned
106
185
  // by a node in it) re-derive from committed state, so verdicts survive the
107
186
  // transition that produced them (A19 — pending is a property of the data).
108
- for (let t = 0; t < n; t++) {
109
- const n = e[t];
110
- if (n.o?.ye || n.o?.Ce) GlobalQueue.un(n);
111
- const i = n.o?.St;
112
- if (i && (i.o?.ye === n || i.o?.Ce === n)) GlobalQueue.un(i);
187
+ for (let i = 0; i < n; i++) {
188
+ const n = e[i];
189
+ if (n.o?.je || n.o?.xe) GlobalQueue.En(n);
190
+ const t = n.o?.Ht;
191
+ if (t && (t.o?.je === n || t.o?.xe === n)) GlobalQueue.En(t);
113
192
  }
114
193
  e.splice(0, n);
115
194
  }
116
195
 
196
+ /**
197
+ * A18 supersession (#3331): the node's own source arrived with a value that
198
+ * differs from its active override. "Knowing otherwise" ends the optimism for
199
+ * the graph at once: the override stays only as the DISPLAYED value (untracked
200
+ * reads, the applied frame) until the owning transaction commits, while
201
+ * tracked readers see the staged truth and re-derive from it as that
202
+ * transaction's held work — so async downstream restarts now, not at the
203
+ * revert (no waterfall).
204
+ *
205
+ * The lane's job for this node is over: a lane applies an optimistic view
206
+ * ahead of its transaction, and there is no optimistic view left — the
207
+ * corrected cascade is plain transaction-held work (staged memos, effect runs
208
+ * in the stashable queues). Demote the node and every cascade member that
209
+ * rides this lane; the caller then notifies on the plain channel. Runners the
210
+ * lane still holds for demoted effects (the optimistic frame that never got to
211
+ * apply) defer to the regular queue in runEffect. In a lane merged with a
212
+ * still-optimistic source, members shared with that source lose their lane
213
+ * too and simply wait for the transaction — less optimistic, never torn.
214
+ *
215
+ * A later arrival EQUAL to the override (an earlier action's answer superseded
216
+ * this one's; now this one's answer confirms it) ends the supersession: the
217
+ * graph re-derives from the override, which is the truth again. Notifies the
218
+ * subscribers in both cases. A plain matching confirmation (no supersession
219
+ * in force) is A17-silent for ordinary subscribers and wakes only an
220
+ * authoritative-view reader (until()'s predicate, refresh()'s waiter) that
221
+ * observed this node past its override — "authoritative arrival equal to the
222
+ * override" is exactly the acknowledgment it waits for (#3164, #3303). The
223
+ * wake hook is installed by the setters of that bit; optional here because
224
+ * the bit only implies the optimistic engine was consulted.
225
+ */ function supersedeOverride(e, n) {
226
+ const i = !e.Fe || !e.Fe(n, unwrapOverride(e.o.Ce));
227
+ if (!i) {
228
+ if (!(e.T & CONFIG_OVERRIDE_SUPERSEDED)) {
229
+ if (e.T & CONFIG_AUTHORITATIVE_OBSERVED) GlobalQueue.Zt?.(e);
230
+ return;
231
+ }
232
+ e.T &= ~CONFIG_OVERRIDE_SUPERSEDED;
233
+ } else {
234
+ // Provenance (#3331): an answer brought back by an OLDER action than the
235
+ // one that wrote this override answers a question the user has since
236
+ // changed. It is staged like any other landing and reveals if it is
237
+ // still the truth when the transaction commits, but it does not move the
238
+ // graph now — a slow source must not leak back in over a newer intent.
239
+ // 0 is mainline (no action): always the current question.
240
+ if (origin && origin < e.o.vt) return;
241
+ e.T |= CONFIG_OVERRIDE_SUPERSEDED;
242
+ const n = e.o?.Ue;
243
+ if (n) {
244
+ const i = findLane(n);
245
+ const t = [ e ];
246
+ while (t.length) {
247
+ const e = t.pop();
248
+ const n = e.o?.Ue;
249
+ if (!n || findLane(n) !== i) continue;
250
+ e.o.Ue = undefined;
251
+ i.ye.delete(e);
252
+ for (let n = e.u; n !== null; n = n.Ne) t.push(n._e);
253
+ }
254
+ }
255
+ }
256
+ insertSubs(e);
257
+ }
258
+
259
+ /**
260
+ * The flush's pre-verdict step once the action bodies have ended (#3427).
261
+ * The bodies were the optimism's justification; with them over, the
262
+ * overrides still in force revert at the settle — unless the transaction is
263
+ * still waiting on AUTHORITATIVE work: an override node's own source in
264
+ * flight (`transitionBlocked` — that answer supersedes or confirms on
265
+ * arrival), or a held flight that does not derive from an override (a plain
266
+ * write's load the action asked for). Through that window the optimistic
267
+ * world stands: a co-written "saving" flag stays rendered until the page it
268
+ * covers lands (A17 — the optimistic world is one).
269
+ *
270
+ * The flights that DO derive from an override — routed through a live lane —
271
+ * are obsolete: their input is the guess that is about to revert, and nobody
272
+ * will read their answer. With nothing authoritative left, each override's
273
+ * truth is already here (the staged value an A17-silent landing left, else
274
+ * the committed value) and supersedes it now, exactly as an arriving
275
+ * differing truth does (A18, #3331): the graph re-derives from it as this
276
+ * transaction's held work — a lane-derived memo re-asks with the truth, its
277
+ * other changed inputs included — and the transaction settles when THAT
278
+ * lands. Before this the settle first waited for the obsolete flight,
279
+ * revealed the obsolete optimistic frame when it landed, and only then
280
+ * started the correction — a waterfall with a flash in the middle. Returns
281
+ * whether it superseded anything (the caller re-runs the heap).
282
+ *
283
+ * The optimistic world is one, so it ends early only when all of it can. An
284
+ * optimistic STORE edit cannot yet: its truth is the base layer under an
285
+ * overlay that `_clearOptimisticStores` folds off at settlement, with no
286
+ * tracked/displayed split — superseding its tracking signals alone would
287
+ * re-derive readers against a still-displayed overlay (and a memo reading
288
+ * both a signal and the store would ask a mixed question). A transaction
289
+ * holding one keeps the settle-then-revert order throughout. Companions
290
+ * (`_parentSource` set) are optimistic nodes too — a verdict written through
291
+ * the optimistic path so it flushes ahead of the hold — but they answer for
292
+ * their owner and snap at settlement (`_snapCompanions`), not here.
293
+ */ function endOptimism(e) {
294
+ if (!e.he || e.pe.length || !e.rt.length || e.dn.size || transitionBlocked(e)) return false;
295
+ for (const n of e.oe.keys()) if (sourceObserved(e, n, e) && n.o?.ae?.has(n) && !resolveLane(n)) return false;
296
+ let n = false;
297
+ for (const i of e.rt) {
298
+ if (!hasActiveOverride(i) || i.o.Ht ||
299
+ // A derived override re-derives when its source's is superseded.
300
+ i.T & (CONFIG_OVERRIDE_SUPERSEDED | CONFIG_DERIVED_OVERRIDE) || i.S & STATUS_UNINITIALIZED) continue;
301
+ const e = i.ve !== NOT_PENDING ? i.ve : i.Qe;
302
+ if (!i.Fe || !i.Fe(e, unwrapOverride(i.o.Ce))) {
303
+ supersedeOverride(i, e);
304
+ // Judged by the mark, not the call: a provenance refusal (an older
305
+ // action's window is still open) leaves the node for a later pass.
306
+ if (i.T & CONFIG_OVERRIDE_SUPERSEDED) n = true;
307
+ }
308
+ }
309
+ return n;
310
+ }
311
+
312
+ /** read()'s value for a tracked reader of a superseded node: the truth —
313
+ * staged, or already committed (a mainline landing commits at the head of
314
+ * its flush, ahead of the heap run, and the override drops only at the
315
+ * batch's end; in between the graph must not fall back to the override it
316
+ * has left) — or the displayed override for a stale (render) reader of some
317
+ * OTHER transaction, the same visibility a foreign transaction's staged
318
+ * write has. */
319
+ /**
320
+ * A tracked read of an active override (read()'s override arm). Lanes mirror
321
+ * transitions (#3460): a render effect OFF the override's held lane — re-run
322
+ * by a sync write, or mounted mid-hold — sees the committed value, as a stale
323
+ * reader of a held transaction does, and publishes now; the lane's release
324
+ * re-runs it (readsHeldCommitted). The lane defers the override's own readers'
325
+ * runs, so the committed value is what is on screen — the override is the
326
+ * visible value only once the lane has revealed (or, demoted at body-end,
327
+ * A18). Otherwise the override displays, unless the node's own source
328
+ * answered with a DIFFERENT value (A18 supersession, #3331): the optimism is
329
+ * over for the graph — a tracked reader sees the staged truth — while the
330
+ * override remains the DISPLAYED value for untracked reads (and for a stale
331
+ * reader of some other transaction).
332
+ */ function overrideRead(e, n) {
333
+ if (stale && readsHeldCommitted(e, n)) return e.Qe;
334
+ if (!(e.T & CONFIG_OVERRIDE_SUPERSEDED)) return unwrapOverride(e.o?.Ce);
335
+ // The owning transaction: `_overrideOwner` (#2912), not the stamp — an
336
+ // override written directly inside an action never passes the adoption
337
+ // loop that stamps `_transition`, and a body-end supersession (#3427)
338
+ // stages nothing that would queue it. Without the owner a stale reader of
339
+ // a body-ended node read the committed truth beside a display still
340
+ // showing the override.
341
+ const i = resolveTransition(e);
342
+ if (stale && i && activeTransition !== i) return unwrapOverride(e.o?.Ce);
343
+ // A superseded read is a staged read (A29) whether the truth is staged or
344
+ // already committed: the pass that derives from it derives from the
345
+ // owning transaction's world (the override is still displayed by it).
346
+ enterStagedRead(e, i);
347
+ return e.ve !== NOT_PENDING ? e.ve : e.Qe;
348
+ }
349
+
350
+ /**
351
+ * An authoritative store landing on an override-covered node — a derived
352
+ * optimistic store's own truth arriving over a tentative edit through the
353
+ * projection-write channel (setSignal under projectionWriteActive). The
354
+ * store twin of asyncWrite's override branch: the truth stages for its
355
+ * transaction's commit whatever its relation to the committed value (a
356
+ * landing equal to committed still differs from the override), companions
357
+ * learn of it, and supersedeOverride decides the rest — A18 supersession with
358
+ * action provenance, or an A17-silent confirmation (#3331). Before this the
359
+ * landing took setSignal's plain path: a differing truth staged silently
360
+ * under the override and the graph never moved until the commit.
361
+ */ function landOnOverride(e, n) {
362
+ const i = e.ve === NOT_PENDING ? e.Qe : e.ve;
363
+ if (typeof n === "function") n = n(i);
364
+ if (e.ve === NOT_PENDING) queuePendingNode(e);
365
+ e.ve = n;
366
+ GlobalQueue.me?.(e, n);
367
+ supersedeOverride(e, n);
368
+ schedule();
369
+ return n;
370
+ }
371
+
117
372
  function runQueue(e, n) {
118
- for (let t = 0; t < e.length; t++) e[t](n);
373
+ for (let i = 0; i < e.length; i++) e[i](n | LANE_RUN);
119
374
  }
120
375
 
121
376
  /**
@@ -123,32 +378,32 @@ function runQueue(e, n) {
123
378
  * laneHeld).
124
379
  */ function runLaneEffects(e) {
125
380
  for (const n of activeLanes) {
126
- if (n.rn || laneHeld(n)) continue;
127
- const t = n.tn[e - 1];
128
- if (t.length) {
129
- n.tn[e - 1] = [];
130
- runQueue(t, e);
381
+ if (n.cn || laneHeld(n)) continue;
382
+ const i = n.fn[e - 1];
383
+ if (i.length) {
384
+ n.fn[e - 1] = [];
385
+ runQueue(i, e);
131
386
  }
132
387
  }
133
388
  // Optimistic patch applications ride the same visibility slot as lane
134
389
  // effects (in-flight DOM updates); no-op unless patches registered.
135
- if (e === EFFECT_RENDER) GlobalQueue.ln?.();
390
+ if (e === EFFECT_RENDER) GlobalQueue.In?.();
136
391
  }
137
392
 
138
393
  function cleanupCompletedLanes(e) {
139
394
  for (const n of activeLanes) {
140
- const t = e ? n.Ae === e : !n.Ae;
141
- if (!t) continue;
142
- if (!n.rn) {
143
- if (n.tn[0].length) runQueue(n.tn[0], EFFECT_RENDER);
144
- if (n.tn[1].length) runQueue(n.tn[1], EFFECT_USER);
395
+ const i = e ? n.Ge === e : !n.Ge;
396
+ if (!i) continue;
397
+ if (!n.cn) {
398
+ if (n.fn[0].length) runQueue(n.fn[0], EFFECT_RENDER);
399
+ if (n.fn[1].length) runQueue(n.fn[1], EFFECT_USER);
145
400
  }
146
- if (n.nn.o?.$e === n) if (n.nn.o !== null) n.nn.o.$e = undefined;
147
- n.Oe.clear();
148
- n.tn[0].length = 0;
149
- n.tn[1].length = 0;
401
+ if (n.an.o?.Ue === n) if (n.an.o !== null) n.an.o.Ue = undefined;
402
+ n.ye.clear();
403
+ n.fn[0].length = 0;
404
+ n.fn[1].length = 0;
150
405
  activeLanes.delete(n);
151
- signalLanes.delete(n.nn);
406
+ signalLanes.delete(n.an);
152
407
  }
153
408
  }
154
409
 
@@ -162,30 +417,44 @@ function cleanupCompletedLanes(e) {
162
417
  // this is only reachable under a lane, which implies the engine.
163
418
  if (e.S & STATUS_UNINITIALIZED) return true;
164
419
  // Per-lane suspension: only throw if in same lane as pending async
165
- // AND the node doesn't have an active override (overrides are the visible value,
166
- // downstream in the lane should read the override, not throw)
167
- const n = e.o?.$e;
420
+ // AND the node doesn't have an active WRITTEN override (overrides are the
421
+ // visible value, downstream in the lane should read the override, not
422
+ // throw). A derived override (#3479) is a previous speculative answer, not
423
+ // an intent: the re-ask pending behind it suspends like any lane async.
424
+ const n = e.o?.Ue;
168
425
  if (!n) return false;
169
- return findLane(n) === findLane(currentOptimisticLane) && !hasActiveOverride(e);
426
+ return findLane(n) === findLane(currentOptimisticLane) && (!hasActiveOverride(e) || (e.T & CONFIG_DERIVED_OVERRIDE) !== 0);
427
+ }
428
+
429
+ /**
430
+ * read()'s reveal carve-out asks whether a pending node is routed through a
431
+ * LIVE lane: a lane-derived flight's inputs are already revealed through the
432
+ * lane (the override, or latest()'s fresh value), so a stale reader of another
433
+ * transaction must hold on the flight rather than show the node's committed
434
+ * value beside them (#3334). Exact, not sticky: `resolveLane` clears a lane
435
+ * reference the engine has since retired, so a node that was once lane-routed
436
+ * and is now pending under a plain hold is judged by that hold alone.
437
+ */ function laneLive(e) {
438
+ return resolveLane(e) !== undefined;
170
439
  }
171
440
 
172
441
  /**
173
442
  * read()'s entanglement gate: a reader recomputing under an optimistic lane
174
443
  * that reads a pending mid-transition write sees the committed value; the sub
175
444
  * is recorded for replay at commit.
176
- */ function gatedRead(e, n, t) {
177
- if (latestReadActive || e.Re === NOT_PENDING || e.oe || n !== e && !(n.ie & REACTIVE_MANUAL_WRITE)) {
445
+ */ function gatedRead(e, n, i) {
446
+ if (latestReadActive || e.ve === NOT_PENDING || e.ce || n !== e && !(n.ue & REACTIVE_MANUAL_WRITE)) {
178
447
  return false;
179
448
  }
180
- activeTransition.cn.add(t);
449
+ activeTransition.ct.add(i);
181
450
  return true;
182
451
  }
183
452
 
184
453
  /**
185
454
  * read()'s value selection under a lane: return the committed `_value` for
186
455
  * optimistic/lane-assigned signals, stale-mode reads, and pending owners.
187
- */ function laneReadsCommitted(e, n, t) {
188
- if (e.o?.Pe !== undefined || !!e.o?.$e || !!(n.S & STATUS_PENDING)) {
456
+ */ function laneReadsCommitted(e, n, i) {
457
+ if (e.o?.Ce !== undefined || !!e.o?.Ue || !!(n.S & STATUS_PENDING)) {
189
458
  // The committed view hides a staged in-flight value that will promote
190
459
  // silently (commitPendingNode never re-notifies). gatedRead records plain
191
460
  // signals for replay at commit; async memos are excluded from it by the
@@ -193,11 +462,17 @@ function cleanupCompletedLanes(e) {
193
462
  // already settled (laneAsyncSettled keeps _optimisticLane) served its
194
463
  // committed value to a reader that never re-ran after the landing, so a
195
464
  // pending-gated branch stayed one value behind permanently (#3041
196
- // follow-up). Record the reader under the same replay contract.
197
- if (e.Re !== NOT_PENDING) (activeTransition ?? globalQueue.m).cn.add(t);
465
+ // follow-up). Record the reader under the same replay contract — when
466
+ // the commit will actually change what it read: a staged value equal to
467
+ // the committed one (a lane recompute already published it, INV-11)
468
+ // promotes to the same view, and a replay would only re-run effects
469
+ // against an unchanged frame (#3330). An override-covered node's revert
470
+ // notifies its own subscribers when the truth differs (resolveOptimistic
471
+ // Nodes), so the reader is recorded only for the staged-vs-committed gap.
472
+ if (e.ve !== NOT_PENDING && e.ve !== e.Qe) (activeTransition ?? globalQueue.m).ct.add(i);
198
473
  return true;
199
474
  }
200
- if (n === e && stale && t.o?.St !== e) {
475
+ if (n === e && stale && i.o?.Ht !== e) {
201
476
  // The committed view can hide a staged write (a lane member — even just
202
477
  // an isPending companion flip — puts the reader "under a lane"). The
203
478
  // staged value commits with no re-delivery (commitPendingNode never
@@ -209,7 +484,7 @@ function cleanupCompletedLanes(e) {
209
484
  // into the transaction (#3041 follow-up: a pending-gated branch that
210
485
  // first read its async source during the landing flush stayed one value
211
486
  // behind permanently); with none, into the ambient batch.
212
- if (e.Re !== NOT_PENDING) (activeTransition ?? globalQueue.m).cn.add(t);
487
+ if (e.ve !== NOT_PENDING) (activeTransition ?? globalQueue.m).ct.add(i);
213
488
  return true;
214
489
  }
215
490
  return false;
@@ -232,18 +507,18 @@ function cleanupCompletedLanes(e) {
232
507
  // recompute() runs plain: the value stages and commits with the flush.
233
508
  // (el's own override slot excludes companions themselves; a lane merged
234
509
  // into a real optimistic lane resolves to a non-companion source.)
235
- if (!globalQueue.fn && !activeTransition && !n.Ae && n.nn.o?.St !== undefined && e.o?.Pe === undefined) {
236
- if (e.o !== null) e.o.$e = undefined;
510
+ if (!globalQueue.Kt && !activeTransition && !n.Ge && n.an.o?.Ht !== undefined && e.o?.Ce === undefined) {
511
+ if (e.o !== null) e.o.Ue = undefined;
237
512
  return false;
238
513
  }
239
514
  return n;
240
515
  }
241
- for (let n = e.lt; n; n = n.ot) {
242
- const t = n.st;
243
- if (t.ie & REACTIVE_OPTIMISTIC_DIRTY) {
244
- const n = resolveLane(t);
516
+ for (let n = e.Se; n; n = n.de) {
517
+ const i = n.Ee;
518
+ if (i.ue & REACTIVE_OPTIMISTIC_DIRTY) {
519
+ const n = resolveLane(i);
245
520
  if (n) {
246
- e.ie |= REACTIVE_OPTIMISTIC_DIRTY;
521
+ e.ue |= REACTIVE_OPTIMISTIC_DIRTY;
247
522
  assignOrMergeLane(e, n);
248
523
  return n;
249
524
  }
@@ -257,9 +532,9 @@ function cleanupCompletedLanes(e) {
257
532
  * companion is NOT refreshed here: its verdict never read _pendingAsync, and
258
533
  * the source's own write/commit/settlement paths keep it current. */ function laneAsyncPending(e) {
259
534
  const n = findLane(currentOptimisticLane);
260
- if (n.nn !== e) {
261
- n.Oe.add(e);
262
- ext(e).$e = n;
535
+ if (n.an !== e) {
536
+ n.ye.add(e);
537
+ ext(e).Ue = n;
263
538
  e.T |= CONFIG_HAS_LANE;
264
539
  }
265
540
  }
@@ -267,13 +542,13 @@ function cleanupCompletedLanes(e) {
267
542
  /** recompute()'s success path: the node's async settled, clear it from its lane. */ function laneAsyncSettled(e) {
268
543
  const n = resolveLane(e);
269
544
  if (n) {
270
- n.Oe.delete(e);
545
+ n.ye.delete(e);
271
546
  }
272
547
  }
273
548
 
274
549
  function trackOptimisticStore(e) {
275
550
  // After initTransition, globalQueue._batch IS activeTransition (same reference)
276
- globalQueue.m.En.add(e);
551
+ globalQueue.m.dn.add(e);
277
552
  schedule();
278
553
  }
279
554
 
@@ -282,19 +557,25 @@ function trackOptimisticStore(e) {
282
557
  * create optimistic state (verdict.ts at module top level, createOptimistic
283
558
  * and createOptimisticStore at first call) BEFORE any optimistic node exists.
284
559
  */ function installOptimisticEngine() {
285
- if (GlobalQueue.yt !== null) return;
286
- GlobalQueue.yt = optimisticWrite;
287
- GlobalQueue.Tn = resolveOptimisticNodes;
288
- GlobalQueue.dn = transitionBlocked;
289
- GlobalQueue.In = cleanupCompletedLanes;
290
- GlobalQueue.Nn = runLaneEffects;
291
- GlobalQueue.Ut = gatedRead;
292
- GlobalQueue.kt = laneSuspends;
293
- GlobalQueue.xt = laneReadsCommitted;
294
- GlobalQueue.Je = recomputeLane;
295
- GlobalQueue.tt = laneAsyncPending;
296
- GlobalQueue.et = laneAsyncSettled;
297
- GlobalQueue._n = trackOptimisticStore;
560
+ if (GlobalQueue.ln !== null) return;
561
+ GlobalQueue.ln = optimisticWrite;
562
+ GlobalQueue.On = resolveOptimisticNodes;
563
+ GlobalQueue.Nn = transitionBlocked;
564
+ GlobalQueue.Rn = cleanupCompletedLanes;
565
+ GlobalQueue._n = runLaneEffects;
566
+ GlobalQueue.we = supersedeOverride;
567
+ GlobalQueue.Tn = endOptimism;
568
+ GlobalQueue.en = overrideRead;
569
+ GlobalQueue.Ve = laneOverride;
570
+ GlobalQueue.un = landOnOverride;
571
+ GlobalQueue.tn = gatedRead;
572
+ GlobalQueue.$t = laneSuspends;
573
+ GlobalQueue.Xt = laneLive;
574
+ GlobalQueue.Bt = laneReadsCommitted;
575
+ GlobalQueue.st = recomputeLane;
576
+ GlobalQueue._t = laneAsyncPending;
577
+ GlobalQueue.ft = laneAsyncSettled;
578
+ GlobalQueue.Dn = trackOptimisticStore;
298
579
  }
299
580
 
300
581
  export { installOptimisticEngine };