@solidjs/signals 2.0.0-rc.1 → 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 (150) hide show
  1. package/dist/dev-shared.js +7138 -0
  2. package/dist/dev.attribution.js +3307 -0
  3. package/dist/dev.js +5691 -4491
  4. package/dist/observe/affects.js +129 -0
  5. package/dist/observe/attribution.js +7 -0
  6. package/dist/observe/boundaries.js +793 -0
  7. package/dist/observe/core/action.js +177 -0
  8. package/dist/observe/core/async.js +849 -0
  9. package/dist/observe/core/attribution-costs.js +66 -0
  10. package/dist/observe/core/attribution-feedback.js +280 -0
  11. package/dist/observe/core/attribution-hooks.js +83 -0
  12. package/dist/observe/core/attribution-queries.js +43 -0
  13. package/dist/observe/core/attribution.js +2904 -0
  14. package/dist/observe/core/constants.js +283 -0
  15. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  16. package/dist/observe/core/core.js +1999 -0
  17. package/dist/observe/core/dev.js +343 -0
  18. package/dist/observe/core/effect.js +200 -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 +627 -0
  27. package/dist/observe/core/owner.js +353 -0
  28. package/dist/observe/core/scheduler.js +1547 -0
  29. package/dist/observe/core/verdict.js +674 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +484 -0
  32. package/dist/observe/signals.js +731 -0
  33. package/dist/observe/store/index.js +44 -0
  34. package/dist/observe/store/next/optimistic.js +717 -0
  35. package/dist/observe/store/next/projection.js +266 -0
  36. package/dist/observe/store/next/reconcile.js +375 -0
  37. package/dist/observe/store/next/store.js +2480 -0
  38. package/dist/observe/store/next/target.js +51 -0
  39. package/dist/observe/store/store.js +331 -0
  40. package/dist/observe/store/storePath.js +103 -0
  41. package/dist/observe/store/utils.js +1070 -0
  42. package/dist/prod/affects.js +10 -9
  43. package/dist/prod/attribution.js +45 -0
  44. package/dist/prod/boundaries.js +388 -178
  45. package/dist/prod/core/action.js +65 -37
  46. package/dist/prod/core/async.js +378 -163
  47. package/dist/prod/core/attribution-hooks.js +3 -0
  48. package/dist/prod/core/constants.js +186 -1
  49. package/dist/prod/core/context.js +10 -16
  50. package/dist/prod/core/core.js +1546 -416
  51. package/dist/prod/core/dev.js +18 -1
  52. package/dist/prod/core/effect.js +119 -79
  53. package/dist/prod/core/error-hooks.js +71 -0
  54. package/dist/prod/core/error.js +13 -1
  55. package/dist/prod/core/external.js +4 -4
  56. package/dist/prod/core/graph.js +105 -54
  57. package/dist/prod/core/heap.js +72 -65
  58. package/dist/prod/core/invariants.js +3 -2
  59. package/dist/prod/core/lanes.js +117 -52
  60. package/dist/prod/core/optimistic.js +458 -104
  61. package/dist/prod/core/owner.js +131 -84
  62. package/dist/prod/core/scheduler.js +998 -241
  63. package/dist/prod/core/verdict.js +417 -112
  64. package/dist/prod/index.js +20 -8
  65. package/dist/prod/map.js +312 -151
  66. package/dist/prod/signals.js +363 -32
  67. package/dist/prod/store/index.js +2 -0
  68. package/dist/prod/store/next/optimistic.js +530 -197
  69. package/dist/prod/store/next/projection.js +142 -57
  70. package/dist/prod/store/next/reconcile.js +149 -103
  71. package/dist/prod/store/next/store.js +1470 -346
  72. package/dist/prod/store/next/target.js +40 -9
  73. package/dist/prod/store/store.js +23 -19
  74. package/dist/prod/store/utils.js +997 -130
  75. package/dist/types/attribution.d.ts +19 -0
  76. package/dist/types/attribution.prod.d.ts +22 -0
  77. package/dist/types/boundaries.d.ts +78 -5
  78. package/dist/types/core/action.d.ts +12 -5
  79. package/dist/types/core/async.d.ts +3 -1
  80. package/dist/types/core/attribution-costs.d.ts +35 -0
  81. package/dist/types/core/attribution-feedback.d.ts +133 -0
  82. package/dist/types/core/attribution-hooks.d.ts +304 -0
  83. package/dist/types/core/attribution-queries.d.ts +24 -0
  84. package/dist/types/core/attribution.d.ts +892 -0
  85. package/dist/types/core/constants.d.ts +179 -0
  86. package/dist/types/core/core.d.ts +299 -25
  87. package/dist/types/core/dev.d.ts +421 -8
  88. package/dist/types/core/effect.d.ts +8 -1
  89. package/dist/types/core/error-hooks.d.ts +71 -0
  90. package/dist/types/core/error.d.ts +9 -0
  91. package/dist/types/core/graph.d.ts +23 -0
  92. package/dist/types/core/heap.d.ts +5 -3
  93. package/dist/types/core/index.d.ts +6 -3
  94. package/dist/types/core/invariants.d.ts +5 -1
  95. package/dist/types/core/lanes.d.ts +51 -19
  96. package/dist/types/core/owner.d.ts +15 -3
  97. package/dist/types/core/scheduler.d.ts +248 -1
  98. package/dist/types/core/types.d.ts +124 -41
  99. package/dist/types/index.d.ts +18 -5
  100. package/dist/types/map.d.ts +2 -0
  101. package/dist/types/signals.d.ts +145 -13
  102. package/dist/types/store/index.d.ts +7 -6
  103. package/dist/types/store/next/optimistic.d.ts +18 -13
  104. package/dist/types/store/next/projection.d.ts +5 -2
  105. package/dist/types/store/next/reconcile.d.ts +7 -0
  106. package/dist/types/store/next/store.d.ts +83 -11
  107. package/dist/types/store/next/target.d.ts +108 -11
  108. package/dist/types/store/store.d.ts +20 -11
  109. package/dist/types/store/utils.d.ts +188 -0
  110. package/package.json +31 -26
  111. package/dist/node.cjs +0 -8137
  112. package/dist/types/store/optimistic.d.ts +0 -45
  113. package/dist/types/store/projection.d.ts +0 -70
  114. package/dist/types/store/reconcile.d.ts +0 -46
  115. package/dist/types-cjs/affects.d.cts +0 -47
  116. package/dist/types-cjs/boundaries.d.cts +0 -175
  117. package/dist/types-cjs/core/action.d.cts +0 -64
  118. package/dist/types-cjs/core/async.d.cts +0 -21
  119. package/dist/types-cjs/core/constants.d.cts +0 -71
  120. package/dist/types-cjs/core/core.d.cts +0 -156
  121. package/dist/types-cjs/core/dev.d.cts +0 -64
  122. package/dist/types-cjs/core/effect.d.cts +0 -30
  123. package/dist/types-cjs/core/error.d.cts +0 -47
  124. package/dist/types-cjs/core/external.d.cts +0 -15
  125. package/dist/types-cjs/core/graph.d.cts +0 -5
  126. package/dist/types-cjs/core/heap.d.cts +0 -22
  127. package/dist/types-cjs/core/index.d.cts +0 -13
  128. package/dist/types-cjs/core/invariants.d.cts +0 -59
  129. package/dist/types-cjs/core/lanes.d.cts +0 -56
  130. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  131. package/dist/types-cjs/core/owner.d.cts +0 -124
  132. package/dist/types-cjs/core/scheduler.d.cts +0 -172
  133. package/dist/types-cjs/core/types.d.cts +0 -148
  134. package/dist/types-cjs/core/verdict.d.cts +0 -2
  135. package/dist/types-cjs/index.d.cts +0 -10
  136. package/dist/types-cjs/map.d.cts +0 -69
  137. package/dist/types-cjs/package.json +0 -3
  138. package/dist/types-cjs/signals.d.cts +0 -624
  139. package/dist/types-cjs/store/index.d.cts +0 -19
  140. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  141. package/dist/types-cjs/store/next/projection.d.cts +0 -24
  142. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  143. package/dist/types-cjs/store/next/store.d.cts +0 -71
  144. package/dist/types-cjs/store/next/target.d.cts +0 -99
  145. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  146. package/dist/types-cjs/store/projection.d.cts +0 -70
  147. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  148. package/dist/types-cjs/store/store.d.cts +0 -138
  149. package/dist/types-cjs/store/storePath.d.cts +0 -58
  150. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,104 +1,111 @@
1
- import { REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, EFFECT_TRACKED, EFFECT_USER, REACTIVE_RECOMPUTING_DEPS, REACTIVE_MANUAL_WRITE, REACTIVE_ZOMBIE, REACTIVE_CHECK, REACTIVE_DIRTY } from "./constants.js";
1
+ import "./core.js";
2
+
3
+ import { REACTIVE_IN_HEAP, REACTIVE_IN_HEAP_HEIGHT, REACTIVE_ZOMBIE, REACTIVE_RECOMPUTING_DEPS, REACTIVE_MANUAL_WRITE, REACTIVE_CHECK, REACTIVE_DIRTY, CONFIG_FW_CHILDREN } from "./constants.js";
2
4
 
3
5
  import { zombieQueue, dirtyQueue } from "./scheduler.js";
4
6
 
5
7
  /** The queue a node belongs to, picked from its own zombie flag. */ function queueFor(e) {
6
- return e.se & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
8
+ return e.oe & REACTIVE_ZOMBIE ? zombieQueue : dirtyQueue;
7
9
  }
8
10
 
9
11
  /**
10
- * Schedule one subscriber to re-run on the next flush: tracked effects bypass
11
- * the heap and go directly to their effect queue; everything else is inserted
12
- * into its own (zombie-flag-routed) heap with the `_min` cursor pulled down.
12
+ * Schedule one subscriber to re-run on the next flush: inserted into its own
13
+ * (zombie-flag-routed) heap with the `_min` cursor pulled down. Tracked
14
+ * effects ride the heap too — the heap visit is their (empty) compute phase,
15
+ * which hands the callback to the user queue once the pass has committed
16
+ * (see GlobalQueue._update, #3291).
13
17
  */ function enqueueSub(e) {
14
- if (e.Re === EFFECT_TRACKED) {
15
- const E = e;
16
- if (!E.Je) {
17
- E.Je = true;
18
- E.C.enqueue(EFFECT_USER, E.ht);
19
- }
20
- return;
21
- }
22
18
  const E = queueFor(e);
23
- if (E.Ve > e.Le) E.Ve = e.Le;
19
+ if (E.ln > e.rn) E.ln = e.rn;
24
20
  insertIntoHeap(e, E);
25
21
  }
26
22
 
27
23
  function actualInsertIntoHeap(e, E) {
28
- const t = (e.Fe?.Tt ? e.Fe.It?.Le : e.Fe?.Le) ?? -1;
29
- if (t >= e.Le) e.Le = t + 1;
30
- const n = e.Le;
24
+ const t = (e._parent?.Wn ? e._parent.qn?.rn : e._parent?.rn) ?? -1;
25
+ if (t >= e.rn) e.rn = t + 1;
26
+ const n = e.rn;
31
27
  const I = E.eE[n];
32
28
  if (I === undefined) E.eE[n] = e; else {
33
- const E = I.ot;
34
- E.st = e;
35
- e.ot = E;
36
- I.ot = e;
29
+ const E = I.Fn;
30
+ E.Pn = e;
31
+ e.Fn = E;
32
+ I.Fn = e;
37
33
  }
38
34
  if (n > E.EE) E.EE = n;
39
35
  }
40
36
 
41
37
  function insertIntoHeap(e, E) {
42
- let t = e.se;
43
- if (t & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_MANUAL_WRITE)) return;
38
+ let t = e.oe;
39
+ // RECOMPUTING refusals are not always losses: a genuinely missed wake (a
40
+ // write to a link this pass already validated) is latched link-side in
41
+ // insertSubs as REACTIVE_MISSED_WAKE for recompute's tail (#3037).
42
+ if (t & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_MANUAL_WRITE)) return;
44
43
  if (t & REACTIVE_CHECK) {
45
- e.se = t & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
44
+ e.oe = t & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
46
45
  } else {
47
- e.se = t | REACTIVE_IN_HEAP;
48
- // An unmarked node entering a marked heap invalidates the markHeap memo:
49
- // `_marked` is only reset by runHeap, so a write between two mid-tick
50
- // pulls (read-time markHeap + updateIfNecessary) would otherwise leave
51
- // this node unmarked and every downstream pull stale until the next
52
- // flush (#2922: the second `latest()` returned the first write's value).
53
- if (E.tE && !(t & REACTIVE_DIRTY)) E.tE = false;
46
+ e.oe = t | REACTIVE_IN_HEAP;
47
+ // An unmarked node entering an already-marked heap is marked on the
48
+ // spot, keeping the markHeap memo valid. `_marked` is only reset by
49
+ // runHeap, so a write between two mid-tick pulls (read-time markHeap +
50
+ // updateIfNecessary) would otherwise leave this node unmarked and every
51
+ // downstream pull stale until the next flush (#2922: the second
52
+ // `latest()` returned the first write's value). Invalidating the memo
53
+ // instead re-walked the WHOLE heap on the next pull — with N effects
54
+ // parked in the heap for a synchronous mount (each row writing a ref
55
+ // signal its effect subscribes to), mounting N rows was O(N²) (#3350).
56
+ // markNode's own guard skips an already-DIRTY node.
57
+ if (E.tE) markNode(e);
54
58
  }
55
59
  if (!(t & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, E);
56
60
  }
57
61
 
58
62
  function insertIntoHeapHeight(e, E) {
59
- let t = e.se;
63
+ let t = e.oe;
60
64
  if (t & (REACTIVE_IN_HEAP | REACTIVE_RECOMPUTING_DEPS | REACTIVE_IN_HEAP_HEIGHT | REACTIVE_MANUAL_WRITE)) return;
61
- e.se = t | REACTIVE_IN_HEAP_HEIGHT;
65
+ e.oe = t | REACTIVE_IN_HEAP_HEIGHT;
62
66
  actualInsertIntoHeap(e, E);
63
67
  }
64
68
 
65
69
  function deleteFromHeap(e, E) {
66
- const t = e.se;
70
+ const t = e.oe;
67
71
  if (!(t & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
68
- e.se = t & -25;
69
- const n = e.Le;
70
- if (e.ot === e) E.eE[n] = undefined; else {
71
- const t = e.st;
72
+ e.oe = t & -25;
73
+ const n = e.rn;
74
+ if (e.Fn === e) E.eE[n] = undefined; else {
75
+ const t = e.Pn;
72
76
  const I = E.eE[n];
73
77
  const o = t ?? I;
74
- if (e === I) E.eE[n] = t; else e.ot.st = t;
75
- o.ot = e.ot;
78
+ if (e === I) E.eE[n] = t; else e.Fn.Pn = t;
79
+ o.Fn = e.Fn;
76
80
  }
77
- e.ot = e;
78
- e.st = undefined;
81
+ e.Fn = e;
82
+ e.Pn = undefined;
79
83
  }
80
84
 
81
85
  function markHeap(e) {
82
86
  if (e.tE) return;
83
87
  e.tE = true;
84
88
  for (let E = 0; E <= e.EE; E++) {
85
- for (let t = e.eE[E]; t !== undefined; t = t.st) {
86
- if (t.se & REACTIVE_IN_HEAP) markNode(t);
89
+ for (let t = e.eE[E]; t !== undefined; t = t.Pn) {
90
+ if (t.oe & REACTIVE_IN_HEAP) markNode(t);
87
91
  }
88
92
  }
89
93
  }
90
94
 
91
95
  function markNode(e, E = REACTIVE_DIRTY) {
92
- const t = e.se;
96
+ const t = e.oe;
93
97
  if ((t & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= E) return;
94
- e.se = t & -4 | E;
95
- for (let E = e.o; E !== null; E = E.ue) {
96
- markNode(E.fe, REACTIVE_CHECK);
98
+ e.oe = t & -4 | E;
99
+ for (let E = e.u; E !== null; E = E.Ae) {
100
+ markNode(E.ge, REACTIVE_CHECK);
97
101
  }
98
- if (e.u !== null) {
99
- for (let E = e.u; E !== null; E = E.ae) {
100
- for (let e = E.o; e !== null; e = e.ue) {
101
- markNode(e.fe, REACTIVE_CHECK);
102
+ // Firewall children (projection machinery only): gate the cold-extension
103
+ // deref on the config bit — markNode runs per sub edge per write, and an
104
+ // unconditional _x chase here taxed every propagation (diamond -22%).
105
+ if (e.C & CONFIG_FW_CHILDREN) {
106
+ for (let E = e.o.i; E !== null; E = E.Ue) {
107
+ for (let e = E.u; e !== null; e = e.Ae) {
108
+ markNode(e.ge, REACTIVE_CHECK);
102
109
  }
103
110
  }
104
111
  }
@@ -106,11 +113,11 @@ function markNode(e, E = REACTIVE_DIRTY) {
106
113
 
107
114
  function runHeap(e, E) {
108
115
  e.tE = false;
109
- for (e.Ve = 0; e.Ve <= e.EE; e.Ve++) {
110
- let t = e.eE[e.Ve];
116
+ for (e.ln = 0; e.ln <= e.EE; e.ln++) {
117
+ let t = e.eE[e.ln];
111
118
  while (t !== undefined) {
112
- if (t.se & REACTIVE_IN_HEAP) E(t); else adjustHeight(t, e);
113
- t = e.eE[e.Ve];
119
+ if (t.oe & REACTIVE_IN_HEAP) E(t); else adjustHeight(t, e);
120
+ t = e.eE[e.ln];
114
121
  }
115
122
  }
116
123
  e.EE = 0;
@@ -118,21 +125,21 @@ function runHeap(e, E) {
118
125
 
119
126
  function adjustHeight(e, E) {
120
127
  deleteFromHeap(e, E);
121
- let t = e.Le;
122
- for (let E = e.tt; E; E = E.nt) {
123
- const e = E.it;
124
- const n = e.lt || e;
125
- if (n.ce && n.Le >= t) t = n.Le + 1;
128
+ let t = e.rn;
129
+ for (let E = e.Ie; E; E = E.Ne) {
130
+ const e = E.Oe;
131
+ const n = e.De || e;
132
+ if (n.he && n.rn >= t) t = n.rn + 1;
126
133
  }
127
- if (e.Le !== t) {
128
- e.Le = t;
129
- for (let E = e.o; E !== null; E = E.ue) {
134
+ if (e.rn !== t) {
135
+ e.rn = t;
136
+ for (let E = e.u; E !== null; E = E.Ae) {
130
137
  // Route each subscriber by its own zombie flag, mirroring the
131
138
  // post-recompute height-adjust path. Inserting into the running `heap`
132
139
  // unconditionally can park a zombie in `dirtyQueue` (or a live node in
133
140
  // `zombieQueue`), breaking the flag/queue invariant `deleteFromHeap`
134
141
  // relies on — the same corruption class as #2759.
135
- insertIntoHeapHeight(E.fe, queueFor(E.fe));
142
+ insertIntoHeapHeight(E.ge, queueFor(E.ge));
136
143
  }
137
144
  }
138
145
  }
@@ -1,3 +1,5 @@
1
+ import "./core.js";
2
+
1
3
  /**
2
4
  * INV-2: a node with an *active* override must be registered for reversion in
3
5
  * the queue's or a transition's `_optimisticNodes`. An unregistered active
@@ -6,8 +8,7 @@
6
8
  * (There is no revert-target requirement: authoritative values commit
7
9
  * silently into `_value` under the override mask — A17 — so reverting is
8
10
  * just dropping the override.)
9
- */
10
- function devCheckActiveOverrides(e) {
11
+ */ function devCheckActiveOverrides(e) {
11
12
  return;
12
13
  }
13
14
 
@@ -1,6 +1,10 @@
1
- import { NOT_PENDING } from "./constants.js";
1
+ import { CONFIG_DERIVED_OVERRIDE, CONFIG_HAS_LANE, REACTIVE_DISPOSED } from "./constants.js";
2
2
 
3
- import { currentTransition, activeTransition } from "./scheduler.js";
3
+ import { hasActiveOverride, ext, ownsHold, currentOptimisticLane } from "./core.js";
4
+
5
+ import { enqueueSub } from "./heap.js";
6
+
7
+ import { currentTransition, activeTransition, waitingTransition } from "./scheduler.js";
4
8
 
5
9
  // Map from optimistic signal to its lane (reused for multiple writes to same signal)
6
10
  const signalLanes = new WeakMap;
@@ -18,15 +22,16 @@ const activeLanes = new Set;
18
22
  }
19
23
  // Detect parent lane: _parentSource chains from pendingSignal → pendingValueComputed → original.
20
24
  // The child lane should not merge with the parent lane.
21
- const i = n.nn;
22
- const r = i?.Ke ? findLane(i.Ke) : null;
25
+ const i = n.o?.kn;
26
+ const t = i?.o?.me;
27
+ const r = t ? findLane(t) : null;
23
28
  e = {
24
- en: n,
25
- Ae: new Set,
26
- rn: [ [], [] ],
27
- tn: null,
28
- Ne: activeTransition,
29
- an: r
29
+ ni: n,
30
+ Qe: new Set,
31
+ dn: [ [], [] ],
32
+ ei: null,
33
+ we: activeTransition,
34
+ ii: r
30
35
  };
31
36
  signalLanes.set(n, e);
32
37
  activeLanes.add(e);
@@ -36,8 +41,8 @@ const activeLanes = new Set;
36
41
  // parent-child is a property of the nodes, not of write order — otherwise
37
42
  // the owner's write merges the companion's subscribers into this lane and
38
43
  // their effects wait on its async instead of flushing immediately.
39
- adoptCompanionLane(n.Oe, e);
40
- adoptCompanionLane(n.ge, e);
44
+ adoptCompanionLane(n.o?.Ze, e);
45
+ adoptCompanionLane(n.o?.He, e);
41
46
  return e;
42
47
  }
43
48
 
@@ -45,46 +50,108 @@ function adoptCompanionLane(n, e) {
45
50
  if (!n) return;
46
51
  const i = signalLanes.get(n);
47
52
  if (!i) return;
48
- const r = findLane(i);
53
+ const t = findLane(i);
49
54
  // Only the companion's own unmerged root is safely re-parentable: a root
50
55
  // that absorbed other lanes carries work that is not a child of this owner.
51
- if (r !== e && r.en === n && !r.an) r.an = e;
56
+ if (t !== e && t.ni === n && !t.ii) t.ii = e;
52
57
  }
53
58
 
54
59
  /**
55
60
  * Union-find: find the root lane.
56
61
  */ function findLane(n) {
57
- while (n.tn) n = n.tn;
62
+ while (n.ei) n = n.ei;
58
63
  return n;
59
64
  }
60
65
 
66
+ /**
67
+ * Is the lane held? `_pendingAsync` records the async the lane OWNS (derived
68
+ * under it); a transaction's reporter map records the async a render effect
69
+ * OBSERVED pending with no boundary taking it (INV-3, the one registration
70
+ * site). A hold needs both — the same rule the transaction itself uses, so a
71
+ * memo nobody renders, or one a fallback-showing boundary caught, cannot tear
72
+ * a frame and holds nothing (#3289). An orphan lane has no observation record
73
+ * and never holds.
74
+ *
75
+ * The observation is looked up per NODE, in whichever live transaction
76
+ * recorded it — not in this lane's transaction. Lanes merge across
77
+ * transactions (#2912: ownership never travels through lanes), so after a
78
+ * merge the root's transaction holds the observations of only one member;
79
+ * the async the other member's transaction observed must hold the merged
80
+ * reveal just the same (A15 for lanes, #3335).
81
+ */ function laneHeld(n) {
82
+ if (!n.we) return false;
83
+ for (const e of n.Qe) if (waitingTransition(e) !== null) return true;
84
+ return false;
85
+ }
86
+
87
+ /**
88
+ * Lanes mirror transitions (#3460): a render effect OFF a HELD lane that reads
89
+ * a value the lane is revealing — an override, a `latest()` shadow — sees the
90
+ * committed value, exactly as a stale reader of a held transaction does
91
+ * (A15 reveal corollary): it publishes now, with the frame that is on screen
92
+ * (the lane defers its own readers' runs, so the committed value is what is
93
+ * visible), entangles nothing — a sync write is never held by a lane — and
94
+ * re-derives at the release. The release re-run rides the lane's own render
95
+ * queue, which runs when the lane reveals (runLaneEffects) or its transaction
96
+ * commits (cleanupCompletedLanes). A reader ON the lane computes the lane's
97
+ * reveal and takes the value as before.
98
+ *
99
+ * OFF the lane is provenance, not membership — the transaction mirror
100
+ * exactly: a stale reader of a transaction is a pass that runs outside it. A
101
+ * pass under the lane's own transaction is the lane's work — its write (lane
102
+ * posture), or the landing of its async, which re-enters the transaction
103
+ * (#3334) and runs a member with no ambient lane. Read as an outsider, that
104
+ * pass published the committed view and queued a replay that revealed the
105
+ * override beside its unready derivation at the release (`1:0` for an
106
+ * optimistic frame that never became ready; #3479 review). Membership is the
107
+ * wrong test the other way: a member re-run by a sibling's sync write is a
108
+ * mainline pass and shows the committed view.
109
+ */ function readsHeldCommitted(n, e) {
110
+ const i = resolveLane(n);
111
+ if (!i || !laneHeld(i)) return false;
112
+ if (ownsLane(i, n)) return false;
113
+ i.dn[0].push(() => e.oe & REACTIVE_DISPOSED || enqueueSub(e));
114
+ return true;
115
+ }
116
+
117
+ /** The ownership relation for a lane hold (core `ownsHold`, §6 ruling 2): the
118
+ * running pass owns `lane`'s hold if it runs under the transition that owns
119
+ * the lane (the node's, resolved through override ownership and merges) or
120
+ * inside the lane itself. */ function ownsLane(n, e) {
121
+ if (activeTransition !== null) {
122
+ const n = resolveTransition(e);
123
+ if (n && ownsHold(n)) return true;
124
+ }
125
+ return currentOptimisticLane !== null && findLane(currentOptimisticLane) === n;
126
+ }
127
+
61
128
  /**
62
129
  * Merge two lanes when their dependency graphs overlap.
63
130
  */ function mergeLanes(n, e) {
64
131
  n = findLane(n);
65
132
  e = findLane(e);
66
133
  if (n === e) return n;
67
- e.tn = n;
134
+ e.ei = n;
68
135
  // Move (not copy) the merged lane's work: after the merge all routing goes
69
136
  // through findLane() to the root, so anything left behind here is dead —
70
137
  // and anything *added* here later is a routing bug (INV-5).
71
- for (const i of e.Ae) n.Ae.add(i);
72
- e.Ae.clear();
73
- n.rn[0].push(...e.rn[0]);
74
- n.rn[1].push(...e.rn[1]);
75
- e.rn[0].length = 0;
76
- e.rn[1].length = 0;
138
+ for (const i of e.Qe) n.Qe.add(i);
139
+ e.Qe.clear();
140
+ n.dn[0].push(...e.dn[0]);
141
+ n.dn[1].push(...e.dn[1]);
142
+ e.dn[0].length = 0;
143
+ e.dn[1].length = 0;
77
144
  return n;
78
145
  }
79
146
 
80
147
  /**
81
148
  * Resolve a node's lane: follow union-find chain, verify active, clear if stale.
82
149
  */ function resolveLane(n) {
83
- const e = n.Ke;
150
+ const e = n.o?.me;
84
151
  if (!e) return undefined;
85
152
  const i = findLane(e);
86
153
  if (activeLanes.has(i)) return i;
87
- n.Ke = undefined;
154
+ if (n.o !== null) n.o.me = undefined;
88
155
  return undefined;
89
156
  }
90
157
 
@@ -94,18 +161,12 @@ function resolveTransition(n) {
94
161
  // transactions (#2912) — the merged root's _transition would hand this
95
162
  // node's override to whichever action wrote last through the shared
96
163
  // reader. Chase merge chains; a dead owner settled through another path.
97
- if (hasActiveOverride(n) && n.sn) {
98
- const e = n.sn = currentTransition(n.sn);
99
- if (e.fn !== true) return e;
100
- n.sn = null;
164
+ if (hasActiveOverride(n) && n.o?.Ln) {
165
+ const e = ext(n).Ln = currentTransition(n.o?.Ln);
166
+ if (e.Rn !== true) return e;
167
+ if (n.o !== null) n.o.Ln = null;
101
168
  }
102
- return resolveLane(n)?.Ne ?? n.Ne;
103
- }
104
-
105
- /**
106
- * Check if a node has an active optimistic override.
107
- */ function hasActiveOverride(n) {
108
- return !!(n.De !== undefined && n.De !== NOT_PENDING);
169
+ return resolveLane(n)?.we ?? n.we;
109
170
  }
110
171
 
111
172
  /**
@@ -113,28 +174,32 @@ function resolveTransition(n) {
113
174
  * a different active lane), merge unless the node has an active override.
114
175
  */ function assignOrMergeLane(n, e) {
115
176
  const i = findLane(e);
116
- const r = n.Ke;
117
- if (r) {
118
- // If the subscriber's lane was merged into another lane, it's stale —
119
- // replace it with the new source lane instead of following the merge chain
120
- // (which would incorrectly merge the new lane into the old group)
121
- if (r.tn) {
122
- n.Ke = e;
123
- return;
124
- }
125
- const t = findLane(r);
126
- if (activeLanes.has(t)) {
127
- if (t !== i && !hasActiveOverride(n)) {
177
+ const t = n.o?.me;
178
+ if (t) {
179
+ // A merged lane is followed to its root like any other: the root is where
180
+ // the subscriber's affinity lives now. Replacing it with the source lane
181
+ // outright (as this once did) skipped the parent/child check below — an
182
+ // isPending reader of two async siblings had their two companion lanes
183
+ // merge, and the next parent-lane notification then moved it onto the
184
+ // held parent, where its verdict waited on the async it reports (#3409).
185
+ const r = findLane(t);
186
+ if (activeLanes.has(r)) {
187
+ // A WRITTEN override is its own lane's source and merges nothing
188
+ // through it; a derived one (lanes stage, #3479) is a plain member —
189
+ // the shared reader that merges two writers' lanes carries one.
190
+ if (r !== i && (!hasActiveOverride(n) || n.C & CONFIG_DERIVED_OVERRIDE)) {
128
191
  // Parent-child lanes stay independent so isPending resolves without
129
192
  // waiting for the parent's async. The child keeps ownership.
130
- if (i.an && findLane(i.an) === t) {
131
- n.Ke = e;
132
- } else if (t.an && findLane(t.an) === i) ; else mergeLanes(i, t);
193
+ if (i.ii && findLane(i.ii) === r) {
194
+ ext(n).me = e;
195
+ n.C |= CONFIG_HAS_LANE;
196
+ } else if (r.ii && findLane(r.ii) === i) ; else mergeLanes(i, r);
133
197
  }
134
198
  return;
135
199
  }
136
200
  }
137
- n.Ke = e;
201
+ ext(n).me = e;
202
+ n.C |= CONFIG_HAS_LANE;
138
203
  }
139
204
 
140
- export { activeLanes, assignOrMergeLane, findLane, getOrCreateLane, hasActiveOverride, mergeLanes, resolveLane, resolveTransition, signalLanes };
205
+ export { activeLanes, assignOrMergeLane, findLane, getOrCreateLane, hasActiveOverride, laneHeld, mergeLanes, ownsLane, readsHeldCommitted, resolveLane, resolveTransition, signalLanes };