@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.
- package/README.md +1 -1
- package/dist/dev-shared.js +7138 -0
- package/dist/dev.attribution.js +3307 -0
- package/dist/dev.js +8076 -6692
- package/dist/observe/affects.js +129 -0
- package/dist/observe/attribution.js +7 -0
- package/dist/observe/boundaries.js +793 -0
- package/dist/observe/core/action.js +177 -0
- package/dist/observe/core/async.js +849 -0
- package/dist/observe/core/attribution-costs.js +66 -0
- package/dist/observe/core/attribution-feedback.js +280 -0
- package/dist/observe/core/attribution-hooks.js +83 -0
- package/dist/observe/core/attribution-queries.js +43 -0
- package/dist/observe/core/attribution.js +2904 -0
- package/dist/observe/core/constants.js +283 -0
- package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
- package/dist/observe/core/core.js +1999 -0
- package/dist/observe/core/dev.js +343 -0
- package/dist/observe/core/effect.js +200 -0
- package/dist/observe/core/error-hooks.js +71 -0
- package/dist/observe/core/error.js +80 -0
- package/dist/observe/core/external.js +98 -0
- package/dist/observe/core/graph.js +155 -0
- package/dist/observe/core/heap.js +147 -0
- package/dist/observe/core/invariants.js +45 -0
- package/dist/observe/core/lanes.js +205 -0
- package/dist/observe/core/optimistic.js +627 -0
- package/dist/observe/core/owner.js +353 -0
- package/dist/observe/core/scheduler.js +1547 -0
- package/dist/observe/core/verdict.js +674 -0
- package/dist/observe/index.js +59 -0
- package/dist/observe/map.js +484 -0
- package/dist/observe/signals.js +731 -0
- package/dist/observe/store/index.js +44 -0
- package/dist/observe/store/next/optimistic.js +717 -0
- package/dist/observe/store/next/projection.js +266 -0
- package/dist/observe/store/next/reconcile.js +375 -0
- package/dist/observe/store/next/store.js +2480 -0
- package/dist/observe/store/next/target.js +51 -0
- package/dist/observe/store/store.js +331 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/utils.js +1070 -0
- package/dist/prod/affects.js +10 -9
- package/dist/prod/attribution.js +45 -0
- package/dist/prod/boundaries.js +388 -178
- package/dist/prod/core/action.js +65 -37
- package/dist/prod/core/async.js +477 -208
- package/dist/prod/core/attribution-hooks.js +3 -0
- package/dist/prod/core/constants.js +186 -1
- package/dist/prod/core/context.js +10 -16
- package/dist/prod/core/core.js +1556 -415
- package/dist/prod/core/dev.js +18 -1
- package/dist/prod/core/effect.js +119 -79
- package/dist/prod/core/error-hooks.js +71 -0
- package/dist/prod/core/error.js +13 -1
- package/dist/prod/core/external.js +4 -4
- package/dist/prod/core/graph.js +105 -54
- package/dist/prod/core/heap.js +72 -65
- package/dist/prod/core/invariants.js +3 -2
- package/dist/prod/core/lanes.js +117 -52
- package/dist/prod/core/optimistic.js +474 -103
- package/dist/prod/core/owner.js +131 -84
- package/dist/prod/core/scheduler.js +1013 -248
- package/dist/prod/core/verdict.js +418 -113
- package/dist/prod/index.js +25 -13
- package/dist/prod/map.js +314 -151
- package/dist/prod/signals.js +382 -32
- package/dist/prod/store/index.js +38 -0
- package/dist/prod/store/next/optimistic.js +710 -0
- package/dist/prod/store/next/projection.js +257 -0
- package/dist/prod/store/next/reconcile.js +373 -0
- package/dist/prod/store/next/store.js +2356 -0
- package/dist/prod/store/next/target.js +51 -0
- package/dist/prod/store/store.js +129 -881
- package/dist/prod/store/utils.js +982 -242
- package/dist/types/attribution.d.ts +19 -0
- package/dist/types/attribution.prod.d.ts +22 -0
- package/dist/types/boundaries.d.ts +78 -5
- package/dist/types/core/action.d.ts +12 -5
- package/dist/types/core/async.d.ts +3 -1
- package/dist/types/core/attribution-costs.d.ts +35 -0
- package/dist/types/core/attribution-feedback.d.ts +133 -0
- package/dist/types/core/attribution-hooks.d.ts +304 -0
- package/dist/types/core/attribution-queries.d.ts +24 -0
- package/dist/types/core/attribution.d.ts +892 -0
- package/dist/types/core/constants.d.ts +179 -0
- package/dist/types/core/core.d.ts +305 -23
- package/dist/types/core/dev.d.ts +421 -8
- package/dist/types/core/effect.d.ts +8 -1
- package/dist/types/core/error-hooks.d.ts +71 -0
- package/dist/types/core/error.d.ts +9 -0
- package/dist/types/core/graph.d.ts +23 -0
- package/dist/types/core/heap.d.ts +5 -3
- package/dist/types/core/index.d.ts +6 -3
- package/dist/types/core/invariants.d.ts +5 -1
- package/dist/types/core/lanes.d.ts +51 -19
- package/dist/types/core/owner.d.ts +15 -3
- package/dist/types/core/scheduler.d.ts +252 -3
- package/dist/types/core/types.d.ts +124 -41
- package/dist/types/index.d.ts +18 -5
- package/dist/types/map.d.ts +2 -0
- package/dist/types/signals.d.ts +164 -13
- package/dist/types/store/index.d.ts +16 -5
- package/dist/types/store/next/optimistic.d.ts +25 -0
- package/dist/types/store/next/projection.d.ts +27 -0
- package/dist/types/store/next/reconcile.d.ts +10 -0
- package/dist/types/store/next/store.d.ts +143 -0
- package/dist/types/store/next/target.d.ts +196 -0
- package/dist/types/store/store.d.ts +46 -112
- package/dist/types/store/utils.d.ts +188 -40
- package/package.json +32 -26
- package/dist/node.cjs +0 -7938
- package/dist/prod/store/optimistic.js +0 -217
- package/dist/prod/store/projection.js +0 -231
- package/dist/prod/store/reconcile.js +0 -707
- package/dist/types/store/optimistic.d.ts +0 -45
- package/dist/types/store/projection.d.ts +0 -70
- package/dist/types/store/reconcile.d.ts +0 -46
- package/dist/types-cjs/affects.d.cts +0 -47
- package/dist/types-cjs/boundaries.d.cts +0 -175
- package/dist/types-cjs/core/action.d.cts +0 -64
- package/dist/types-cjs/core/async.d.cts +0 -21
- package/dist/types-cjs/core/constants.d.cts +0 -71
- package/dist/types-cjs/core/core.d.cts +0 -148
- package/dist/types-cjs/core/dev.d.cts +0 -64
- package/dist/types-cjs/core/effect.d.cts +0 -30
- package/dist/types-cjs/core/error.d.cts +0 -47
- package/dist/types-cjs/core/external.d.cts +0 -15
- package/dist/types-cjs/core/graph.d.cts +0 -5
- package/dist/types-cjs/core/heap.d.cts +0 -22
- package/dist/types-cjs/core/index.d.cts +0 -13
- package/dist/types-cjs/core/invariants.d.cts +0 -59
- package/dist/types-cjs/core/lanes.d.cts +0 -56
- package/dist/types-cjs/core/optimistic.d.cts +0 -6
- package/dist/types-cjs/core/owner.d.cts +0 -124
- package/dist/types-cjs/core/scheduler.d.cts +0 -170
- package/dist/types-cjs/core/types.d.cts +0 -148
- package/dist/types-cjs/core/verdict.d.cts +0 -2
- package/dist/types-cjs/index.d.cts +0 -10
- package/dist/types-cjs/map.d.cts +0 -69
- package/dist/types-cjs/package.json +0 -3
- package/dist/types-cjs/signals.d.cts +0 -605
- package/dist/types-cjs/store/index.d.cts +0 -9
- package/dist/types-cjs/store/optimistic.d.cts +0 -45
- package/dist/types-cjs/store/projection.d.cts +0 -70
- package/dist/types-cjs/store/reconcile.d.cts +0 -46
- package/dist/types-cjs/store/store.d.cts +0 -213
- package/dist/types-cjs/store/storePath.d.cts +0 -58
- package/dist/types-cjs/store/utils.d.cts +0 -114
package/dist/prod/core/heap.js
CHANGED
|
@@ -1,104 +1,111 @@
|
|
|
1
|
-
import
|
|
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.
|
|
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:
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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.Ft);
|
|
19
|
-
}
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
18
|
const E = queueFor(e);
|
|
23
|
-
if (E.
|
|
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.
|
|
29
|
-
if (t >= e.
|
|
30
|
-
const n = e.
|
|
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.
|
|
34
|
-
E.
|
|
35
|
-
e.
|
|
36
|
-
I.
|
|
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.
|
|
43
|
-
|
|
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.
|
|
44
|
+
e.oe = t & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
|
|
46
45
|
} else {
|
|
47
|
-
e.
|
|
48
|
-
// An unmarked node entering
|
|
49
|
-
// `_marked` is only reset by
|
|
50
|
-
// pulls (read-time markHeap +
|
|
51
|
-
// this node unmarked and every
|
|
52
|
-
// flush (#2922: the second
|
|
53
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
70
|
+
const t = e.oe;
|
|
67
71
|
if (!(t & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
|
|
68
|
-
e.
|
|
69
|
-
const n = e.
|
|
70
|
-
if (e.
|
|
71
|
-
const t = e.
|
|
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.
|
|
75
|
-
o.
|
|
78
|
+
if (e === I) E.eE[n] = t; else e.Fn.Pn = t;
|
|
79
|
+
o.Fn = e.Fn;
|
|
76
80
|
}
|
|
77
|
-
e.
|
|
78
|
-
e.
|
|
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.
|
|
86
|
-
if (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.
|
|
96
|
+
const t = e.oe;
|
|
93
97
|
if ((t & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= E) return;
|
|
94
|
-
e.
|
|
95
|
-
for (let E = e.
|
|
96
|
-
markNode(E.
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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.
|
|
110
|
-
let t = e.eE[e.
|
|
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.
|
|
113
|
-
t = e.eE[e.
|
|
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.
|
|
122
|
-
for (let E = e.
|
|
123
|
-
const e = E.
|
|
124
|
-
const n = e.
|
|
125
|
-
if (n.
|
|
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.
|
|
128
|
-
e.
|
|
129
|
-
for (let E = e.
|
|
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.
|
|
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
|
|
package/dist/prod/core/lanes.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CONFIG_DERIVED_OVERRIDE, CONFIG_HAS_LANE, REACTIVE_DISPOSED } from "./constants.js";
|
|
2
2
|
|
|
3
|
-
import {
|
|
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.
|
|
22
|
-
const
|
|
25
|
+
const i = n.o?.kn;
|
|
26
|
+
const t = i?.o?.me;
|
|
27
|
+
const r = t ? findLane(t) : null;
|
|
23
28
|
e = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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.
|
|
40
|
-
adoptCompanionLane(n.
|
|
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
|
|
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 (
|
|
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.
|
|
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.
|
|
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.
|
|
72
|
-
e.
|
|
73
|
-
n.
|
|
74
|
-
n.
|
|
75
|
-
e.
|
|
76
|
-
e.
|
|
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.
|
|
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.
|
|
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.
|
|
98
|
-
const e = n.
|
|
99
|
-
if (e.
|
|
100
|
-
n.
|
|
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)?.
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Check if a node has an active optimistic override.
|
|
107
|
-
*/ function hasActiveOverride(n) {
|
|
108
|
-
return !!(n._e !== undefined && n._e !== 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
|
|
117
|
-
if (
|
|
118
|
-
//
|
|
119
|
-
//
|
|
120
|
-
// (
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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.
|
|
131
|
-
n.
|
|
132
|
-
|
|
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.
|
|
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 };
|