@solidjs/signals 2.0.0-rc.7 → 2.0.0-rc.8
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/dist/dev-shared.js +5243 -0
- package/dist/dev.attribution.js +2333 -0
- package/dist/dev.js +1229 -6834
- package/dist/observe/affects.js +127 -0
- package/dist/observe/attribution.js +1 -0
- package/dist/observe/boundaries.js +586 -0
- package/dist/observe/core/action.js +167 -0
- package/dist/observe/core/async.js +736 -0
- package/dist/observe/core/attribution-hooks.js +60 -0
- package/dist/observe/core/attribution.js +2318 -0
- package/dist/{types-cjs/core/constants.d.cts → observe/core/constants.js} +129 -73
- package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
- package/dist/observe/core/core.js +1289 -0
- package/dist/observe/core/dev.js +232 -0
- package/dist/observe/core/effect.js +179 -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 +43 -0
- package/dist/observe/core/lanes.js +168 -0
- package/dist/observe/core/optimistic.js +438 -0
- package/dist/observe/core/owner.js +308 -0
- package/dist/observe/core/scheduler.js +1190 -0
- package/dist/observe/core/verdict.js +551 -0
- package/dist/observe/index.js +55 -0
- package/dist/observe/map.js +482 -0
- package/dist/{types-cjs/signals.d.cts → observe/signals.js} +295 -317
- package/dist/observe/store/index.js +38 -0
- package/dist/observe/store/next/optimistic.js +651 -0
- package/dist/observe/store/next/projection.js +242 -0
- package/dist/observe/store/next/reconcile.js +373 -0
- package/dist/observe/store/next/store.js +2213 -0
- package/dist/observe/store/next/target.js +51 -0
- package/dist/observe/store/store.js +323 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/utils.js +210 -0
- package/dist/prod/attribution.js +32 -0
- package/dist/prod/core/action.js +52 -32
- package/dist/prod/core/async.js +171 -127
- package/dist/prod/core/constants.js +24 -1
- package/dist/prod/core/context.js +3 -3
- package/dist/prod/core/core.js +434 -291
- package/dist/prod/core/effect.js +54 -34
- package/dist/prod/core/external.js +2 -2
- package/dist/prod/core/graph.js +32 -32
- package/dist/prod/core/heap.js +49 -44
- package/dist/prod/core/lanes.js +45 -38
- package/dist/prod/core/optimistic.js +207 -73
- package/dist/prod/core/owner.js +43 -39
- package/dist/prod/core/scheduler.js +319 -190
- package/dist/prod/core/verdict.js +67 -67
- package/dist/prod/index.js +9 -3
- package/dist/prod/map.js +292 -141
- package/dist/prod/signals.js +7 -10
- package/dist/prod/store/next/optimistic.js +140 -125
- package/dist/prod/store/next/projection.js +3 -3
- package/dist/prod/store/next/reconcile.js +87 -84
- package/dist/prod/store/next/store.js +524 -280
- package/dist/prod/store/next/target.js +32 -10
- package/dist/prod/store/store.js +12 -14
- package/dist/prod/store/utils.js +36 -27
- package/dist/types/attribution.d.ts +15 -0
- package/dist/types/attribution.prod.d.ts +13 -0
- package/dist/types/core/async.d.ts +1 -1
- package/dist/types/core/attribution-hooks.d.ts +119 -6
- package/dist/types/core/attribution.d.ts +208 -53
- package/dist/types/core/constants.d.ts +23 -0
- package/dist/types/core/core.d.ts +7 -0
- package/dist/types/core/dev.d.ts +124 -26
- package/dist/types/core/effect.d.ts +8 -1
- package/dist/types/core/index.d.ts +2 -1
- package/dist/types/core/lanes.d.ts +8 -1
- package/dist/types/core/scheduler.d.ts +60 -0
- package/dist/types/core/types.d.ts +29 -9
- package/dist/types/index.d.ts +9 -2
- package/dist/types/map.d.ts +2 -0
- package/dist/types/store/index.d.ts +1 -0
- package/dist/types/store/next/store.d.ts +5 -0
- package/dist/types/store/next/target.d.ts +36 -9
- package/dist/types/store/utils.d.ts +7 -0
- package/package.json +21 -17
- package/dist/node.cjs +0 -10541
- package/dist/node.dev.cjs +0 -13724
- 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 -23
- package/dist/types-cjs/core/attribution-hooks.d.cts +0 -127
- package/dist/types-cjs/core/attribution.d.cts +0 -495
- package/dist/types-cjs/core/core.d.cts +0 -185
- package/dist/types-cjs/core/dev.d.cts +0 -136
- package/dist/types-cjs/core/effect.d.cts +0 -30
- package/dist/types-cjs/core/error.d.cts +0 -56
- package/dist/types-cjs/core/external.d.cts +0 -15
- package/dist/types-cjs/core/graph.d.cts +0 -28
- package/dist/types-cjs/core/heap.d.cts +0 -24
- 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 -54
- 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 -236
- package/dist/types-cjs/core/types.d.cts +0 -204
- 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/store/index.d.cts +0 -18
- package/dist/types-cjs/store/next/optimistic.d.cts +0 -25
- package/dist/types-cjs/store/next/projection.d.cts +0 -8
- package/dist/types-cjs/store/next/reconcile.d.cts +0 -10
- package/dist/types-cjs/store/next/store.d.cts +0 -121
- package/dist/types-cjs/store/next/target.d.cts +0 -166
- package/dist/types-cjs/store/store.d.cts +0 -143
- package/dist/types-cjs/store/storePath.d.cts +0 -58
- package/dist/types-cjs/store/utils.d.cts +0 -74
package/dist/prod/core/effect.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { REACTIVE_DISPOSED, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, STATUS_PENDING } from "./constants.js";
|
|
1
|
+
import { REACTIVE_DISPOSED, LANE_RUN, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, STATUS_PENDING } from "./constants.js";
|
|
2
2
|
|
|
3
3
|
import { setEffectStatusNotify, ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
|
|
4
4
|
|
|
@@ -6,26 +6,26 @@ import { unwrapStatusError, StatusError } from "./error.js";
|
|
|
6
6
|
|
|
7
7
|
import { enqueueSub } from "./heap.js";
|
|
8
8
|
|
|
9
|
-
import { GlobalQueue, haltReactivity, schedule } from "./scheduler.js";
|
|
9
|
+
import { GlobalQueue, currentTransition, activeTransition, haltReactivity, schedule } from "./scheduler.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
|
13
13
|
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
|
14
14
|
* sources and recompute
|
|
15
|
-
*/ function effect(t, e, E,
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
recompute(
|
|
19
|
-
!
|
|
15
|
+
*/ function effect(t, e, E, r) {
|
|
16
|
+
const n = !!r?.user;
|
|
17
|
+
const f = createEffectNode(t, e, E, n ? EFFECT_USER : EFFECT_RENDER, r);
|
|
18
|
+
recompute(f, true);
|
|
19
|
+
!r?.defer && (f.Ce === EFFECT_USER || r?.schedule ? f.C.enqueue(f.Ce, runEffect.bind(null, f)) : runEffect(f, LANE_RUN));
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function notifyEffectStatus(t, e) {
|
|
23
23
|
// Use passed values if provided, otherwise read from node
|
|
24
24
|
const E = t !== undefined ? t : this.S;
|
|
25
|
-
const
|
|
25
|
+
const r = e !== undefined ? e : this.o?._;
|
|
26
26
|
if (E & STATUS_ERROR) {
|
|
27
27
|
this.C.notify(this, STATUS_PENDING, 0);
|
|
28
|
-
if (this.
|
|
28
|
+
if (this.Ce === EFFECT_USER) {
|
|
29
29
|
// The error handler is the error arm of the effect phase (#2840 ruling):
|
|
30
30
|
// queue it like the effect function. It runs in the same imperative,
|
|
31
31
|
// writable scope, throws escalate the same way, and a held transition
|
|
@@ -37,21 +37,41 @@ function notifyEffectStatus(t, e) {
|
|
|
37
37
|
// re-propagates unblocked at commit.
|
|
38
38
|
if (this.S & STATUS_ERROR) {
|
|
39
39
|
this.He = true;
|
|
40
|
-
this.C.enqueue(this.
|
|
40
|
+
this.C.enqueue(this.Ce, this.rt ??= runEffect.bind(null, this));
|
|
41
41
|
}
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
if (!this.C.notify(this, STATUS_ERROR, STATUS_ERROR)) {
|
|
45
|
-
haltReactivity(unwrapStatusError(
|
|
46
|
-
throw
|
|
45
|
+
haltReactivity(unwrapStatusError(r));
|
|
46
|
+
throw r;
|
|
47
47
|
}
|
|
48
|
-
} else if (this.
|
|
49
|
-
this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E,
|
|
48
|
+
} else if (this.Ce === EFFECT_RENDER) {
|
|
49
|
+
this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E, r);
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function runEffect(t) {
|
|
53
|
+
function runEffect(t, e) {
|
|
54
54
|
if (!t.He || t.ie & REACTIVE_DISPOSED) return;
|
|
55
|
+
// Ownership (#3319): a value computed under a transaction is applied by that
|
|
56
|
+
// transaction's commit. The ordinary effect phase runs with a transaction
|
|
57
|
+
// active only when the flush's finalize ENTERED one (every other path parks
|
|
58
|
+
// or settles first): leave a run owned by a still-held transaction queued —
|
|
59
|
+
// `_modified` stays set — and the next gate stashes it with the owner.
|
|
60
|
+
// Mainline-owned runs (null) apply now. Lanes are exempt by design (they
|
|
61
|
+
// apply their own effects ahead of their transaction — the optimistic view)
|
|
62
|
+
// and mark their runs with LANE_RUN.
|
|
63
|
+
|
|
64
|
+
// Lane exemption has one exception (#3331): a lane runner for an effect that
|
|
65
|
+
// no longer rides a lane — its optimistic source was superseded, so the lane
|
|
66
|
+
// has no optimistic view left to apply, and the value this effect now
|
|
67
|
+
// carries (or will, once its plain recompute lands) belongs to the still-held
|
|
68
|
+
// transaction. Hand the run to the regular queue, where the transaction's
|
|
69
|
+
// gate stashes it with the owner. Lane-less runners with no live owner
|
|
70
|
+
// (reverts, wake-only lanes) apply now.
|
|
71
|
+
if (t._t !== null && !currentTransition(t._t).ft && (e & LANE_RUN ? !t.o?.Oe : activeTransition !== null)) {
|
|
72
|
+
t.C.enqueue(t.Ce, t.rt);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
55
75
|
// Error arm (#2840), user effects only: a compute-phase error that is still
|
|
56
76
|
// the node's settled state at effect time runs the bundle's error handler in
|
|
57
77
|
// this same imperative, writable scope. Unwrap the StatusError used for
|
|
@@ -62,14 +82,14 @@ function runEffect(t) {
|
|
|
62
82
|
// Render effects bypass: their errors route to boundaries synchronously in
|
|
63
83
|
// notifyEffectStatus, and a runner queued by an earlier valueChanged in the
|
|
64
84
|
// same flush must not be hijacked by a later-arriving error status.
|
|
65
|
-
if (t.S & STATUS_ERROR && t.
|
|
85
|
+
if (t.S & STATUS_ERROR && t.Ce === EFFECT_USER) {
|
|
66
86
|
const e = unwrapStatusError(t.o?._);
|
|
67
|
-
t.
|
|
87
|
+
t.Ft = t.me;
|
|
68
88
|
t.He = false;
|
|
69
89
|
try {
|
|
70
|
-
t.
|
|
71
|
-
const e = t.
|
|
72
|
-
t.
|
|
90
|
+
t.vt ? t.vt(e, () => {
|
|
91
|
+
const e = t.Ht;
|
|
92
|
+
t.Ht = undefined;
|
|
73
93
|
e?.();
|
|
74
94
|
}) : console.error(e);
|
|
75
95
|
} catch (e) {
|
|
@@ -80,14 +100,14 @@ function runEffect(t) {
|
|
|
80
100
|
}
|
|
81
101
|
return;
|
|
82
102
|
}
|
|
83
|
-
const
|
|
84
|
-
t.
|
|
103
|
+
const E = t.Ht;
|
|
104
|
+
t.Ht = undefined;
|
|
85
105
|
try {
|
|
86
|
-
|
|
87
|
-
const
|
|
88
|
-
if (false &&
|
|
106
|
+
E?.();
|
|
107
|
+
const e = t.ht(t.me, t.Ft);
|
|
108
|
+
if (false && e !== undefined && typeof e !== "function") ;
|
|
89
109
|
// The final cleanup is invoked by disposeChildren at true disposal.
|
|
90
|
-
t.
|
|
110
|
+
t.Ht = e;
|
|
91
111
|
} catch (e) {
|
|
92
112
|
ext(t)._ = new StatusError(t, e);
|
|
93
113
|
t.S |= STATUS_ERROR;
|
|
@@ -96,12 +116,12 @@ function runEffect(t) {
|
|
|
96
116
|
throw e;
|
|
97
117
|
}
|
|
98
118
|
} finally {
|
|
99
|
-
t.
|
|
119
|
+
t.Ft = t.me;
|
|
100
120
|
t.He = false;
|
|
101
121
|
}
|
|
102
122
|
}
|
|
103
123
|
|
|
104
|
-
GlobalQueue.
|
|
124
|
+
GlobalQueue.ct = runEffect;
|
|
105
125
|
|
|
106
126
|
/**
|
|
107
127
|
* Internal tracked effect - bypasses heap, goes directly to effect queue.
|
|
@@ -119,19 +139,19 @@ GlobalQueue.ut = runEffect;
|
|
|
119
139
|
} finally {}
|
|
120
140
|
};
|
|
121
141
|
const E = computed(() => {
|
|
122
|
-
const e = E.
|
|
123
|
-
E.
|
|
142
|
+
const e = E.Ht;
|
|
143
|
+
E.Ht = undefined;
|
|
124
144
|
e?.();
|
|
125
|
-
const
|
|
126
|
-
E.
|
|
145
|
+
const r = staleValues(t);
|
|
146
|
+
E.Ht = r;
|
|
127
147
|
}, {
|
|
128
148
|
...e,
|
|
129
149
|
lazy: true
|
|
130
150
|
});
|
|
131
|
-
E.
|
|
151
|
+
E.Ht = undefined;
|
|
132
152
|
E.T = E.T & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
|
|
133
153
|
E.He = true;
|
|
134
|
-
E.
|
|
154
|
+
E.Ce = EFFECT_TRACKED;
|
|
135
155
|
// Status dispatch rides the SHARED notifier (statusNotifierOf keys off
|
|
136
156
|
// _type): its error arm is behavior-identical to the closure that used to
|
|
137
157
|
// live here, without the per-node NodeExtension allocation.
|
|
@@ -64,8 +64,8 @@ function externalUntrack(e) {
|
|
|
64
64
|
// removed on reset) so core's null checks stay equivalent to the old
|
|
65
65
|
// `externalSourceConfig` truthiness checks.
|
|
66
66
|
function syncExternalHooks() {
|
|
67
|
-
GlobalQueue.
|
|
68
|
-
GlobalQueue.
|
|
67
|
+
GlobalQueue.kt = externalSourceConfig ? wireExternalSource : null;
|
|
68
|
+
GlobalQueue.Lt = externalSourceConfig ? externalUntrack : null;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function enableExternalSource(e) {
|
package/dist/prod/core/graph.js
CHANGED
|
@@ -10,17 +10,17 @@ import { bumpNotifyEpoch } from "./scheduler.js";
|
|
|
10
10
|
|
|
11
11
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
|
|
12
12
|
function unlinkSubs(e) {
|
|
13
|
-
const n = e.
|
|
14
|
-
const l = e.
|
|
15
|
-
const o = e.
|
|
13
|
+
const n = e.Se;
|
|
14
|
+
const l = e.ae;
|
|
15
|
+
const o = e.Te;
|
|
16
16
|
const s = e.en;
|
|
17
|
-
if (o !== null) o.en = s; else n.
|
|
18
|
-
if (s !== null) s.
|
|
17
|
+
if (o !== null) o.en = s; else n.dt = s;
|
|
18
|
+
if (s !== null) s.Te = o; else {
|
|
19
19
|
n.u = o;
|
|
20
20
|
if (o === null) {
|
|
21
21
|
// Slot nodes (store leaves) dispatch to the ONE shared hook — no
|
|
22
22
|
// per-node unobserved closure, no NodeExtension to hold it.
|
|
23
|
-
if (n.T & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.o?.
|
|
23
|
+
if (n.T & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.o?.Ct?.();
|
|
24
24
|
// No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
|
|
25
25
|
// A pending node is exempt: its in-flight async work (or the
|
|
26
26
|
// transition holding it) is an observer — tearing down would orphan
|
|
@@ -35,13 +35,13 @@ function unlinkSubs(e) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function trimStaleDeps(e) {
|
|
38
|
-
const n = e.
|
|
39
|
-
let l = n !== null ? n.
|
|
38
|
+
const n = e.et;
|
|
39
|
+
let l = n !== null ? n.ae : e.fe;
|
|
40
40
|
if (l !== null) {
|
|
41
41
|
do {
|
|
42
42
|
l = unlinkSubs(l);
|
|
43
43
|
} while (l !== null);
|
|
44
|
-
if (n !== null) n.
|
|
44
|
+
if (n !== null) n.ae = null; else e.fe = null;
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
@@ -50,13 +50,13 @@ function trimStaleDeps(e) {
|
|
|
50
50
|
// and skipping early also avoids adding one (hidden-class churn) via the
|
|
51
51
|
// null-out below.
|
|
52
52
|
function clearDeps(e) {
|
|
53
|
-
let n = e.
|
|
53
|
+
let n = e.fe;
|
|
54
54
|
if (!n) return;
|
|
55
55
|
do {
|
|
56
56
|
n = unlinkSubs(n);
|
|
57
57
|
} while (n !== null);
|
|
58
|
-
e.
|
|
59
|
-
e.
|
|
58
|
+
e.fe = null;
|
|
59
|
+
e.et = null;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function unobserved(e) {
|
|
@@ -108,20 +108,20 @@ function link(e, n, l = false) {
|
|
|
108
108
|
// not relabel the value dependency as probe-only — the value read is what
|
|
109
109
|
// real-error propagation and affects() coverage key off, regardless of
|
|
110
110
|
// read order within the computation.
|
|
111
|
-
const o = n.
|
|
112
|
-
if (o !== null && o.
|
|
113
|
-
o.
|
|
111
|
+
const o = n.et;
|
|
112
|
+
if (o !== null && o.Se === e) {
|
|
113
|
+
o.je &&= l;
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
116
|
let s = null;
|
|
117
117
|
const t = n.ie & REACTIVE_RECOMPUTING_DEPS;
|
|
118
118
|
if (t) {
|
|
119
|
-
s = o !== null ? o.
|
|
120
|
-
if (s !== null && s.
|
|
121
|
-
s.
|
|
122
|
-
n.
|
|
119
|
+
s = o !== null ? o.ae : n.fe;
|
|
120
|
+
if (s !== null && s.Se === e) {
|
|
121
|
+
s.yt = n.tt;
|
|
122
|
+
n.et = s;
|
|
123
123
|
// First touch of this pass: the previous pass's label is stale.
|
|
124
|
-
s.
|
|
124
|
+
s.je = l;
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -130,24 +130,24 @@ function link(e, n, l = false) {
|
|
|
130
130
|
// [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
|
|
131
131
|
// (the old alien-signals `isValidLink` walk, O(n²) when a computation
|
|
132
132
|
// re-reads earlier deps non-consecutively, e.g. store leaf reads).
|
|
133
|
-
const r = e.
|
|
134
|
-
if (r !== null && r.
|
|
133
|
+
const r = e.dt;
|
|
134
|
+
if (r !== null && r.Ie === n && (!t || r.yt === n.tt)) {
|
|
135
135
|
// Gen-matched during a recompute = repeat touch this pass (AND); outside
|
|
136
136
|
// a recompute there is no pass boundary, so the latest read labels it.
|
|
137
|
-
if (t) r.
|
|
137
|
+
if (t) r.je &&= l; else r.je = l;
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
-
const u = n.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
140
|
+
const u = n.et = e.dt = {
|
|
141
|
+
Se: e,
|
|
142
|
+
Ie: n,
|
|
143
|
+
ae: s,
|
|
144
144
|
en: r,
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
145
|
+
Te: null,
|
|
146
|
+
yt: n.tt,
|
|
147
|
+
je: l
|
|
148
148
|
};
|
|
149
|
-
if (o !== null) o.
|
|
150
|
-
if (r !== null) r.
|
|
149
|
+
if (o !== null) o.ae = u; else n.fe = u;
|
|
150
|
+
if (r !== null) r.Te = u; else e.u = u;
|
|
151
151
|
// New subscriber edge: staged-rewrite skips (§12d) must not miss it.
|
|
152
152
|
bumpNotifyEpoch();
|
|
153
153
|
}
|
package/dist/prod/core/heap.js
CHANGED
|
@@ -16,22 +16,22 @@ import { zombieQueue, dirtyQueue } from "./scheduler.js";
|
|
|
16
16
|
* (see GlobalQueue._update, #3291).
|
|
17
17
|
*/ function enqueueSub(e) {
|
|
18
18
|
const E = queueFor(e);
|
|
19
|
-
if (E.
|
|
19
|
+
if (E.Ke > e.Be) E.Ke = e.Be;
|
|
20
20
|
insertIntoHeap(e, E);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
function actualInsertIntoHeap(e, E) {
|
|
24
|
-
const t = (e.
|
|
25
|
-
if (t >= e.
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
const E =
|
|
30
|
-
E.
|
|
31
|
-
e.
|
|
32
|
-
|
|
24
|
+
const t = (e.qe?.gt ? e.qe.bt?.Be : e.qe?.Be) ?? -1;
|
|
25
|
+
if (t >= e.Be) e.Be = t + 1;
|
|
26
|
+
const n = e.Be;
|
|
27
|
+
const I = E.eE[n];
|
|
28
|
+
if (I === undefined) E.eE[n] = e; else {
|
|
29
|
+
const E = I.Tt;
|
|
30
|
+
E.Nt = e;
|
|
31
|
+
e.Tt = E;
|
|
32
|
+
I.Tt = e;
|
|
33
33
|
}
|
|
34
|
-
if (
|
|
34
|
+
if (n > E.EE) E.EE = n;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function insertIntoHeap(e, E) {
|
|
@@ -44,12 +44,17 @@ function insertIntoHeap(e, E) {
|
|
|
44
44
|
e.ie = t & -4 | REACTIVE_DIRTY | REACTIVE_IN_HEAP;
|
|
45
45
|
} else {
|
|
46
46
|
e.ie = t | REACTIVE_IN_HEAP;
|
|
47
|
-
// An unmarked node entering
|
|
48
|
-
// `_marked` is only reset by
|
|
49
|
-
// pulls (read-time markHeap +
|
|
50
|
-
// this node unmarked and every
|
|
51
|
-
// flush (#2922: the second
|
|
52
|
-
|
|
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);
|
|
53
58
|
}
|
|
54
59
|
if (!(t & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, E);
|
|
55
60
|
}
|
|
@@ -65,23 +70,23 @@ function deleteFromHeap(e, E) {
|
|
|
65
70
|
const t = e.ie;
|
|
66
71
|
if (!(t & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
|
|
67
72
|
e.ie = t & -25;
|
|
68
|
-
const
|
|
69
|
-
if (e.
|
|
70
|
-
const t = e.
|
|
71
|
-
const
|
|
72
|
-
const o = t ??
|
|
73
|
-
if (e ===
|
|
74
|
-
o.
|
|
73
|
+
const n = e.Be;
|
|
74
|
+
if (e.Tt === e) E.eE[n] = undefined; else {
|
|
75
|
+
const t = e.Nt;
|
|
76
|
+
const I = E.eE[n];
|
|
77
|
+
const o = t ?? I;
|
|
78
|
+
if (e === I) E.eE[n] = t; else e.Tt.Nt = t;
|
|
79
|
+
o.Tt = e.Tt;
|
|
75
80
|
}
|
|
76
|
-
e.
|
|
77
|
-
e.
|
|
81
|
+
e.Tt = e;
|
|
82
|
+
e.Nt = undefined;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
function markHeap(e) {
|
|
81
86
|
if (e.tE) return;
|
|
82
87
|
e.tE = true;
|
|
83
88
|
for (let E = 0; E <= e.EE; E++) {
|
|
84
|
-
for (let t = e.eE[E]; t !== undefined; t = t.
|
|
89
|
+
for (let t = e.eE[E]; t !== undefined; t = t.Nt) {
|
|
85
90
|
if (t.ie & REACTIVE_IN_HEAP) markNode(t);
|
|
86
91
|
}
|
|
87
92
|
}
|
|
@@ -91,16 +96,16 @@ function markNode(e, E = REACTIVE_DIRTY) {
|
|
|
91
96
|
const t = e.ie;
|
|
92
97
|
if ((t & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= E) return;
|
|
93
98
|
e.ie = t & -4 | E;
|
|
94
|
-
for (let E = e.u; E !== null; E = E.
|
|
95
|
-
markNode(E.
|
|
99
|
+
for (let E = e.u; E !== null; E = E.Te) {
|
|
100
|
+
markNode(E.Ie, REACTIVE_CHECK);
|
|
96
101
|
}
|
|
97
102
|
// Firewall children (projection machinery only): gate the cold-extension
|
|
98
103
|
// deref on the config bit — markNode runs per sub edge per write, and an
|
|
99
104
|
// unconditional _x chase here taxed every propagation (diamond -22%).
|
|
100
105
|
if (e.T & CONFIG_FW_CHILDREN) {
|
|
101
|
-
for (let E = e.o.i; E !== null; E = E.
|
|
102
|
-
for (let e = E.u; e !== null; e = e.
|
|
103
|
-
markNode(e.
|
|
106
|
+
for (let E = e.o.i; E !== null; E = E.Ee) {
|
|
107
|
+
for (let e = E.u; e !== null; e = e.Te) {
|
|
108
|
+
markNode(e.Ie, REACTIVE_CHECK);
|
|
104
109
|
}
|
|
105
110
|
}
|
|
106
111
|
}
|
|
@@ -108,11 +113,11 @@ function markNode(e, E = REACTIVE_DIRTY) {
|
|
|
108
113
|
|
|
109
114
|
function runHeap(e, E) {
|
|
110
115
|
e.tE = false;
|
|
111
|
-
for (e.
|
|
112
|
-
let t = e.eE[e.
|
|
116
|
+
for (e.Ke = 0; e.Ke <= e.EE; e.Ke++) {
|
|
117
|
+
let t = e.eE[e.Ke];
|
|
113
118
|
while (t !== undefined) {
|
|
114
119
|
if (t.ie & REACTIVE_IN_HEAP) E(t); else adjustHeight(t, e);
|
|
115
|
-
t = e.eE[e.
|
|
120
|
+
t = e.eE[e.Ke];
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
123
|
e.EE = 0;
|
|
@@ -120,21 +125,21 @@ function runHeap(e, E) {
|
|
|
120
125
|
|
|
121
126
|
function adjustHeight(e, E) {
|
|
122
127
|
deleteFromHeap(e, E);
|
|
123
|
-
let t = e.
|
|
124
|
-
for (let E = e.
|
|
125
|
-
const e = E.
|
|
126
|
-
const
|
|
127
|
-
if (
|
|
128
|
+
let t = e.Be;
|
|
129
|
+
for (let E = e.fe; E; E = E.ae) {
|
|
130
|
+
const e = E.Se;
|
|
131
|
+
const n = e.ce || e;
|
|
132
|
+
if (n.oe && n.Be >= t) t = n.Be + 1;
|
|
128
133
|
}
|
|
129
|
-
if (e.
|
|
130
|
-
e.
|
|
131
|
-
for (let E = e.u; E !== null; E = E.
|
|
134
|
+
if (e.Be !== t) {
|
|
135
|
+
e.Be = t;
|
|
136
|
+
for (let E = e.u; E !== null; E = E.Te) {
|
|
132
137
|
// Route each subscriber by its own zombie flag, mirroring the
|
|
133
138
|
// post-recompute height-adjust path. Inserting into the running `heap`
|
|
134
139
|
// unconditionally can park a zombie in `dirtyQueue` (or a live node in
|
|
135
140
|
// `zombieQueue`), breaking the flag/queue invariant `deleteFromHeap`
|
|
136
141
|
// relies on — the same corruption class as #2759.
|
|
137
|
-
insertIntoHeapHeight(E.
|
|
142
|
+
insertIntoHeapHeight(E.Ie, queueFor(E.Ie));
|
|
138
143
|
}
|
|
139
144
|
}
|
|
140
145
|
}
|
package/dist/prod/core/lanes.js
CHANGED
|
@@ -2,7 +2,7 @@ import { CONFIG_HAS_LANE, NOT_PENDING } from "./constants.js";
|
|
|
2
2
|
|
|
3
3
|
import { ext } from "./core.js";
|
|
4
4
|
|
|
5
|
-
import { currentTransition, activeTransition } from "./scheduler.js";
|
|
5
|
+
import { currentTransition, waitingTransition, activeTransition } from "./scheduler.js";
|
|
6
6
|
|
|
7
7
|
// Map from optimistic signal to its lane (reused for multiple writes to same signal)
|
|
8
8
|
const signalLanes = new WeakMap;
|
|
@@ -20,15 +20,15 @@ const activeLanes = new Set;
|
|
|
20
20
|
}
|
|
21
21
|
// Detect parent lane: _parentSource chains from pendingSignal → pendingValueComputed → original.
|
|
22
22
|
// The child lane should not merge with the parent lane.
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const r =
|
|
23
|
+
const i = n.o?.Gt;
|
|
24
|
+
const t = i?.o?.Oe;
|
|
25
|
+
const r = t ? findLane(t) : null;
|
|
26
26
|
e = {
|
|
27
27
|
nn: n,
|
|
28
|
-
|
|
28
|
+
he: new Set,
|
|
29
29
|
tn: [ [], [] ],
|
|
30
30
|
rn: null,
|
|
31
|
-
|
|
31
|
+
ge: activeTransition,
|
|
32
32
|
an: r
|
|
33
33
|
};
|
|
34
34
|
signalLanes.set(n, e);
|
|
@@ -39,19 +39,19 @@ const activeLanes = new Set;
|
|
|
39
39
|
// parent-child is a property of the nodes, not of write order — otherwise
|
|
40
40
|
// the owner's write merges the companion's subscribers into this lane and
|
|
41
41
|
// their effects wait on its async instead of flushing immediately.
|
|
42
|
-
adoptCompanionLane(n.o?.
|
|
43
|
-
adoptCompanionLane(n.o?.
|
|
42
|
+
adoptCompanionLane(n.o?.Le, e);
|
|
43
|
+
adoptCompanionLane(n.o?.Qe, e);
|
|
44
44
|
return e;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function adoptCompanionLane(n, e) {
|
|
48
48
|
if (!n) return;
|
|
49
|
-
const
|
|
50
|
-
if (!
|
|
51
|
-
const
|
|
49
|
+
const i = signalLanes.get(n);
|
|
50
|
+
if (!i) return;
|
|
51
|
+
const t = findLane(i);
|
|
52
52
|
// Only the companion's own unmerged root is safely re-parentable: a root
|
|
53
53
|
// that absorbed other lanes carries work that is not a child of this owner.
|
|
54
|
-
if (
|
|
54
|
+
if (t !== e && t.nn === n && !t.an) t.an = e;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
@@ -63,15 +63,22 @@ function adoptCompanionLane(n, e) {
|
|
|
63
63
|
|
|
64
64
|
/**
|
|
65
65
|
* Is the lane held? `_pendingAsync` records the async the lane OWNS (derived
|
|
66
|
-
* under it);
|
|
66
|
+
* under it); a transaction's reporter map records the async a render effect
|
|
67
67
|
* OBSERVED pending with no boundary taking it (INV-3, the one registration
|
|
68
68
|
* site). A hold needs both — the same rule the transaction itself uses, so a
|
|
69
69
|
* memo nobody renders, or one a fallback-showing boundary caught, cannot tear
|
|
70
70
|
* a frame and holds nothing (#3289). An orphan lane has no observation record
|
|
71
71
|
* and never holds.
|
|
72
|
+
*
|
|
73
|
+
* The observation is looked up per NODE, in whichever live transaction
|
|
74
|
+
* recorded it — not in this lane's transaction. Lanes merge across
|
|
75
|
+
* transactions (#2912: ownership never travels through lanes), so after a
|
|
76
|
+
* merge the root's transaction holds the observations of only one member;
|
|
77
|
+
* the async the other member's transaction observed must hold the merged
|
|
78
|
+
* reveal just the same (A15 for lanes, #3335).
|
|
72
79
|
*/ function laneHeld(n) {
|
|
73
|
-
|
|
74
|
-
|
|
80
|
+
if (!n.ge) return false;
|
|
81
|
+
for (const e of n.he) if (waitingTransition(e) !== null) return true;
|
|
75
82
|
return false;
|
|
76
83
|
}
|
|
77
84
|
|
|
@@ -85,8 +92,8 @@ function adoptCompanionLane(n, e) {
|
|
|
85
92
|
// Move (not copy) the merged lane's work: after the merge all routing goes
|
|
86
93
|
// through findLane() to the root, so anything left behind here is dead —
|
|
87
94
|
// and anything *added* here later is a routing bug (INV-5).
|
|
88
|
-
for (const
|
|
89
|
-
e.
|
|
95
|
+
for (const i of e.he) n.he.add(i);
|
|
96
|
+
e.he.clear();
|
|
90
97
|
n.tn[0].push(...e.tn[0]);
|
|
91
98
|
n.tn[1].push(...e.tn[1]);
|
|
92
99
|
e.tn[0].length = 0;
|
|
@@ -97,11 +104,11 @@ function adoptCompanionLane(n, e) {
|
|
|
97
104
|
/**
|
|
98
105
|
* Resolve a node's lane: follow union-find chain, verify active, clear if stale.
|
|
99
106
|
*/ function resolveLane(n) {
|
|
100
|
-
const e = n.o
|
|
107
|
+
const e = n.o?.Oe;
|
|
101
108
|
if (!e) return undefined;
|
|
102
|
-
const
|
|
103
|
-
if (activeLanes.has(
|
|
104
|
-
if (n.o !== null) n.o
|
|
109
|
+
const i = findLane(e);
|
|
110
|
+
if (activeLanes.has(i)) return i;
|
|
111
|
+
if (n.o !== null) n.o.Oe = undefined;
|
|
105
112
|
return undefined;
|
|
106
113
|
}
|
|
107
114
|
|
|
@@ -111,50 +118,50 @@ function resolveTransition(n) {
|
|
|
111
118
|
// transactions (#2912) — the merged root's _transition would hand this
|
|
112
119
|
// node's override to whichever action wrote last through the shared
|
|
113
120
|
// reader. Chase merge chains; a dead owner settled through another path.
|
|
114
|
-
if (hasActiveOverride(n) && n.o?.
|
|
115
|
-
const e = ext(n).
|
|
116
|
-
if (e.
|
|
117
|
-
if (n.o !== null) n.o.
|
|
121
|
+
if (hasActiveOverride(n) && n.o?.Ot) {
|
|
122
|
+
const e = ext(n).Ot = currentTransition(n.o?.Ot);
|
|
123
|
+
if (e.ft !== true) return e;
|
|
124
|
+
if (n.o !== null) n.o.Ot = null;
|
|
118
125
|
}
|
|
119
|
-
return resolveLane(n)?.
|
|
126
|
+
return resolveLane(n)?.ge ?? n.ge;
|
|
120
127
|
}
|
|
121
128
|
|
|
122
129
|
/**
|
|
123
130
|
* Check if a node has an active optimistic override.
|
|
124
131
|
*/ function hasActiveOverride(n) {
|
|
125
132
|
const e = n.o;
|
|
126
|
-
return e !== null && e.
|
|
133
|
+
return e !== null && e.be !== undefined && e.be !== NOT_PENDING;
|
|
127
134
|
}
|
|
128
135
|
|
|
129
136
|
/**
|
|
130
137
|
* Assign or merge a lane onto a node. At convergence points (node already has
|
|
131
138
|
* a different active lane), merge unless the node has an active override.
|
|
132
139
|
*/ function assignOrMergeLane(n, e) {
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
140
|
+
const i = findLane(e);
|
|
141
|
+
const t = n.o?.Oe;
|
|
142
|
+
if (t) {
|
|
136
143
|
// If the subscriber's lane was merged into another lane, it's stale —
|
|
137
144
|
// replace it with the new source lane instead of following the merge chain
|
|
138
145
|
// (which would incorrectly merge the new lane into the old group)
|
|
139
|
-
if (
|
|
140
|
-
ext(n)
|
|
146
|
+
if (t.rn) {
|
|
147
|
+
ext(n).Oe = e;
|
|
141
148
|
n.T |= CONFIG_HAS_LANE;
|
|
142
149
|
return;
|
|
143
150
|
}
|
|
144
|
-
const r = findLane(
|
|
151
|
+
const r = findLane(t);
|
|
145
152
|
if (activeLanes.has(r)) {
|
|
146
|
-
if (r !==
|
|
153
|
+
if (r !== i && !hasActiveOverride(n)) {
|
|
147
154
|
// Parent-child lanes stay independent so isPending resolves without
|
|
148
155
|
// waiting for the parent's async. The child keeps ownership.
|
|
149
|
-
if (
|
|
150
|
-
ext(n)
|
|
156
|
+
if (i.an && findLane(i.an) === r) {
|
|
157
|
+
ext(n).Oe = e;
|
|
151
158
|
n.T |= CONFIG_HAS_LANE;
|
|
152
|
-
} else if (r.an && findLane(r.an) ===
|
|
159
|
+
} else if (r.an && findLane(r.an) === i) ; else mergeLanes(i, r);
|
|
153
160
|
}
|
|
154
161
|
return;
|
|
155
162
|
}
|
|
156
163
|
}
|
|
157
|
-
ext(n)
|
|
164
|
+
ext(n).Oe = e;
|
|
158
165
|
n.T |= CONFIG_HAS_LANE;
|
|
159
166
|
}
|
|
160
167
|
|