@solidjs/signals 2.0.0-rc.14 → 2.0.0-rc.16
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 +882 -405
- package/dist/dev.attribution.js +172 -66
- package/dist/dev.js +1529 -745
- package/dist/observe/affects-marks.js +86 -0
- package/dist/observe/affects.js +32 -80
- package/dist/observe/boundaries.js +202 -166
- package/dist/observe/core/async.js +192 -141
- package/dist/observe/core/attribution-queries.js +1 -1
- package/dist/observe/core/attribution.js +315 -214
- package/dist/observe/core/constants.js +23 -4
- package/dist/observe/core/context.js +3 -3
- package/dist/observe/core/core.js +532 -360
- package/dist/observe/core/dev.js +63 -35
- package/dist/observe/core/effect.js +47 -47
- package/dist/observe/core/error.js +5 -3
- package/dist/observe/core/external.js +5 -6
- package/dist/observe/core/graph.js +56 -42
- package/dist/observe/core/heap.js +33 -33
- package/dist/observe/core/identities.js +62 -0
- package/dist/observe/core/lanes.js +242 -229
- package/dist/observe/core/owner.js +62 -50
- package/dist/observe/core/scheduler.js +322 -168
- package/dist/observe/core/truth.js +45 -0
- package/dist/observe/core/verdict.js +114 -64
- package/dist/observe/deferred.js +184 -0
- package/dist/observe/index.js +7 -1
- package/dist/observe/map.js +339 -254
- package/dist/observe/reveal.js +77 -77
- package/dist/observe/signals.js +54 -33
- package/dist/observe/store/affects.js +76 -69
- package/dist/observe/store/edges.js +39 -0
- package/dist/observe/store/hooks.js +13 -0
- package/dist/observe/store/index.js +0 -2
- package/dist/observe/store/optimistic.js +82 -44
- package/dist/observe/store/projection.js +83 -64
- package/dist/observe/store/reconcile.js +32 -30
- package/dist/observe/store/store.js +219 -123
- package/dist/prod/affects-marks.js +86 -0
- package/dist/prod/affects.js +33 -79
- package/dist/prod/boundaries.js +185 -149
- package/dist/prod/core/async.js +176 -135
- package/dist/prod/core/constants.js +23 -4
- package/dist/prod/core/context.js +3 -3
- package/dist/prod/core/core.js +521 -353
- package/dist/prod/core/effect.js +66 -66
- package/dist/prod/core/error.js +5 -3
- package/dist/prod/core/external.js +5 -6
- package/dist/prod/core/graph.js +56 -42
- package/dist/prod/core/heap.js +38 -38
- package/dist/prod/core/identities.js +62 -0
- package/dist/prod/core/lanes.js +237 -224
- package/dist/prod/core/owner.js +62 -51
- package/dist/prod/core/scheduler.js +312 -158
- package/dist/prod/core/truth.js +45 -0
- package/dist/prod/core/verdict.js +113 -63
- package/dist/prod/deferred.js +182 -0
- package/dist/prod/index.js +7 -1
- package/dist/prod/map.js +366 -281
- package/dist/prod/reveal.js +77 -77
- package/dist/prod/signals.js +59 -38
- package/dist/prod/store/affects.js +76 -69
- package/dist/prod/store/edges.js +39 -0
- package/dist/prod/store/hooks.js +13 -0
- package/dist/prod/store/index.js +0 -2
- package/dist/prod/store/optimistic.js +121 -84
- package/dist/prod/store/projection.js +46 -34
- package/dist/prod/store/reconcile.js +32 -30
- package/dist/prod/store/store.js +205 -116
- package/dist/types/affects-marks.d.ts +14 -0
- package/dist/types/boundaries.d.ts +5 -1
- package/dist/types/core/async.d.ts +10 -0
- package/dist/types/core/attribution.d.ts +6 -2
- package/dist/types/core/constants.d.ts +18 -1
- package/dist/types/core/core.d.ts +77 -5
- package/dist/types/core/dev.d.ts +43 -13
- package/dist/types/core/graph.d.ts +11 -0
- package/dist/types/core/identities.d.ts +17 -0
- package/dist/types/core/index.d.ts +2 -1
- package/dist/types/core/lanes.d.ts +2 -4
- package/dist/types/core/owner.d.ts +5 -3
- package/dist/types/core/scheduler.d.ts +59 -34
- package/dist/types/core/truth.d.ts +16 -0
- package/dist/types/core/types.d.ts +21 -6
- package/dist/types/core/verdict.d.ts +32 -0
- package/dist/types/deferred.d.ts +28 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/map.d.ts +2 -2
- package/dist/types/signals.d.ts +28 -7
- package/dist/types/store/affects.d.ts +11 -0
- package/dist/types/store/edges.d.ts +9 -0
- package/dist/types/store/hooks.d.ts +48 -0
- package/dist/types/store/index.d.ts +10 -4
- package/dist/types/store/optimistic.d.ts +3 -2
- package/dist/types/store/projection.d.ts +4 -3
- package/dist/types/store/store.d.ts +4 -39
- package/dist/types/store/target.d.ts +16 -8
- package/dist/types/store/types.d.ts +14 -0
- package/package.json +1 -1
package/dist/prod/core/effect.js
CHANGED
|
@@ -8,28 +8,28 @@ import { trimStaleDeps } from "./graph.js";
|
|
|
8
8
|
|
|
9
9
|
import { enqueueSub } from "./heap.js";
|
|
10
10
|
|
|
11
|
-
import { globalQueue, schedule,
|
|
11
|
+
import { globalQueue, schedule, heldRunHook, haltReactivity, GlobalQueue } from "./scheduler.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
|
15
15
|
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
|
16
16
|
* sources and recompute
|
|
17
|
-
*/ function effect(e,
|
|
18
|
-
const f = !!
|
|
19
|
-
const r = createEffectNode(
|
|
17
|
+
*/ function effect(t, e, E, u) {
|
|
18
|
+
const f = !!u?.user;
|
|
19
|
+
const r = createEffectNode(t, e, E, f ? EFFECT_USER : EFFECT_RENDER, u);
|
|
20
20
|
recompute(r, true);
|
|
21
21
|
// A first pass that read a staged value was staged itself (recompute: born
|
|
22
22
|
// staged); the flush's commit replays this effect. Its first run is not this
|
|
23
23
|
// creation's (A29). A lane's node likewise: its run is the lane's, queued
|
|
24
24
|
// by the pass and released at the reveal (lanes.ts).
|
|
25
|
-
!
|
|
25
|
+
!u?.defer && r.se === NOT_PENDING && !r.T?.Re?.v && (r.i === EFFECT_USER || u?.schedule ? globalQueue.enqueue(r.i, runEffect.bind(null, r)) : runEffect(r, r.i));
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function notifyEffectStatus(
|
|
28
|
+
function notifyEffectStatus(t, e) {
|
|
29
29
|
// Use passed values if provided, otherwise read from node
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
30
|
+
const E = t !== undefined ? t : this.m;
|
|
31
|
+
const u = e !== undefined ? e : this.T?.F;
|
|
32
|
+
if (E & STATUS_ERROR) {
|
|
33
33
|
globalQueue.notify(this, STATUS_PENDING, 0);
|
|
34
34
|
if (this.i === EFFECT_USER) {
|
|
35
35
|
// The error handler is the error arm of the effect phase (#2840 ruling):
|
|
@@ -39,23 +39,23 @@ function notifyEffectStatus(e, t) {
|
|
|
39
39
|
// phase takes the success arm instead. Blocked forwards (explicit
|
|
40
40
|
// `status` arg without node-state writes) don't queue: the status
|
|
41
41
|
// re-propagates unblocked at commit.
|
|
42
|
-
if (this.
|
|
43
|
-
this.
|
|
44
|
-
globalQueue.enqueue(this.i, this.
|
|
42
|
+
if (this.m & STATUS_ERROR) {
|
|
43
|
+
this.Ae = true;
|
|
44
|
+
globalQueue.enqueue(this.i, this.W ??= runEffect.bind(null, this));
|
|
45
45
|
}
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
if (!globalQueue.notify(this, STATUS_ERROR, STATUS_ERROR)) {
|
|
49
|
-
haltReactivity(unwrapStatusError(
|
|
50
|
-
throw
|
|
49
|
+
haltReactivity(unwrapStatusError(u));
|
|
50
|
+
throw u;
|
|
51
51
|
}
|
|
52
52
|
} else if (this.i === EFFECT_RENDER) {
|
|
53
|
-
globalQueue.notify(this, STATUS_PENDING | STATUS_ERROR,
|
|
53
|
+
globalQueue.notify(this, STATUS_PENDING | STATUS_ERROR, E, u);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function runEffect(
|
|
58
|
-
if (!
|
|
57
|
+
function runEffect(t, e) {
|
|
58
|
+
if (!t.Ae || t.R & REACTIVE_DISPOSED) return;
|
|
59
59
|
// A queued run behind a fallback (boundaries.ts) waits for the reveal: a
|
|
60
60
|
// user effect's, which would read a DOM that is not attached, and a render
|
|
61
61
|
// effect's update too (maintainer, 2026-10-02: "we held the queue but let
|
|
@@ -64,7 +64,7 @@ function runEffect(e, t) {
|
|
|
64
64
|
// hidden subtree. The synchronous first render on creation is not a queued
|
|
65
65
|
// run and goes through. `_modified` stays set; the boundary re-queues the
|
|
66
66
|
// run (`release`).
|
|
67
|
-
if (
|
|
67
|
+
if (heldRunHook?.(t)) return;
|
|
68
68
|
// Error arm (#2840), user effects only: a compute-phase error that is still
|
|
69
69
|
// the node's settled state at effect time runs the bundle's error handler in
|
|
70
70
|
// this same imperative, writable scope. Unwrap the StatusError used for
|
|
@@ -75,94 +75,94 @@ function runEffect(e, t) {
|
|
|
75
75
|
// Render effects bypass: their errors route to boundaries synchronously in
|
|
76
76
|
// notifyEffectStatus, and a runner queued by an earlier valueChanged in the
|
|
77
77
|
// same flush must not be hijacked by a later-arriving error status.
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
if (t.m & STATUS_ERROR && t.i === EFFECT_USER) {
|
|
79
|
+
const e = unwrapStatusError(t.T?.F);
|
|
80
|
+
t.ge = t.Ie;
|
|
81
|
+
t.Ae = false;
|
|
82
82
|
try {
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}) : console.error(
|
|
88
|
-
} catch (
|
|
89
|
-
if (!globalQueue.notify(
|
|
90
|
-
haltReactivity(
|
|
91
|
-
throw
|
|
83
|
+
t.qe ? t.qe(e, () => {
|
|
84
|
+
const e = t.Je;
|
|
85
|
+
t.Je = undefined;
|
|
86
|
+
e?.();
|
|
87
|
+
}) : console.error(e);
|
|
88
|
+
} catch (e) {
|
|
89
|
+
if (!globalQueue.notify(t, STATUS_ERROR, STATUS_ERROR)) {
|
|
90
|
+
haltReactivity(e);
|
|
91
|
+
throw e;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
96
|
// Captured before the callback: its own throw errors the node below, but
|
|
97
97
|
// the compute pass that produced `_value` was clean, so its tail still goes.
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
|
|
98
|
+
const E = t.T?.F == null;
|
|
99
|
+
const u = t.Je;
|
|
100
|
+
t.Je = undefined;
|
|
101
101
|
try {
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
if (false &&
|
|
102
|
+
u?.();
|
|
103
|
+
const e = t.Ke(t.Ie, t.ge);
|
|
104
|
+
if (false && e !== undefined && typeof e !== "function") ;
|
|
105
105
|
// The final cleanup is invoked by disposeChildren at true disposal.
|
|
106
|
-
|
|
107
|
-
} catch (
|
|
108
|
-
ext(
|
|
109
|
-
|
|
110
|
-
if (!globalQueue.notify(
|
|
111
|
-
haltReactivity(
|
|
112
|
-
throw
|
|
106
|
+
t.Je = e;
|
|
107
|
+
} catch (e) {
|
|
108
|
+
ext(t).F = new StatusError(t, e);
|
|
109
|
+
t.m |= STATUS_ERROR;
|
|
110
|
+
if (!globalQueue.notify(t, STATUS_ERROR, STATUS_ERROR)) {
|
|
111
|
+
haltReactivity(e);
|
|
112
|
+
throw e;
|
|
113
113
|
}
|
|
114
114
|
} finally {
|
|
115
|
-
|
|
116
|
-
|
|
115
|
+
t.ge = t.Ie;
|
|
116
|
+
t.Ae = false;
|
|
117
117
|
// The run applied: this is the frame now, so the dependency tail the
|
|
118
118
|
// compute pass left linked goes (A30, #3438 — `recompute` defers an
|
|
119
119
|
// effect's trim while a run is owed; the twin of `commitPendingNode`'s
|
|
120
120
|
// trim for a staged pass). An errored compute kept its full list with
|
|
121
121
|
// `_depsTail` marking where it stopped; leave it, as the commit does.
|
|
122
|
-
if (
|
|
122
|
+
if (E) trimStaleDeps(t);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
GlobalQueue.
|
|
126
|
+
GlobalQueue.K = runEffect;
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
129
|
* Internal tracked effect - bypasses heap, goes directly to effect queue.
|
|
130
130
|
* Runs as a leaf owner: child primitives and onCleanup are forbidden (false throws).
|
|
131
131
|
* Uses stale reads.
|
|
132
|
-
*/ function trackedEffect(
|
|
132
|
+
*/ function trackedEffect(t, e) {
|
|
133
133
|
const run = () => {
|
|
134
134
|
// `_modified` is NOT redundant with the heap: the heap dedups within a
|
|
135
135
|
// pass, but several passes in one flush each enqueue `_run` into the same
|
|
136
136
|
// user queue, and this gate is what collapses them into one run.
|
|
137
|
-
if (!
|
|
138
|
-
if (
|
|
137
|
+
if (!E.Ae || E.R & REACTIVE_DISPOSED) return;
|
|
138
|
+
if (heldRunHook?.(E)) return;
|
|
139
139
|
try {
|
|
140
|
-
|
|
141
|
-
recompute(
|
|
140
|
+
E.Ae = false;
|
|
141
|
+
recompute(E);
|
|
142
142
|
} finally {}
|
|
143
143
|
};
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const
|
|
149
|
-
|
|
144
|
+
const E = computed(() => {
|
|
145
|
+
const e = E.Je;
|
|
146
|
+
E.Je = undefined;
|
|
147
|
+
e?.();
|
|
148
|
+
const u = staleValues(t);
|
|
149
|
+
E.Je = u;
|
|
150
150
|
}, {
|
|
151
|
-
...
|
|
151
|
+
...e,
|
|
152
152
|
lazy: true
|
|
153
153
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
E.Je = undefined;
|
|
155
|
+
E.l = E.l & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
|
|
156
|
+
E.Ae = true;
|
|
157
|
+
E.i = EFFECT_TRACKED;
|
|
158
158
|
// Status dispatch rides the SHARED notifier (statusNotifierOf keys off
|
|
159
159
|
// _type): its error arm is behavior-identical to the closure that used to
|
|
160
160
|
// live here, without the per-node NodeExtension allocation.
|
|
161
|
-
|
|
161
|
+
E.M = run;
|
|
162
162
|
// The first run rides the heap like every wake (GlobalQueue._update), so a
|
|
163
163
|
// tracked effect created inside a render-effect callback runs after that
|
|
164
164
|
// pass's staged writes commit, not before.
|
|
165
|
-
enqueueSub(
|
|
165
|
+
enqueueSub(E);
|
|
166
166
|
schedule();
|
|
167
167
|
}
|
|
168
168
|
|
package/dist/prod/core/error.js
CHANGED
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
* ```
|
|
24
24
|
*/
|
|
25
25
|
class NotReadyError extends Error {
|
|
26
|
-
source;
|
|
27
26
|
constructor(r) {
|
|
28
27
|
// Control-flow throw: it happens on every read of a pending source, so in
|
|
29
28
|
// production skip V8's eager stack capture (proportional to stack depth —
|
|
@@ -40,9 +39,12 @@ class NotReadyError extends Error {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
class StatusError extends Error {
|
|
43
|
-
source;
|
|
44
42
|
constructor(r, o) {
|
|
45
|
-
|
|
43
|
+
// Best-effort message: formatting must never replace the original (#4112).
|
|
44
|
+
try {
|
|
45
|
+
var t = String(o instanceof Error ? o.message : o);
|
|
46
|
+
} catch {}
|
|
47
|
+
super(t, {
|
|
46
48
|
cause: o
|
|
47
49
|
});
|
|
48
50
|
this.source = r;
|
|
@@ -2,7 +2,7 @@ import { signal, setSignal, read } from "./core.js";
|
|
|
2
2
|
|
|
3
3
|
import { cleanup } from "./owner.js";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { setExternalHooks } from "./scheduler.js";
|
|
6
6
|
|
|
7
7
|
let externalSourceConfig = null;
|
|
8
8
|
|
|
@@ -37,7 +37,7 @@ let externalSourceConfig = null;
|
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
39
|
// Wires a freshly created computed through the active external-source bridge.
|
|
40
|
-
// Lives here (installed
|
|
40
|
+
// Lives here (installed as a scheduler hook while a config is active) rather than
|
|
41
41
|
// inline in core: esbuild cannot literal-track the mutable config binding the
|
|
42
42
|
// way rollup does, so an inline `if (externalSourceConfig)` block ships in
|
|
43
43
|
// every bundle even though only enableExternalSource() can make it reachable.
|
|
@@ -46,11 +46,11 @@ function wireExternalSource(e) {
|
|
|
46
46
|
equals: false,
|
|
47
47
|
ownedWrite: true
|
|
48
48
|
});
|
|
49
|
-
const r = externalSourceConfig.factory(e.
|
|
49
|
+
const r = externalSourceConfig.factory(e.X, () => {
|
|
50
50
|
setSignal(n, undefined);
|
|
51
51
|
});
|
|
52
52
|
cleanup(() => r.dispose());
|
|
53
|
-
e.
|
|
53
|
+
e.X = e => {
|
|
54
54
|
read(n);
|
|
55
55
|
return r.track(e);
|
|
56
56
|
};
|
|
@@ -64,8 +64,7 @@ function externalUntrack(e) {
|
|
|
64
64
|
// removed on reset) so core's presence checks stay equivalent to the old
|
|
65
65
|
// `externalSourceConfig` truthiness checks.
|
|
66
66
|
function syncExternalHooks() {
|
|
67
|
-
|
|
68
|
-
GlobalQueue.It = externalSourceConfig ? externalUntrack : undefined;
|
|
67
|
+
if (externalSourceConfig) setExternalHooks(wireExternalSource, externalUntrack); else setExternalHooks(undefined, undefined);
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
function enableExternalSource(e) {
|
package/dist/prod/core/graph.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE
|
|
1
|
+
import { REACTIVE_RECOMPUTING_DEPS, CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE } from "./constants.js";
|
|
2
2
|
|
|
3
3
|
import { deleteFromHeap } from "./heap.js";
|
|
4
4
|
|
|
@@ -17,38 +17,40 @@ function setSlotUnobserved(e) {
|
|
|
17
17
|
|
|
18
18
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
|
|
19
19
|
function unlinkSubs(e) {
|
|
20
|
-
const n = e.
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
if (
|
|
26
|
-
n.
|
|
27
|
-
if (
|
|
20
|
+
const n = e.S;
|
|
21
|
+
const l = e.G;
|
|
22
|
+
const o = e.t;
|
|
23
|
+
const s = e.Xe;
|
|
24
|
+
if (o !== null) o.Xe = s; else n.ve = s;
|
|
25
|
+
if (s !== null) s.t = o; else {
|
|
26
|
+
n.o = o;
|
|
27
|
+
if (o === null) {
|
|
28
28
|
// Store slot nodes dispatch to the ONE shared hook — no per-node
|
|
29
29
|
// unobserved closure, no NodeExtension to hold it.
|
|
30
|
-
if (n.
|
|
30
|
+
if (n.l & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.T?.we?.();
|
|
31
31
|
// No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
|
|
32
32
|
// A pending node is exempt: its in-flight async work is an observer —
|
|
33
33
|
// tearing down would orphan the work and re-execute it on the next
|
|
34
34
|
// read. The settle path runs this same last-one-out check when that
|
|
35
35
|
// observer releases (the untracked-read dormancy sweep guards on
|
|
36
36
|
// pending identically).
|
|
37
|
+
// During a pass's teardown of its unfinished frame, the release waits
|
|
38
|
+
// for the pass to end (`deferredReleases`, #4142).
|
|
37
39
|
const e = n;
|
|
38
|
-
e.
|
|
40
|
+
e.X && e.l & CONFIG_AUTO_DISPOSE && !(e.R & REACTIVE_ZOMBIE) && !(e.m & STATUS_PENDING) && (deferredReleases ? deferredReleases.push(e) : unobserved(e));
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
|
-
return
|
|
43
|
+
return l;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
function trimStaleDeps(e) {
|
|
45
|
-
const n = e.
|
|
46
|
-
let
|
|
47
|
-
if (
|
|
47
|
+
const n = e._;
|
|
48
|
+
let l = n !== null ? n.G : e.C;
|
|
49
|
+
if (l !== null) {
|
|
48
50
|
do {
|
|
49
|
-
|
|
50
|
-
} while (
|
|
51
|
-
if (n !== null) n.
|
|
51
|
+
l = unlinkSubs(l);
|
|
52
|
+
} while (l !== null);
|
|
53
|
+
if (n !== null) n.G = null; else e.C = null;
|
|
52
54
|
}
|
|
53
55
|
}
|
|
54
56
|
|
|
@@ -57,15 +59,27 @@ function trimStaleDeps(e) {
|
|
|
57
59
|
// and skipping early also avoids adding one (hidden-class churn) via the
|
|
58
60
|
// null-out below.
|
|
59
61
|
function clearDeps(e) {
|
|
60
|
-
let n = e.
|
|
62
|
+
let n = e.C;
|
|
61
63
|
if (!n) return;
|
|
62
64
|
do {
|
|
63
65
|
n = unlinkSubs(n);
|
|
64
66
|
} while (n !== null);
|
|
67
|
+
e.C = null;
|
|
65
68
|
e._ = null;
|
|
66
|
-
e.S = null;
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Last-one-out releases held back while a pass tears down the frame of an
|
|
73
|
+
* earlier pass that never committed (#4142). The pass is about to rebuild
|
|
74
|
+
* the same children, which read the same lazy nodes again. Released on the
|
|
75
|
+
* spot, a lazy async memo whose only reader was the old frame's child memo
|
|
76
|
+
* was torn down, re-ran on the new child's read, went pending, and the cycle
|
|
77
|
+
* repeated forever. `recompute` collects them around that teardown and
|
|
78
|
+
* releases what is still unobserved when the pass ends.
|
|
79
|
+
*/ let deferredReleases = null;
|
|
80
|
+
|
|
81
|
+
const deferReleases = e => deferredReleases = e;
|
|
82
|
+
|
|
69
83
|
function unobserved(e) {
|
|
70
84
|
deleteFromHeap(e, dirtyQueue);
|
|
71
85
|
clearDeps(e);
|
|
@@ -101,7 +115,7 @@ function sweepDormant() {
|
|
|
101
115
|
// is an observer; the settle path re-runs last-one-out), lost its
|
|
102
116
|
// AUTO_DISPOSE bit (owner teardown strips it, #3024), or already been
|
|
103
117
|
// torn down.
|
|
104
|
-
if (!e.
|
|
118
|
+
if (!e.o && e.l & CONFIG_AUTO_DISPOSE && !(e.m & STATUS_PENDING) && !(e.R & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
|
|
105
119
|
unobserved(e);
|
|
106
120
|
}
|
|
107
121
|
}
|
|
@@ -110,15 +124,15 @@ function sweepDormant() {
|
|
|
110
124
|
|
|
111
125
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L52
|
|
112
126
|
function link(e, n) {
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
115
|
-
let
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
n.
|
|
127
|
+
const l = n._;
|
|
128
|
+
if (l !== null && l.S === e) return;
|
|
129
|
+
let o = null;
|
|
130
|
+
const s = n.R & REACTIVE_RECOMPUTING_DEPS;
|
|
131
|
+
if (s) {
|
|
132
|
+
o = l !== null ? l.G : n.C;
|
|
133
|
+
if (o !== null && o.S === e) {
|
|
134
|
+
o.Te = n.Ne;
|
|
135
|
+
n._ = o;
|
|
122
136
|
return;
|
|
123
137
|
}
|
|
124
138
|
}
|
|
@@ -127,20 +141,20 @@ function link(e, n) {
|
|
|
127
141
|
// [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
|
|
128
142
|
// (the old alien-signals `isValidLink` walk, O(n²) when a computation
|
|
129
143
|
// re-reads earlier deps non-consecutively, e.g. store leaf reads).
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
144
|
+
const t = e.ve;
|
|
145
|
+
if (t !== null && t.u === n && (!s || t.Te === n.Ne)) return;
|
|
146
|
+
const r = n._ = e.ve = {
|
|
147
|
+
S: e,
|
|
148
|
+
u: n,
|
|
149
|
+
G: o,
|
|
150
|
+
Xe: t,
|
|
151
|
+
t: null,
|
|
152
|
+
Te: n.Ne
|
|
139
153
|
};
|
|
140
|
-
if (
|
|
141
|
-
if (
|
|
154
|
+
if (l !== null) l.G = r; else n.C = r;
|
|
155
|
+
if (t !== null) t.t = r; else e.o = r;
|
|
142
156
|
// New subscriber edge: staged-rewrite skips (§12d) must not miss it.
|
|
143
157
|
bumpNotifyEpoch();
|
|
144
158
|
}
|
|
145
159
|
|
|
146
|
-
export { clearDeps, dormantNodes, link, setSlotUnobserved, slotUnobservedHook, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };
|
|
160
|
+
export { clearDeps, deferReleases, deferredReleases, dormantNodes, link, setSlotUnobserved, slotUnobservedHook, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };
|
package/dist/prod/core/heap.js
CHANGED
|
@@ -11,22 +11,22 @@ import { dirtyQueue } from "./scheduler.js";
|
|
|
11
11
|
* callback to the user queue once the pass has committed (see
|
|
12
12
|
* GlobalQueue._update, #3291).
|
|
13
13
|
*/ function enqueueSub(e) {
|
|
14
|
-
if (dirtyQueue.
|
|
14
|
+
if (dirtyQueue.Ge > e.Fe) dirtyQueue.Ge = e.Fe;
|
|
15
15
|
insertIntoHeap(e, dirtyQueue);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
function actualInsertIntoHeap(e, t) {
|
|
19
|
-
const E = (e._parent?.
|
|
20
|
-
if (E >= e.
|
|
21
|
-
const n = e.
|
|
22
|
-
const I = t
|
|
23
|
-
if (I === undefined) t
|
|
24
|
-
const t = I.
|
|
25
|
-
t.
|
|
26
|
-
e.
|
|
27
|
-
I.
|
|
19
|
+
const E = (e._parent?.je ? e._parent.Ye?.Fe : e._parent?.Fe) ?? -1;
|
|
20
|
+
if (E >= e.Fe) e.Fe = E + 1;
|
|
21
|
+
const n = e.Fe;
|
|
22
|
+
const I = t.$e[n];
|
|
23
|
+
if (I === undefined) t.$e[n] = e; else {
|
|
24
|
+
const t = I.We;
|
|
25
|
+
t.be = e;
|
|
26
|
+
e.We = t;
|
|
27
|
+
I.We = e;
|
|
28
28
|
}
|
|
29
|
-
if (n > t.
|
|
29
|
+
if (n > t.et) t.et = n;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function insertIntoHeap(e, t) {
|
|
@@ -49,7 +49,7 @@ function insertIntoHeap(e, t) {
|
|
|
49
49
|
// parked in the heap for a synchronous mount (each row writing a ref
|
|
50
50
|
// signal its effect subscribes to), mounting N rows was O(N²) (#3350).
|
|
51
51
|
// markNode's own guard skips an already-DIRTY node.
|
|
52
|
-
if (t.
|
|
52
|
+
if (t.p) markNode(e);
|
|
53
53
|
}
|
|
54
54
|
if (!(E & REACTIVE_IN_HEAP_HEIGHT)) actualInsertIntoHeap(e, t);
|
|
55
55
|
}
|
|
@@ -65,23 +65,23 @@ function deleteFromHeap(e, t) {
|
|
|
65
65
|
const E = e.R;
|
|
66
66
|
if (!(E & (REACTIVE_IN_HEAP | REACTIVE_IN_HEAP_HEIGHT))) return;
|
|
67
67
|
e.R = E & -25;
|
|
68
|
-
const n = e.
|
|
69
|
-
if (e.
|
|
70
|
-
const E = e.
|
|
71
|
-
const I = t
|
|
68
|
+
const n = e.Fe;
|
|
69
|
+
if (e.We === e) t.$e[n] = undefined; else {
|
|
70
|
+
const E = e.be;
|
|
71
|
+
const I = t.$e[n];
|
|
72
72
|
const i = E ?? I;
|
|
73
|
-
if (e === I) t
|
|
74
|
-
i.
|
|
73
|
+
if (e === I) t.$e[n] = E; else e.We.be = E;
|
|
74
|
+
i.We = e.We;
|
|
75
75
|
}
|
|
76
|
-
e.
|
|
77
|
-
e.
|
|
76
|
+
e.We = e;
|
|
77
|
+
e.be = undefined;
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function markHeap(e) {
|
|
81
|
-
if (e.
|
|
82
|
-
e.
|
|
83
|
-
for (let t = 0; t <= e.
|
|
84
|
-
for (let E = e
|
|
81
|
+
if (e.p) return;
|
|
82
|
+
e.p = true;
|
|
83
|
+
for (let t = 0; t <= e.et; t++) {
|
|
84
|
+
for (let E = e.$e[t]; E !== undefined; E = E.be) {
|
|
85
85
|
if (E.R & REACTIVE_IN_HEAP) markNode(E);
|
|
86
86
|
}
|
|
87
87
|
}
|
|
@@ -91,33 +91,33 @@ function markNode(e, t = REACTIVE_DIRTY) {
|
|
|
91
91
|
const E = e.R;
|
|
92
92
|
if ((E & (REACTIVE_CHECK | REACTIVE_DIRTY)) >= t) return;
|
|
93
93
|
e.R = E & -4 | t;
|
|
94
|
-
for (let t = e.
|
|
95
|
-
markNode(t.
|
|
94
|
+
for (let t = e.o; t !== null; t = t.t) {
|
|
95
|
+
markNode(t.u, REACTIVE_CHECK);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
function runHeap(e, t) {
|
|
100
|
-
e.
|
|
101
|
-
for (e.
|
|
102
|
-
let E = e
|
|
100
|
+
e.p = false;
|
|
101
|
+
for (e.Ge = 0; e.Ge <= e.et; e.Ge++) {
|
|
102
|
+
let E = e.$e[e.Ge];
|
|
103
103
|
while (E !== undefined) {
|
|
104
104
|
if (E.R & REACTIVE_IN_HEAP) t(E); else adjustHeight(E, e);
|
|
105
|
-
E = e
|
|
105
|
+
E = e.$e[e.Ge];
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
e.
|
|
108
|
+
e.et = 0;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
function adjustHeight(e, t) {
|
|
112
112
|
deleteFromHeap(e, t);
|
|
113
|
-
let E = e.
|
|
114
|
-
for (let t = e.
|
|
115
|
-
const e = t.
|
|
116
|
-
if (e.
|
|
113
|
+
let E = e.Fe;
|
|
114
|
+
for (let t = e.C; t; t = t.G) {
|
|
115
|
+
const e = t.S;
|
|
116
|
+
if (e.X && e.Fe >= E) E = e.Fe + 1;
|
|
117
117
|
}
|
|
118
|
-
if (e.
|
|
119
|
-
e.
|
|
120
|
-
for (let E = e.
|
|
118
|
+
if (e.Fe !== E) {
|
|
119
|
+
e.Fe = E;
|
|
120
|
+
for (let E = e.o; E !== null; E = E.t) insertIntoHeapHeight(E.u, t);
|
|
121
121
|
}
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { CONFIG_TRANSPARENT } from "./constants.js";
|
|
2
|
+
|
|
3
|
+
import "./core.js";
|
|
4
|
+
|
|
5
|
+
import { getOwner } from "./owner.js";
|
|
6
|
+
|
|
7
|
+
// Deferred hydration, dependency edges: plain-signal identities.
|
|
8
|
+
// While on (`setSignalIdentities`; the server-components client turns it on
|
|
9
|
+
// before hydrating), a plain signal created under an id-bearing owner is
|
|
10
|
+
// named `<owner id>~<n>`, n counting the plain signals (and plain store
|
|
11
|
+
// roots: `createStore` over an object, store/edges.ts) created under that
|
|
12
|
+
// owner in its current pass (transparent owners defer to the nearest
|
|
13
|
+
// id-bearing one, as child ids do). The server names the same signal the
|
|
14
|
+
// same way and restarts the count on every re-run, so an edge it shipped (a
|
|
15
|
+
// slot fill read it) matches the client node; the write hook receives the
|
|
16
|
+
// node and looks its name up (`signalName`). The count restarts when the owner's pass
|
|
17
|
+
// generation (`_depGen`, bumped by every recompute) moves on. Only the
|
|
18
|
+
// frames client imports this module, so nothing here ships without it.
|
|
19
|
+
// Names live in a side table, not on the node: frames reads them across the
|
|
20
|
+
// package boundary, where a mangled field would not survive.
|
|
21
|
+
let counts = null;
|
|
22
|
+
|
|
23
|
+
const names = new WeakMap;
|
|
24
|
+
|
|
25
|
+
/** @internal The identity of a plain signal named while identities were on. */ function signalName(n) {
|
|
26
|
+
return n === undefined ? undefined : names.get(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function identify(n) {
|
|
30
|
+
let e = getOwner();
|
|
31
|
+
if (!e) return;
|
|
32
|
+
while (e.l & CONFIG_TRANSPARENT && e._parent) e = e._parent;
|
|
33
|
+
if (e.id == null) return;
|
|
34
|
+
const t = e.Ne;
|
|
35
|
+
let i = counts.get(e);
|
|
36
|
+
if (i === undefined || i[0] !== t) counts.set(e, i = [ t, 0 ]);
|
|
37
|
+
const s = e.id + "~" + i[1]++;
|
|
38
|
+
// A store root named twice (one object made into two stores, or a store
|
|
39
|
+
// handed to `createStore`) is one target under two server names: its
|
|
40
|
+
// writes cannot be attributed (an empty name).
|
|
41
|
+
names.set(n, names.has(n) ? "" : s);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** @internal Name plain signals from now on (`on`), or stop. */ function setSignalIdentities(n) {
|
|
45
|
+
counts = n ? counts || new WeakMap : null;
|
|
46
|
+
signalHook = n ? identify : null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @internal Called with every plain signal `createSignal` makes, and every
|
|
51
|
+
* plain store root `createStore` makes, while set (the namer above). Never
|
|
52
|
+
* set unless `setSignalIdentities` is imported, so a bundle without it keeps
|
|
53
|
+
* only a null check.
|
|
54
|
+
*/ let signalHook = null;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @internal Dev only: `watch` is called with every node read while set (the
|
|
58
|
+
* dev hook `onRead`) — the frames client's identity-drift check watches the
|
|
59
|
+
* named signals a deferred occurrence reads as it mounts. A no-op in prod.
|
|
60
|
+
*/ function setReadWatch(n) {}
|
|
61
|
+
|
|
62
|
+
export { setReadWatch, setSignalIdentities, signalHook, signalName };
|