@solidjs/signals 2.0.0-rc.8 → 2.0.0-rc.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev-shared.js +1399 -285
- package/dist/dev.attribution.js +459 -307
- package/dist/dev.js +1864 -435
- package/dist/observe/affects.js +3 -1
- package/dist/observe/attribution.js +7 -1
- package/dist/observe/boundaries.js +209 -154
- package/dist/observe/core/action.js +18 -8
- package/dist/observe/core/async.js +220 -110
- package/dist/observe/core/attribution-costs.js +66 -0
- package/dist/observe/core/attribution-feedback.js +282 -0
- package/dist/observe/core/attribution-hooks.js +23 -1
- package/dist/observe/core/attribution-queries.js +28 -0
- package/dist/observe/core/attribution.js +262 -485
- package/dist/observe/core/constants.js +34 -1
- package/dist/observe/core/context.js +3 -3
- package/dist/observe/core/core.js +867 -367
- package/dist/observe/core/dev.js +78 -17
- package/dist/observe/core/effect.js +67 -51
- package/dist/observe/core/error-hooks.js +71 -0
- package/dist/observe/core/external.js +4 -4
- package/dist/observe/core/graph.js +37 -37
- package/dist/observe/core/heap.js +45 -45
- package/dist/observe/core/invariants.js +2 -0
- package/dist/observe/core/lanes.js +86 -49
- package/dist/observe/core/optimistic.js +242 -95
- package/dist/observe/core/owner.js +98 -84
- package/dist/observe/core/scheduler.js +543 -305
- package/dist/observe/core/verdict.js +247 -129
- package/dist/observe/index.js +7 -3
- package/dist/observe/map.js +126 -124
- package/dist/observe/signals.js +33 -17
- package/dist/observe/store/index.js +2 -0
- package/dist/observe/store/next/optimistic.js +141 -132
- package/dist/observe/store/next/projection.js +34 -21
- package/dist/observe/store/next/reconcile.js +58 -56
- package/dist/observe/store/next/store.js +260 -146
- package/dist/observe/store/store.js +5 -3
- package/dist/observe/store/utils.js +948 -135
- package/dist/prod/attribution.js +26 -17
- package/dist/prod/boundaries.js +128 -76
- package/dist/prod/core/action.js +16 -8
- package/dist/prod/core/async.js +251 -143
- package/dist/prod/core/constants.js +34 -1
- package/dist/prod/core/context.js +3 -3
- package/dist/prod/core/core.js +843 -347
- package/dist/prod/core/dev.js +17 -1
- package/dist/prod/core/effect.js +48 -34
- package/dist/prod/core/error-hooks.js +71 -0
- package/dist/prod/core/external.js +4 -4
- package/dist/prod/core/graph.js +37 -37
- package/dist/prod/core/heap.js +45 -45
- package/dist/prod/core/lanes.js +90 -53
- package/dist/prod/core/optimistic.js +247 -100
- package/dist/prod/core/owner.js +57 -45
- package/dist/prod/core/scheduler.js +543 -305
- package/dist/prod/core/verdict.js +245 -127
- package/dist/prod/index.js +7 -3
- package/dist/prod/map.js +112 -112
- package/dist/prod/signals.js +28 -12
- package/dist/prod/store/next/optimistic.js +135 -128
- package/dist/prod/store/next/projection.js +31 -20
- package/dist/prod/store/next/store.js +325 -252
- package/dist/prod/store/store.js +2 -2
- package/dist/prod/store/utils.js +946 -135
- package/dist/types/attribution.d.ts +7 -2
- package/dist/types/attribution.prod.d.ts +10 -1
- package/dist/types/boundaries.d.ts +10 -1
- package/dist/types/core/action.d.ts +12 -5
- 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 +28 -3
- package/dist/types/core/attribution-queries.d.ts +10 -0
- package/dist/types/core/attribution.d.ts +51 -172
- package/dist/types/core/constants.d.ts +33 -0
- package/dist/types/core/core.d.ts +186 -5
- package/dist/types/core/dev.d.ts +129 -9
- package/dist/types/core/error-hooks.d.ts +71 -0
- package/dist/types/core/index.d.ts +3 -1
- package/dist/types/core/invariants.d.ts +4 -0
- package/dist/types/core/lanes.d.ts +31 -4
- package/dist/types/core/scheduler.d.ts +95 -2
- package/dist/types/core/types.d.ts +3 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/signals.d.ts +8 -0
- package/dist/types/store/index.d.ts +2 -1
- package/dist/types/store/next/optimistic.d.ts +1 -1
- package/dist/types/store/next/store.d.ts +6 -5
- package/dist/types/store/next/target.d.ts +1 -1
- package/dist/types/store/utils.d.ts +177 -6
- package/package.json +1 -1
package/dist/observe/core/dev.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { withOrigin, withInteraction, setAttributionHooks, attrHooks } from "./attribution-hooks.js";
|
|
1
|
+
import { currentOrigin, withOrigin, withInteraction, setAttributionHooks, attrHooks } from "./attribution-hooks.js";
|
|
2
2
|
|
|
3
3
|
import { context } from "./core.js";
|
|
4
4
|
|
|
@@ -44,12 +44,60 @@ const attributionSlot = {
|
|
|
44
44
|
return attrHooks;
|
|
45
45
|
},
|
|
46
46
|
withInteraction: withInteraction,
|
|
47
|
-
withOrigin: withOrigin
|
|
47
|
+
withOrigin: withOrigin,
|
|
48
|
+
currentOrigin: currentOrigin
|
|
48
49
|
};
|
|
49
50
|
|
|
51
|
+
// The records channel is process-wide (see `Records`): a host that bundles
|
|
52
|
+
// the core into its server build beside an instrumented `--import`ed copy
|
|
53
|
+
// holds two of this module, and a listener installed through one must hear
|
|
54
|
+
// the records the render emits through the other. The registered key makes
|
|
55
|
+
// every copy find the one listener set; the object is generic — a Map of
|
|
56
|
+
// type to listener set — and carries no knowledge of the records.
|
|
57
|
+
const RECORDS = Symbol.for("@solidjs/signals/observe/records");
|
|
58
|
+
|
|
59
|
+
function recordsChannel() {
|
|
60
|
+
const e = globalThis;
|
|
61
|
+
if (e[RECORDS]) return e[RECORDS];
|
|
62
|
+
const t = new Map;
|
|
63
|
+
return e[RECORDS] = {
|
|
64
|
+
subscribe(e, n) {
|
|
65
|
+
let r = t.get(e);
|
|
66
|
+
if (!r) t.set(e, r = new Set);
|
|
67
|
+
r.add(n);
|
|
68
|
+
return () => {
|
|
69
|
+
r.delete(n);
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
observed(e) {
|
|
73
|
+
const n = t.get(e);
|
|
74
|
+
return n !== undefined && n.size > 0;
|
|
75
|
+
},
|
|
76
|
+
emit(e, n, r) {
|
|
77
|
+
const s = t.get(e);
|
|
78
|
+
if (s === undefined || s.size === 0) return;
|
|
79
|
+
// Snapshot: a listener unsubscribing (itself or another) mid-delivery
|
|
80
|
+
// must not skip or double-call anyone this round. A throwing listener
|
|
81
|
+
// is reported; the others, and what was observed, are unaffected.
|
|
82
|
+
for (const e of [ ...s ]) {
|
|
83
|
+
try {
|
|
84
|
+
e(n, r);
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error(e);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
50
93
|
const OBSERVE = {
|
|
51
94
|
diagnostics: diagnostics,
|
|
95
|
+
records: recordsChannel(),
|
|
52
96
|
attribution: attributionSlot,
|
|
97
|
+
// Replaced by solid-js's server entry (see `ServerObserve`); on the
|
|
98
|
+
// client the slot stays this placeholder. The cast: the interface is
|
|
99
|
+
// empty HERE and gains its members by augmentation downstream.
|
|
100
|
+
server: {},
|
|
53
101
|
subjectOf(e) {
|
|
54
102
|
return eventSubjects.get(e);
|
|
55
103
|
},
|
|
@@ -74,8 +122,8 @@ let hasExclusions = false;
|
|
|
74
122
|
|
|
75
123
|
function isExcluded(e) {
|
|
76
124
|
if (!hasExclusions || !e) return false;
|
|
77
|
-
let t = "
|
|
78
|
-
for (;t !== null; t = t.
|
|
125
|
+
let t = "_parent" in e ? e : e.nt ?? null;
|
|
126
|
+
for (;t !== null; t = t._parent) if (excludedOwners.has(t)) return true;
|
|
79
127
|
return false;
|
|
80
128
|
}
|
|
81
129
|
|
|
@@ -96,9 +144,9 @@ const DEV = undefined;
|
|
|
96
144
|
* reads as the component tree plus the scope: `<App> › <TodoRow> › effect`.
|
|
97
145
|
*/ function ownerPath(e) {
|
|
98
146
|
if (!e) return undefined;
|
|
99
|
-
let t = "
|
|
147
|
+
let t = "_parent" in e ? e : e.nt ?? null;
|
|
100
148
|
const n = [];
|
|
101
|
-
for (;t !== null; t = t.
|
|
149
|
+
for (;t !== null; t = t._parent) {
|
|
102
150
|
const e = t._name;
|
|
103
151
|
if (typeof e === "string" && e.length) n.push(e);
|
|
104
152
|
}
|
|
@@ -136,13 +184,26 @@ const DEV = undefined;
|
|
|
136
184
|
}
|
|
137
185
|
|
|
138
186
|
/**
|
|
139
|
-
* The subject each emitted event was about
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
* the
|
|
143
|
-
*
|
|
187
|
+
* The subject each emitted event was about: events are serializable records
|
|
188
|
+
* and cannot carry the node, so the node is kept beside the record for the
|
|
189
|
+
* in-process consumers that want it — the console step, which can show what
|
|
190
|
+
* the node knows (a rendering runtime may stamp a binding effect with the DOM
|
|
191
|
+
* element it writes, `_devElement`, and a live element reference beside the
|
|
192
|
+
* message is the most addressable pointer a console can print), and devtools
|
|
193
|
+
* that go from a re-run record back to the scope that ran. Keyed by the
|
|
194
|
+
* record object, so the subject lives exactly as long as some consumer holds
|
|
195
|
+
* the record (a ring buffer, a captured artifact) — the same lifetime the
|
|
196
|
+
* node had when records carried it directly.
|
|
144
197
|
*/ const eventSubjects = new WeakMap;
|
|
145
198
|
|
|
199
|
+
/** Register `subject` as what `record` was about — see `Observe.subjectOf`. */ function recordSubject(e, t) {
|
|
200
|
+
eventSubjects.set(e, t);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The live subject `record` was about, if its emitter registered one. */ function subjectOf(e) {
|
|
204
|
+
return eventSubjects.get(e);
|
|
205
|
+
}
|
|
206
|
+
|
|
146
207
|
/**
|
|
147
208
|
* The console face of a diagnostic — ONE entry per finding: the message, the
|
|
148
209
|
* owner path (`in <App> › <TodoRow> › effect`) so a human can locate it, the
|
|
@@ -163,7 +224,7 @@ const DEV = undefined;
|
|
|
163
224
|
* locate signal subjects. The per-owner `_signals` list and the devtools
|
|
164
225
|
* `onGraph` hook are dev-tier — the observe build pays one property write.
|
|
165
226
|
*/ function registerGraph(e, t) {
|
|
166
|
-
e.
|
|
227
|
+
e.nt = t;
|
|
167
228
|
}
|
|
168
229
|
|
|
169
230
|
/**
|
|
@@ -192,12 +253,12 @@ function shouldWarnGraphSize(e, t) {
|
|
|
192
253
|
*/ function noteFanOut(e, t) {
|
|
193
254
|
if (!shouldWarnGraphSize(e, t)) return;
|
|
194
255
|
const n = e._name;
|
|
195
|
-
const
|
|
256
|
+
const r = `[HUGE_FAN_OUT] ${n ? `Signal "${n}"` : "A signal"} changed with ${t} subscribers — ` + `every one re-runs this flush. If many independent computations read the same value ` + `(for example every row of a list comparing against one selected id), prefer a per-key ` + `store or projection so only the items whose result flipped update.`;
|
|
196
257
|
reportDiagnostic(emitDiagnostic({
|
|
197
258
|
code: "HUGE_FAN_OUT",
|
|
198
259
|
kind: "graph",
|
|
199
260
|
severity: "warn",
|
|
200
|
-
message:
|
|
261
|
+
message: r,
|
|
201
262
|
nodeName: n,
|
|
202
263
|
ownerId: e.id,
|
|
203
264
|
ownerName: n,
|
|
@@ -214,12 +275,12 @@ function shouldWarnGraphSize(e, t) {
|
|
|
214
275
|
*/ function noteFanIn(e, t) {
|
|
215
276
|
if (!shouldWarnGraphSize(e, t)) return;
|
|
216
277
|
const n = e._name;
|
|
217
|
-
const
|
|
278
|
+
const r = `[HUGE_FAN_IN] ${n ? `Computation "${n}"` : "A computation"} tracked ${t} sources. ` + `It will re-run when any of them change. Narrow the read or split the derivation so each ` + `computation tracks only what it needs.`;
|
|
218
279
|
reportDiagnostic(emitDiagnostic({
|
|
219
280
|
code: "HUGE_FAN_IN",
|
|
220
281
|
kind: "graph",
|
|
221
282
|
severity: "warn",
|
|
222
|
-
message:
|
|
283
|
+
message: r,
|
|
223
284
|
nodeName: n,
|
|
224
285
|
ownerId: e.id,
|
|
225
286
|
ownerName: n,
|
|
@@ -229,4 +290,4 @@ function shouldWarnGraphSize(e, t) {
|
|
|
229
290
|
}, e));
|
|
230
291
|
}
|
|
231
292
|
|
|
232
|
-
export { DEV, GRAPH_SIZE_WARN_AT, GRAPH_SIZE_WARN_EVERY, OBSERVE, anyExcluded, emitDiagnostic, isExcluded, isSuppressed, noteFanIn, noteFanOut, ownerPath, registerGraph, reportDiagnostic };
|
|
293
|
+
export { DEV, GRAPH_SIZE_WARN_AT, GRAPH_SIZE_WARN_EVERY, OBSERVE, anyExcluded, emitDiagnostic, isExcluded, isSuppressed, noteFanIn, noteFanOut, ownerPath, recordSubject, registerGraph, reportDiagnostic, subjectOf };
|
|
@@ -1,11 +1,15 @@
|
|
|
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";
|
|
1
|
+
import { REACTIVE_DISPOSED, LANE_RUN, STATUS_ERROR, EFFECT_USER, NOT_PENDING, 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
|
|
|
5
5
|
import { attrHooks } from "./attribution-hooks.js";
|
|
6
6
|
|
|
7
|
+
import "./dev.js";
|
|
8
|
+
|
|
7
9
|
import { unwrapStatusError, StatusError } from "./error.js";
|
|
8
10
|
|
|
11
|
+
import { trimStaleDeps } from "./graph.js";
|
|
12
|
+
|
|
9
13
|
import { enqueueSub } from "./heap.js";
|
|
10
14
|
|
|
11
15
|
import { GlobalQueue, currentTransition, activeTransition, haltReactivity, schedule } from "./scheduler.js";
|
|
@@ -14,20 +18,23 @@ import { GlobalQueue, currentTransition, activeTransition, haltReactivity, sched
|
|
|
14
18
|
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
|
15
19
|
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
|
16
20
|
* sources and recompute
|
|
17
|
-
*/ function effect(t, e,
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
recompute(
|
|
21
|
-
|
|
21
|
+
*/ function effect(t, e, r, E) {
|
|
22
|
+
const i = !!E?.user;
|
|
23
|
+
const n = createEffectNode(t, e, r, i ? EFFECT_USER : EFFECT_RENDER, E);
|
|
24
|
+
recompute(n, true);
|
|
25
|
+
// A first pass that derived from a live transaction's staged world was
|
|
26
|
+
// staged into that transaction (recompute: born held); the transaction's
|
|
27
|
+
// commit replays this effect. Its first run is not this creation's (A29).
|
|
28
|
+
!E?.defer && n._e === NOT_PENDING && (n.Pe === EFFECT_USER || E?.schedule ? n.T.enqueue(n.Pe, runEffect.bind(null, n)) : runEffect(n, LANE_RUN));
|
|
22
29
|
}
|
|
23
30
|
|
|
24
31
|
function notifyEffectStatus(t, e) {
|
|
25
32
|
// Use passed values if provided, otherwise read from node
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
this.
|
|
30
|
-
if (this.
|
|
33
|
+
const r = t !== undefined ? t : this.S;
|
|
34
|
+
const E = e !== undefined ? e : this.o?._;
|
|
35
|
+
if (r & STATUS_ERROR) {
|
|
36
|
+
this.T.notify(this, STATUS_PENDING, 0);
|
|
37
|
+
if (this.Pe === EFFECT_USER) {
|
|
31
38
|
// The error handler is the error arm of the effect phase (#2840 ruling):
|
|
32
39
|
// queue it like the effect function. It runs in the same imperative,
|
|
33
40
|
// writable scope, throws escalate the same way, and a held transition
|
|
@@ -38,22 +45,22 @@ function notifyEffectStatus(t, e) {
|
|
|
38
45
|
// `status` arg without node-state writes) don't queue: the status
|
|
39
46
|
// re-propagates unblocked at commit.
|
|
40
47
|
if (this.S & STATUS_ERROR) {
|
|
41
|
-
this.
|
|
42
|
-
this.
|
|
48
|
+
this.Nt = true;
|
|
49
|
+
this.T.enqueue(this.Pe, this.Ut ??= runEffect.bind(null, this));
|
|
43
50
|
}
|
|
44
51
|
return;
|
|
45
52
|
}
|
|
46
|
-
if (!this.
|
|
47
|
-
haltReactivity(unwrapStatusError(
|
|
48
|
-
throw
|
|
53
|
+
if (!this.T.notify(this, STATUS_ERROR, STATUS_ERROR)) {
|
|
54
|
+
haltReactivity(unwrapStatusError(E));
|
|
55
|
+
throw E;
|
|
49
56
|
}
|
|
50
|
-
} else if (this.
|
|
51
|
-
this.
|
|
57
|
+
} else if (this.Pe === EFFECT_RENDER) {
|
|
58
|
+
this.T.notify(this, STATUS_PENDING | STATUS_ERROR, r, E);
|
|
52
59
|
}
|
|
53
60
|
}
|
|
54
61
|
|
|
55
62
|
function runEffect(t, e) {
|
|
56
|
-
if (!t.
|
|
63
|
+
if (!t.Nt || t.ft & REACTIVE_DISPOSED) return;
|
|
57
64
|
// Ownership (#3319): a value computed under a transaction is applied by that
|
|
58
65
|
// transaction's commit. The ordinary effect phase runs with a transaction
|
|
59
66
|
// active only when the flush's finalize ENTERED one (every other path parks
|
|
@@ -70,8 +77,8 @@ function runEffect(t, e) {
|
|
|
70
77
|
// transaction. Hand the run to the regular queue, where the transaction's
|
|
71
78
|
// gate stashes it with the owner. Lane-less runners with no live owner
|
|
72
79
|
// (reverts, wake-only lanes) apply now.
|
|
73
|
-
if (t.Vt !== null && !currentTransition(t.Vt).
|
|
74
|
-
t.
|
|
80
|
+
if (t.Vt !== null && !currentTransition(t.Vt).yt && (e & LANE_RUN ? !t.o?.de : activeTransition !== null)) {
|
|
81
|
+
t.T.enqueue(t.Pe, t.Ut);
|
|
75
82
|
return;
|
|
76
83
|
}
|
|
77
84
|
// Error arm (#2840), user effects only: a compute-phase error that is still
|
|
@@ -84,49 +91,58 @@ function runEffect(t, e) {
|
|
|
84
91
|
// Render effects bypass: their errors route to boundaries synchronously in
|
|
85
92
|
// notifyEffectStatus, and a runner queued by an earlier valueChanged in the
|
|
86
93
|
// same flush must not be hijacked by a later-arriving error status.
|
|
87
|
-
if (t.S & STATUS_ERROR && t.
|
|
94
|
+
if (t.S & STATUS_ERROR && t.Pe === EFFECT_USER) {
|
|
88
95
|
const e = unwrapStatusError(t.o?._);
|
|
89
|
-
t
|
|
90
|
-
t.
|
|
96
|
+
t.$t = t.Ae;
|
|
97
|
+
t.Nt = false;
|
|
91
98
|
try {
|
|
92
|
-
t.
|
|
93
|
-
const e = t.
|
|
94
|
-
t.
|
|
99
|
+
t.un ? t.un(e, () => {
|
|
100
|
+
const e = t.an;
|
|
101
|
+
t.an = undefined;
|
|
95
102
|
e?.();
|
|
96
103
|
}) : console.error(e);
|
|
97
104
|
} catch (e) {
|
|
98
|
-
if (!t.
|
|
105
|
+
if (!t.T.notify(t, STATUS_ERROR, STATUS_ERROR)) {
|
|
99
106
|
haltReactivity(e);
|
|
100
107
|
throw e;
|
|
101
108
|
}
|
|
102
109
|
}
|
|
103
110
|
return;
|
|
104
111
|
}
|
|
105
|
-
|
|
106
|
-
|
|
112
|
+
// Captured before the callback: its own throw errors the node below, but
|
|
113
|
+
// the compute pass that produced `_value` was clean, so its tail still goes.
|
|
114
|
+
const r = t.o?._ == null;
|
|
115
|
+
const E = t.an;
|
|
116
|
+
t.an = undefined;
|
|
107
117
|
try {
|
|
108
118
|
E?.();
|
|
109
|
-
const e = t.
|
|
119
|
+
const e = t.ln(t.Ae, t.$t);
|
|
110
120
|
if (false && e !== undefined && typeof e !== "function") ;
|
|
111
121
|
// The final cleanup is invoked by disposeChildren at true disposal.
|
|
112
|
-
t.
|
|
122
|
+
t.an = e;
|
|
113
123
|
} catch (e) {
|
|
114
124
|
ext(t)._ = new StatusError(t, e);
|
|
115
125
|
t.S |= STATUS_ERROR;
|
|
116
|
-
if (!t.
|
|
126
|
+
if (!t.T.notify(t, STATUS_ERROR, STATUS_ERROR)) {
|
|
117
127
|
haltReactivity(e);
|
|
118
128
|
throw e;
|
|
119
129
|
}
|
|
120
130
|
} finally {
|
|
121
|
-
t
|
|
122
|
-
t.
|
|
131
|
+
t.$t = t.Ae;
|
|
132
|
+
t.Nt = false;
|
|
133
|
+
// The run applied: this is the frame now, so the dependency tail the
|
|
134
|
+
// compute pass left linked goes (A30, #3438 — `recompute` defers an
|
|
135
|
+
// effect's trim while a run is owed; the twin of `commitPendingNode`'s
|
|
136
|
+
// trim for a staged pass). An errored compute kept its full list with
|
|
137
|
+
// `_depsTail` marking where it stopped; leave it, as the commit does.
|
|
138
|
+
if (r) trimStaleDeps(t);
|
|
123
139
|
}
|
|
124
140
|
// Outside the try (see the rule in attribution-hooks.ts). Reached whether or
|
|
125
141
|
// not the callback threw — a throw that escapes the catch above halts.
|
|
126
142
|
if (attrHooks !== null) attrHooks.effectRunEnd(t);
|
|
127
143
|
}
|
|
128
144
|
|
|
129
|
-
GlobalQueue.
|
|
145
|
+
GlobalQueue.Lt = runEffect;
|
|
130
146
|
|
|
131
147
|
/**
|
|
132
148
|
* Internal tracked effect - bypasses heap, goes directly to effect queue.
|
|
@@ -137,37 +153,37 @@ GlobalQueue.bt = runEffect;
|
|
|
137
153
|
// `_modified` is NOT redundant with the heap: the heap dedups within a
|
|
138
154
|
// pass, but a held transition's passes each enqueue `_run` into the same
|
|
139
155
|
// user queue, and this gate is what collapses them into one run at commit.
|
|
140
|
-
if (!
|
|
156
|
+
if (!r.Nt || r.ft & REACTIVE_DISPOSED) return;
|
|
141
157
|
try {
|
|
142
|
-
|
|
143
|
-
recompute(
|
|
158
|
+
r.Nt = false;
|
|
159
|
+
recompute(r);
|
|
144
160
|
} finally {}
|
|
145
161
|
};
|
|
146
|
-
const
|
|
147
|
-
const e =
|
|
148
|
-
|
|
162
|
+
const r = computed(() => {
|
|
163
|
+
const e = r.an;
|
|
164
|
+
r.an = undefined;
|
|
149
165
|
e?.();
|
|
150
|
-
const
|
|
151
|
-
|
|
166
|
+
const E = staleValues(t);
|
|
167
|
+
r.an = E;
|
|
152
168
|
}, {
|
|
153
169
|
...e,
|
|
154
170
|
lazy: true
|
|
155
171
|
});
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
172
|
+
r.an = undefined;
|
|
173
|
+
r.C = r.C & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
|
|
174
|
+
r.Nt = true;
|
|
175
|
+
r.Pe = EFFECT_TRACKED;
|
|
160
176
|
// Observe-tier label: the computed literal defaulted its `_name` slot to
|
|
161
177
|
// "computed"; relabel by kind (a store into the slot, not a new field).
|
|
162
|
-
if (e?.name === undefined)
|
|
178
|
+
if (e?.name === undefined) r._name = "trackedEffect";
|
|
163
179
|
// Status dispatch rides the SHARED notifier (statusNotifierOf keys off
|
|
164
180
|
// _type): its error arm is behavior-identical to the closure that used to
|
|
165
181
|
// live here, without the per-node NodeExtension allocation.
|
|
166
|
-
|
|
182
|
+
r.Et = run;
|
|
167
183
|
// The first run rides the heap like every wake (GlobalQueue._update), so a
|
|
168
184
|
// tracked effect created inside a render-effect callback runs after that
|
|
169
185
|
// pass's staged writes commit, not before.
|
|
170
|
-
enqueueSub(
|
|
186
|
+
enqueueSub(r);
|
|
171
187
|
schedule();
|
|
172
188
|
}
|
|
173
189
|
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { ROOT_ERROR_HOOK } from "./scheduler.js";
|
|
2
|
+
|
|
3
|
+
let ambientHook;
|
|
4
|
+
|
|
5
|
+
const reported = new WeakSet;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Registers the ambient client error hook — the one call a browser `init()`
|
|
9
|
+
* makes to see every failure a boundary renders a fallback for, in
|
|
10
|
+
* production. (Uncaught errors reach `reportError` / `window.onerror`.)
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* configureClientErrors({
|
|
14
|
+
* onError: (error, { ownerPath }) =>
|
|
15
|
+
* Sentry.captureException(error, {
|
|
16
|
+
* mechanism: { type: "solid.error_boundary", handled: true }
|
|
17
|
+
* })
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/ function configureClientErrors(e) {
|
|
21
|
+
if (e && e.onError !== undefined && typeof e.onError !== "function") {
|
|
22
|
+
throw new TypeError(`Invalid onError: expected a function, received ${typeof e.onError}.`);
|
|
23
|
+
}
|
|
24
|
+
ambientHook = e ? e.onError : undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The nearest root's hook above `owner` (parked under `ROOT_ERROR_HOOK`), else the ambient one. */ function hookFor(e) {
|
|
28
|
+
for (let n = e; n; n = n._parent) {
|
|
29
|
+
const e = n[ROOT_ERROR_HOOK];
|
|
30
|
+
if (e !== undefined) return e;
|
|
31
|
+
}
|
|
32
|
+
return ambientHook;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Component labels up the owner chain, root first — `_name` where the runtime keeps it. */ function labels(e) {
|
|
36
|
+
const n = [];
|
|
37
|
+
for (let o = e; o; o = o._parent) {
|
|
38
|
+
const e = o._name;
|
|
39
|
+
if (typeof e === "string" && e.length) n.push(e);
|
|
40
|
+
}
|
|
41
|
+
return n.length ? n.reverse() : undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Tells the client error hook about `error`, caught by the boundary whose
|
|
46
|
+
* owner is `owner`, thrown by `thrower` (the computation the engine's status
|
|
47
|
+
* wrapper named; unknown for a value that never crossed one) — once per
|
|
48
|
+
* error object. A throwing hook is reported on the console and otherwise
|
|
49
|
+
* ignored — a monitor must never take the app down.
|
|
50
|
+
* @internal
|
|
51
|
+
*/ function reportClientError(e, n, o) {
|
|
52
|
+
const r = e !== null && (typeof e === "object" || typeof e === "function");
|
|
53
|
+
if (r) {
|
|
54
|
+
if (reported.has(e)) return;
|
|
55
|
+
reported.add(e);
|
|
56
|
+
}
|
|
57
|
+
const t = hookFor(n);
|
|
58
|
+
if (t === undefined) return;
|
|
59
|
+
const i = {};
|
|
60
|
+
const f = labels(n);
|
|
61
|
+
const c = labels(o) ?? f;
|
|
62
|
+
if (c !== undefined) i.ownerPath = c;
|
|
63
|
+
if (f !== undefined) i.boundaryPath = f;
|
|
64
|
+
try {
|
|
65
|
+
t(e, i);
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.error(e);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { configureClientErrors, reportClientError };
|
|
@@ -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.ht, () => {
|
|
50
50
|
setSignal(n, undefined);
|
|
51
51
|
});
|
|
52
52
|
cleanup(() => r.dispose());
|
|
53
|
-
e.
|
|
53
|
+
e.ht = e => {
|
|
54
54
|
read(n);
|
|
55
55
|
return r.track(e);
|
|
56
56
|
};
|
|
@@ -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._n = externalSourceConfig ? wireExternalSource : null;
|
|
68
|
+
GlobalQueue.In = externalSourceConfig ? externalUntrack : null;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function enableExternalSource(e) {
|
|
@@ -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.
|
|
16
|
-
const s = e.
|
|
17
|
-
if (o !== null) o.
|
|
18
|
-
if (s !== null) s.
|
|
13
|
+
const n = e.re;
|
|
14
|
+
const l = e.te;
|
|
15
|
+
const o = e.ie;
|
|
16
|
+
const s = e.bn;
|
|
17
|
+
if (o !== null) o.bn = s; else n.qt = s;
|
|
18
|
+
if (s !== null) s.ie = 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.
|
|
23
|
+
if (n.C & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.o?.Kt?.();
|
|
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
|
|
@@ -28,20 +28,20 @@ function unlinkSubs(e) {
|
|
|
28
28
|
// this same last-one-out check when that observer releases (the
|
|
29
29
|
// untracked-read dormancy sweep guards on pending identically).
|
|
30
30
|
const e = n;
|
|
31
|
-
e.
|
|
31
|
+
e.ht && e.C & CONFIG_AUTO_DISPOSE && !(e.ft & REACTIVE_ZOMBIE) && !(e.S & STATUS_PENDING) && unobserved(e);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
return l;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function trimStaleDeps(e) {
|
|
38
|
-
const n = e.
|
|
39
|
-
let l = n !== null ? n.
|
|
38
|
+
const n = e.Fe;
|
|
39
|
+
let l = n !== null ? n.te : e.ee;
|
|
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.te = null; else e.ee = 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.ee;
|
|
54
54
|
if (!n) return;
|
|
55
55
|
do {
|
|
56
56
|
n = unlinkSubs(n);
|
|
57
57
|
} while (n !== null);
|
|
58
|
-
e.
|
|
59
|
-
e.
|
|
58
|
+
e.ee = null;
|
|
59
|
+
e.Fe = null;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
function unobserved(e) {
|
|
@@ -94,7 +94,7 @@ function sweepDormant() {
|
|
|
94
94
|
// is an observer; the settle path re-runs last-one-out), lost its
|
|
95
95
|
// AUTO_DISPOSE bit (owner teardown strips it, #3024), or already been
|
|
96
96
|
// torn down.
|
|
97
|
-
if (!e.u && e.
|
|
97
|
+
if (!e.u && e.C & CONFIG_AUTO_DISPOSE && !(e.S & STATUS_PENDING) && !(e.ft & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
|
|
98
98
|
unobserved(e);
|
|
99
99
|
}
|
|
100
100
|
}
|
|
@@ -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.Fe;
|
|
112
|
+
if (o !== null && o.re === e) {
|
|
113
|
+
o.Ce &&= l;
|
|
114
114
|
return;
|
|
115
115
|
}
|
|
116
116
|
let s = null;
|
|
117
|
-
const t = n.
|
|
117
|
+
const t = n.ft & 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.te : n.ee;
|
|
120
|
+
if (s !== null && s.re === e) {
|
|
121
|
+
s.pe = n.ye;
|
|
122
|
+
n.Fe = s;
|
|
123
123
|
// First touch of this pass: the previous pass's label is stale.
|
|
124
|
-
s.
|
|
124
|
+
s.Ce = 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.qt;
|
|
134
|
+
if (r !== null && r.se === n && (!t || r.pe === n.ye)) {
|
|
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.Ce &&= l; else r.Ce = l;
|
|
138
138
|
return;
|
|
139
139
|
}
|
|
140
|
-
const u = n.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
const u = n.Fe = e.qt = {
|
|
141
|
+
re: e,
|
|
142
|
+
se: n,
|
|
143
|
+
te: s,
|
|
144
|
+
bn: r,
|
|
145
|
+
ie: null,
|
|
146
|
+
pe: n.ye,
|
|
147
|
+
Ce: l
|
|
148
148
|
};
|
|
149
|
-
if (o !== null) o.
|
|
150
|
-
if (r !== null) r.
|
|
149
|
+
if (o !== null) o.te = u; else n.ee = u;
|
|
150
|
+
if (r !== null) r.ie = u; else e.u = u;
|
|
151
151
|
// New subscriber edge: staged-rewrite skips (§12d) must not miss it.
|
|
152
152
|
bumpNotifyEpoch();
|
|
153
153
|
}
|