@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
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { withOrigin, withInteraction, setAttributionHooks, attrHooks } from "./attribution-hooks.js";
|
|
2
|
+
|
|
3
|
+
import { context } from "./core.js";
|
|
4
|
+
|
|
5
|
+
/** First warning when a change reaches (or a pass tracks) this many edges. */ const GRAPH_SIZE_WARN_AT = 2e3;
|
|
6
|
+
|
|
7
|
+
/** Re-warn once the count has grown by this much since the last warning. */ const GRAPH_SIZE_WARN_EVERY = 500;
|
|
8
|
+
|
|
9
|
+
const diagnosticListeners = new Set;
|
|
10
|
+
|
|
11
|
+
const diagnosticCaptures = new Set;
|
|
12
|
+
|
|
13
|
+
let diagnosticSequence = 0;
|
|
14
|
+
|
|
15
|
+
const diagnostics = {
|
|
16
|
+
subscribe(e) {
|
|
17
|
+
diagnosticListeners.add(e);
|
|
18
|
+
return () => diagnosticListeners.delete(e);
|
|
19
|
+
},
|
|
20
|
+
emit(e, t = null) {
|
|
21
|
+
return emitDiagnostic(e, t);
|
|
22
|
+
},
|
|
23
|
+
capture() {
|
|
24
|
+
const e = [];
|
|
25
|
+
diagnosticCaptures.add(e);
|
|
26
|
+
return {
|
|
27
|
+
get events() {
|
|
28
|
+
return e;
|
|
29
|
+
},
|
|
30
|
+
clear() {
|
|
31
|
+
e.length = 0;
|
|
32
|
+
},
|
|
33
|
+
stop() {
|
|
34
|
+
diagnosticCaptures.delete(e);
|
|
35
|
+
return [ ...e ];
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const attributionSlot = {
|
|
42
|
+
install: setAttributionHooks,
|
|
43
|
+
get installed() {
|
|
44
|
+
return attrHooks;
|
|
45
|
+
},
|
|
46
|
+
withInteraction: withInteraction,
|
|
47
|
+
withOrigin: withOrigin
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const OBSERVE = {
|
|
51
|
+
diagnostics: diagnostics,
|
|
52
|
+
attribution: attributionSlot,
|
|
53
|
+
subjectOf(e) {
|
|
54
|
+
return eventSubjects.get(e);
|
|
55
|
+
},
|
|
56
|
+
exclude(e) {
|
|
57
|
+
excludedOwners.add(e);
|
|
58
|
+
hasExclusions = true;
|
|
59
|
+
},
|
|
60
|
+
isExcluded: isExcluded
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// --- Excluded owners ---------------------------------------------------------------
|
|
64
|
+
|
|
65
|
+
// An observer that lives inside the observed app (an adapter's panel,
|
|
66
|
+
// devtools) marks its root; both channels check the subject's owner chain —
|
|
67
|
+
// the same walk `ownerPath` already makes — and stay silent under it. The
|
|
68
|
+
// flag short-circuits the walk for the common case of no exclusions.
|
|
69
|
+
const excludedOwners = new WeakSet;
|
|
70
|
+
|
|
71
|
+
let hasExclusions = false;
|
|
72
|
+
|
|
73
|
+
/** Events built for an excluded subject: never delivered, never reported. */ const suppressedEvents = new WeakSet;
|
|
74
|
+
|
|
75
|
+
function isExcluded(e) {
|
|
76
|
+
if (!hasExclusions || !e) return false;
|
|
77
|
+
let t = "Nt" in e ? e : e.an ?? null;
|
|
78
|
+
for (;t !== null; t = t.Nt) if (excludedOwners.has(t)) return true;
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** For engines that cache the verdict per node: is anything excluded at all? */ function anyExcluded() {
|
|
83
|
+
return hasExclusions;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Was `entry` built for an excluded subject? Once-per-key reporters must not spend their slot on it. */ function isSuppressed(e) {
|
|
87
|
+
return suppressedEvents.has(e);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const DEV = undefined;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Root-first names of the owners enclosing `subject` (inclusive when the
|
|
94
|
+
* subject is itself a named owner). Signals hop to their registering owner
|
|
95
|
+
* (`_owner`, set by registerGraph). Unnamed owners are skipped so the path
|
|
96
|
+
* reads as the component tree plus the scope: `<App> › <TodoRow> › effect`.
|
|
97
|
+
*/ function ownerPath(e) {
|
|
98
|
+
if (!e) return undefined;
|
|
99
|
+
let t = "Nt" in e ? e : e.an ?? null;
|
|
100
|
+
const n = [];
|
|
101
|
+
for (;t !== null; t = t.Nt) {
|
|
102
|
+
const e = t._name;
|
|
103
|
+
if (typeof e === "string" && e.length) n.push(e);
|
|
104
|
+
}
|
|
105
|
+
return n.length ? n.reverse() : undefined;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Records a diagnostic on the structured channel (listeners, captures) and
|
|
110
|
+
* returns the entry. `subject` locates it: the current reactive `context` by
|
|
111
|
+
* default (right for the synchronous rule checks — they fire inside the
|
|
112
|
+
* scope that misbehaved); pass the node for scheduler-time findings whose
|
|
113
|
+
* ambient context is the flush, or `null` for events that have no location
|
|
114
|
+
* by nature. An `ownerPath` already on the event wins over the subject walk
|
|
115
|
+
* (hosts whose owners are not signals' owners compute their own). Console
|
|
116
|
+
* output is a separate, dev-tier step — see `reportDiagnostic`.
|
|
117
|
+
*/ function emitDiagnostic(e, t = context) {
|
|
118
|
+
const n = {
|
|
119
|
+
sequence: ++diagnosticSequence,
|
|
120
|
+
...e
|
|
121
|
+
};
|
|
122
|
+
// The observer's own subtree: build the entry (the caller may throw its
|
|
123
|
+
// message) but tell nobody.
|
|
124
|
+
if (isExcluded(t)) {
|
|
125
|
+
suppressedEvents.add(n);
|
|
126
|
+
return n;
|
|
127
|
+
}
|
|
128
|
+
if (n.ownerPath === undefined) {
|
|
129
|
+
const e = ownerPath(t);
|
|
130
|
+
if (e) n.ownerPath = e;
|
|
131
|
+
}
|
|
132
|
+
if (t) eventSubjects.set(n, t);
|
|
133
|
+
for (const e of diagnosticListeners) e(n);
|
|
134
|
+
for (const e of diagnosticCaptures) e.push(n);
|
|
135
|
+
return n;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The subject each emitted event was about, for the console step: events are
|
|
140
|
+
* serializable records and cannot carry the node, but the console can show
|
|
141
|
+
* what the node knows — a rendering runtime may stamp a binding effect with
|
|
142
|
+
* the DOM element it writes (`_devElement`), and a live element reference
|
|
143
|
+
* beside the message is the most addressable pointer a console can print.
|
|
144
|
+
*/ const eventSubjects = new WeakMap;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* The console face of a diagnostic — ONE entry per finding: the message, the
|
|
148
|
+
* owner path (`in <App> › <TodoRow> › effect`) so a human can locate it, the
|
|
149
|
+
* once-per-code footer as trailing lines, and — when the subject is a
|
|
150
|
+
* binding effect the rendering runtime tagged — the element it writes, as a
|
|
151
|
+
* second console argument (hover highlights it, click jumps to Elements).
|
|
152
|
+
* Severity picks the console method. Call sites report the entry
|
|
153
|
+
* `emitDiagnostic` returned so the structured and console channels never
|
|
154
|
+
* disagree. Dev-tier: in an observe build this is a no-op, so wiring paths
|
|
155
|
+
* that both emit and report (graph-size warnings) reach the channel only —
|
|
156
|
+
* production observability never writes to the console.
|
|
157
|
+
*/ function reportDiagnostic(e) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Observe-tier: stamp a signal with its creating owner so `ownerPath` can
|
|
163
|
+
* locate signal subjects. The per-owner `_signals` list and the devtools
|
|
164
|
+
* `onGraph` hook are dev-tier — the observe build pays one property write.
|
|
165
|
+
*/ function registerGraph(e, t) {
|
|
166
|
+
e.an = t;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Graph-size warnings are once per node, re-warning only when the count has
|
|
171
|
+
* grown by GRAPH_SIZE_WARN_EVERY since the last one — off-node, so the
|
|
172
|
+
* pathological handful of nodes that ever reach the threshold are the only
|
|
173
|
+
* ones that cost anything, and no node carries a bookkeeping field for it.
|
|
174
|
+
*/ const graphSizeWarnedAt = new WeakMap;
|
|
175
|
+
|
|
176
|
+
function shouldWarnGraphSize(e, t) {
|
|
177
|
+
const n = graphSizeWarnedAt.get(e);
|
|
178
|
+
if (n !== undefined && t < n + GRAPH_SIZE_WARN_EVERY) return false;
|
|
179
|
+
graphSizeWarnedAt.set(e, t);
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Observe-tier: a committed change on `node` is about to re-run `count`
|
|
185
|
+
* subscribers (the notify walk in `insertSubs` counted them as it went —
|
|
186
|
+
* fan-out costs exactly one local increment in a loop that already visits
|
|
187
|
+
* every edge, and nothing at link time). Fires from GRAPH_SIZE_WARN_AT up,
|
|
188
|
+
* on the write rather than the link: a fan-out that is never written costs
|
|
189
|
+
* nothing, and one that is re-runs every subscriber this flush. Always-on
|
|
190
|
+
* wherever the channel exists — unlike the opt-in attribution engine, a
|
|
191
|
+
* graph-size pathology should surface without asking.
|
|
192
|
+
*/ function noteFanOut(e, t) {
|
|
193
|
+
if (!shouldWarnGraphSize(e, t)) return;
|
|
194
|
+
const n = e._name;
|
|
195
|
+
const i = `[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
|
+
reportDiagnostic(emitDiagnostic({
|
|
197
|
+
code: "HUGE_FAN_OUT",
|
|
198
|
+
kind: "graph",
|
|
199
|
+
severity: "warn",
|
|
200
|
+
message: i,
|
|
201
|
+
nodeName: n,
|
|
202
|
+
ownerId: e.id,
|
|
203
|
+
ownerName: n,
|
|
204
|
+
data: {
|
|
205
|
+
count: t
|
|
206
|
+
}
|
|
207
|
+
}, e));
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Observe-tier: a recompute pass of `node` tracked `count` distinct sources
|
|
212
|
+
* (its trimmed dep list, walked once at the end of the pass — see recompute;
|
|
213
|
+
* no per-link work, no pass bracket). Fires from GRAPH_SIZE_WARN_AT up.
|
|
214
|
+
*/ function noteFanIn(e, t) {
|
|
215
|
+
if (!shouldWarnGraphSize(e, t)) return;
|
|
216
|
+
const n = e._name;
|
|
217
|
+
const i = `[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
|
+
reportDiagnostic(emitDiagnostic({
|
|
219
|
+
code: "HUGE_FAN_IN",
|
|
220
|
+
kind: "graph",
|
|
221
|
+
severity: "warn",
|
|
222
|
+
message: i,
|
|
223
|
+
nodeName: n,
|
|
224
|
+
ownerId: e.id,
|
|
225
|
+
ownerName: n,
|
|
226
|
+
data: {
|
|
227
|
+
count: t
|
|
228
|
+
}
|
|
229
|
+
}, e));
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { DEV, GRAPH_SIZE_WARN_AT, GRAPH_SIZE_WARN_EVERY, OBSERVE, anyExcluded, emitDiagnostic, isExcluded, isSuppressed, noteFanIn, noteFanOut, ownerPath, registerGraph, reportDiagnostic };
|
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
|
|
3
|
+
import { setEffectStatusNotify, ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
|
|
4
|
+
|
|
5
|
+
import { attrHooks } from "./attribution-hooks.js";
|
|
6
|
+
|
|
7
|
+
import { unwrapStatusError, StatusError } from "./error.js";
|
|
8
|
+
|
|
9
|
+
import { enqueueSub } from "./heap.js";
|
|
10
|
+
|
|
11
|
+
import { GlobalQueue, currentTransition, activeTransition, haltReactivity, schedule } from "./scheduler.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
|
15
|
+
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
|
16
|
+
* sources and recompute
|
|
17
|
+
*/ function effect(t, e, E, r) {
|
|
18
|
+
const n = !!r?.user;
|
|
19
|
+
const f = createEffectNode(t, e, E, n ? EFFECT_USER : EFFECT_RENDER, r);
|
|
20
|
+
recompute(f, true);
|
|
21
|
+
!r?.defer && (f.Re === EFFECT_USER || r?.schedule ? f.C.enqueue(f.Re, runEffect.bind(null, f)) : runEffect(f, LANE_RUN));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function notifyEffectStatus(t, e) {
|
|
25
|
+
// Use passed values if provided, otherwise read from node
|
|
26
|
+
const E = t !== undefined ? t : this.S;
|
|
27
|
+
const r = e !== undefined ? e : this.o?._;
|
|
28
|
+
if (E & STATUS_ERROR) {
|
|
29
|
+
this.C.notify(this, STATUS_PENDING, 0);
|
|
30
|
+
if (this.Re === EFFECT_USER) {
|
|
31
|
+
// The error handler is the error arm of the effect phase (#2840 ruling):
|
|
32
|
+
// queue it like the effect function. It runs in the same imperative,
|
|
33
|
+
// writable scope, throws escalate the same way, and a held transition
|
|
34
|
+
// (or optimistic lane) defers it exactly as it defers the success arm.
|
|
35
|
+
// No payload is queued — the node already carries `_statusFlags`/`_error`,
|
|
36
|
+
// and the runner dispatches on them, so a recovery before the effect
|
|
37
|
+
// phase takes the success arm instead. Blocked forwards (explicit
|
|
38
|
+
// `status` arg without node-state writes) don't queue: the status
|
|
39
|
+
// re-propagates unblocked at commit.
|
|
40
|
+
if (this.S & STATUS_ERROR) {
|
|
41
|
+
this._t = true;
|
|
42
|
+
this.C.enqueue(this.Re, this.kt ??= runEffect.bind(null, this));
|
|
43
|
+
}
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!this.C.notify(this, STATUS_ERROR, STATUS_ERROR)) {
|
|
47
|
+
haltReactivity(unwrapStatusError(r));
|
|
48
|
+
throw r;
|
|
49
|
+
}
|
|
50
|
+
} else if (this.Re === EFFECT_RENDER) {
|
|
51
|
+
this.C.notify(this, STATUS_PENDING | STATUS_ERROR, E, r);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function runEffect(t, e) {
|
|
56
|
+
if (!t._t || t.it & REACTIVE_DISPOSED) return;
|
|
57
|
+
// Ownership (#3319): a value computed under a transaction is applied by that
|
|
58
|
+
// transaction's commit. The ordinary effect phase runs with a transaction
|
|
59
|
+
// active only when the flush's finalize ENTERED one (every other path parks
|
|
60
|
+
// or settles first): leave a run owned by a still-held transaction queued —
|
|
61
|
+
// `_modified` stays set — and the next gate stashes it with the owner.
|
|
62
|
+
// Mainline-owned runs (null) apply now. Lanes are exempt by design (they
|
|
63
|
+
// apply their own effects ahead of their transaction — the optimistic view)
|
|
64
|
+
// and mark their runs with LANE_RUN.
|
|
65
|
+
|
|
66
|
+
// Lane exemption has one exception (#3331): a lane runner for an effect that
|
|
67
|
+
// no longer rides a lane — its optimistic source was superseded, so the lane
|
|
68
|
+
// has no optimistic view left to apply, and the value this effect now
|
|
69
|
+
// carries (or will, once its plain recompute lands) belongs to the still-held
|
|
70
|
+
// transaction. Hand the run to the regular queue, where the transaction's
|
|
71
|
+
// gate stashes it with the owner. Lane-less runners with no live owner
|
|
72
|
+
// (reverts, wake-only lanes) apply now.
|
|
73
|
+
if (t.Vt !== null && !currentTransition(t.Vt).Ut && (e & LANE_RUN ? !t.o?.Te : activeTransition !== null)) {
|
|
74
|
+
t.C.enqueue(t.Re, t.kt);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// Error arm (#2840), user effects only: a compute-phase error that is still
|
|
78
|
+
// the node's settled state at effect time runs the bundle's error handler in
|
|
79
|
+
// this same imperative, writable scope. Unwrap the StatusError used for
|
|
80
|
+
// source tracking — user code gets the error it threw, as boundaries do. No
|
|
81
|
+
// handler: log and keep the system alive (the run was skipped). A handler
|
|
82
|
+
// (or logging) consumes the error; a handler throw falls to the shared
|
|
83
|
+
// catch below and escalates boundary-or-halt like any effect-phase throw.
|
|
84
|
+
// Render effects bypass: their errors route to boundaries synchronously in
|
|
85
|
+
// notifyEffectStatus, and a runner queued by an earlier valueChanged in the
|
|
86
|
+
// same flush must not be hijacked by a later-arriving error status.
|
|
87
|
+
if (t.S & STATUS_ERROR && t.Re === EFFECT_USER) {
|
|
88
|
+
const e = unwrapStatusError(t.o?._);
|
|
89
|
+
t.Bt = t.ge;
|
|
90
|
+
t._t = false;
|
|
91
|
+
try {
|
|
92
|
+
t.Jt ? t.Jt(e, () => {
|
|
93
|
+
const e = t.Xt;
|
|
94
|
+
t.Xt = undefined;
|
|
95
|
+
e?.();
|
|
96
|
+
}) : console.error(e);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
if (!t.C.notify(t, STATUS_ERROR, STATUS_ERROR)) {
|
|
99
|
+
haltReactivity(e);
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const E = t.Xt;
|
|
106
|
+
t.Xt = undefined;
|
|
107
|
+
try {
|
|
108
|
+
E?.();
|
|
109
|
+
const e = t.zt(t.ge, t.Bt);
|
|
110
|
+
if (false && e !== undefined && typeof e !== "function") ;
|
|
111
|
+
// The final cleanup is invoked by disposeChildren at true disposal.
|
|
112
|
+
t.Xt = e;
|
|
113
|
+
} catch (e) {
|
|
114
|
+
ext(t)._ = new StatusError(t, e);
|
|
115
|
+
t.S |= STATUS_ERROR;
|
|
116
|
+
if (!t.C.notify(t, STATUS_ERROR, STATUS_ERROR)) {
|
|
117
|
+
haltReactivity(e);
|
|
118
|
+
throw e;
|
|
119
|
+
}
|
|
120
|
+
} finally {
|
|
121
|
+
t.Bt = t.ge;
|
|
122
|
+
t._t = false;
|
|
123
|
+
}
|
|
124
|
+
// Outside the try (see the rule in attribution-hooks.ts). Reached whether or
|
|
125
|
+
// not the callback threw — a throw that escapes the catch above halts.
|
|
126
|
+
if (attrHooks !== null) attrHooks.effectRunEnd(t);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
GlobalQueue.bt = runEffect;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Internal tracked effect - bypasses heap, goes directly to effect queue.
|
|
133
|
+
* Runs as a leaf owner: child primitives and onCleanup are forbidden (false throws).
|
|
134
|
+
* Uses stale reads.
|
|
135
|
+
*/ function trackedEffect(t, e) {
|
|
136
|
+
const run = () => {
|
|
137
|
+
// `_modified` is NOT redundant with the heap: the heap dedups within a
|
|
138
|
+
// pass, but a held transition's passes each enqueue `_run` into the same
|
|
139
|
+
// user queue, and this gate is what collapses them into one run at commit.
|
|
140
|
+
if (!E._t || E.it & REACTIVE_DISPOSED) return;
|
|
141
|
+
try {
|
|
142
|
+
E._t = false;
|
|
143
|
+
recompute(E);
|
|
144
|
+
} finally {}
|
|
145
|
+
};
|
|
146
|
+
const E = computed(() => {
|
|
147
|
+
const e = E.Xt;
|
|
148
|
+
E.Xt = undefined;
|
|
149
|
+
e?.();
|
|
150
|
+
const r = staleValues(t);
|
|
151
|
+
E.Xt = r;
|
|
152
|
+
}, {
|
|
153
|
+
...e,
|
|
154
|
+
lazy: true
|
|
155
|
+
});
|
|
156
|
+
E.Xt = undefined;
|
|
157
|
+
E.T = E.T & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
|
|
158
|
+
E._t = true;
|
|
159
|
+
E.Re = EFFECT_TRACKED;
|
|
160
|
+
// Observe-tier label: the computed literal defaulted its `_name` slot to
|
|
161
|
+
// "computed"; relabel by kind (a store into the slot, not a new field).
|
|
162
|
+
if (e?.name === undefined) E._name = "trackedEffect";
|
|
163
|
+
// Status dispatch rides the SHARED notifier (statusNotifierOf keys off
|
|
164
|
+
// _type): its error arm is behavior-identical to the closure that used to
|
|
165
|
+
// live here, without the per-node NodeExtension allocation.
|
|
166
|
+
E.ct = run;
|
|
167
|
+
// The first run rides the heap like every wake (GlobalQueue._update), so a
|
|
168
|
+
// tracked effect created inside a render-effect callback runs after that
|
|
169
|
+
// pass's staged writes commit, not before.
|
|
170
|
+
enqueueSub(E);
|
|
171
|
+
schedule();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Install the shared effect status notifier (statusNotifierOf serves it to
|
|
175
|
+
// every effect node) — module-scope: any bundle that creates effects
|
|
176
|
+
// evaluates this module.
|
|
177
|
+
setEffectStatusNotify(notifyEffectStatus);
|
|
178
|
+
|
|
179
|
+
export { effect, trackedEffect };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thrown by a tracked read whose value is currently pending (an async memo /
|
|
3
|
+
* `createSignal(asyncFn)` / projection / store derivation that hasn't settled
|
|
4
|
+
* yet). Surfacing through the reactive graph is what suspends the consumer
|
|
5
|
+
* scope — the nearest enclosing `<Loading>` boundary catches the throw and
|
|
6
|
+
* renders its fallback until the source resolves.
|
|
7
|
+
*
|
|
8
|
+
* App code rarely catches this directly; `<Loading>` is the canonical
|
|
9
|
+
* handler. The error type is exposed for advanced cases — e.g. interop layers
|
|
10
|
+
* that bridge Solid's pending-throw protocol to a different async strategy,
|
|
11
|
+
* or tests that want to assert on the suspension shape.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* // Advanced: distinguish "not ready yet" from a real error in custom
|
|
16
|
+
* // boundary plumbing. App code should rely on `<Loading>` / `<Errored>`.
|
|
17
|
+
* try {
|
|
18
|
+
* const value = readReactiveSource();
|
|
19
|
+
* } catch (err) {
|
|
20
|
+
* if (err instanceof NotReadyError) throw err; // re-throw to suspend
|
|
21
|
+
* reportError(err);
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
class NotReadyError extends Error {
|
|
26
|
+
source;
|
|
27
|
+
constructor(r) {
|
|
28
|
+
// Control-flow throw: it happens on every read of a pending source, so in
|
|
29
|
+
// production skip V8's eager stack capture (proportional to stack depth —
|
|
30
|
+
// real cost under SSR) by zeroing the V8-specific stackTraceLimit around
|
|
31
|
+
// super(). Dev keeps the stack for debuggability; non-V8 engines (no
|
|
32
|
+
// stackTraceLimit) take the plain path.
|
|
33
|
+
const o = Error;
|
|
34
|
+
const t = o.stackTraceLimit;
|
|
35
|
+
if (t !== undefined) o.stackTraceLimit = 0;
|
|
36
|
+
super();
|
|
37
|
+
if (t !== undefined) o.stackTraceLimit = t;
|
|
38
|
+
this.source = r;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
class StatusError extends Error {
|
|
43
|
+
source;
|
|
44
|
+
constructor(r, o) {
|
|
45
|
+
super(o instanceof Error ? o.message : String(o), {
|
|
46
|
+
cause: o
|
|
47
|
+
});
|
|
48
|
+
this.source = r;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Return the user's error from an internal status wrapper. */ function unwrapStatusError(r) {
|
|
53
|
+
return r instanceof StatusError ? r.cause : r;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Rejection value of `until(fn, { timeout })` when the predicate does not turn
|
|
58
|
+
* truthy within the window. Inside an `action()`, the rejection is thrown back
|
|
59
|
+
* in at the `yield` point — catchable there, or the action fails and its
|
|
60
|
+
* optimistic state reverts.
|
|
61
|
+
*/ class TimeoutError extends Error {
|
|
62
|
+
constructor(r = "Timed out waiting for condition") {
|
|
63
|
+
super(r);
|
|
64
|
+
this.name = "TimeoutError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class NoOwnerError extends Error {
|
|
69
|
+
constructor() {
|
|
70
|
+
super("");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
class ContextNotFoundError extends Error {
|
|
75
|
+
constructor() {
|
|
76
|
+
super("");
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export { ContextNotFoundError, NoOwnerError, NotReadyError, StatusError, TimeoutError, unwrapStatusError };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { signal, setSignal, read } from "./core.js";
|
|
2
|
+
|
|
3
|
+
import { cleanup } from "./owner.js";
|
|
4
|
+
|
|
5
|
+
import { GlobalQueue } from "./scheduler.js";
|
|
6
|
+
|
|
7
|
+
let externalSourceConfig = null;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Registers a factory that bridges external reactive systems (e.g. MobX, Vue refs)
|
|
11
|
+
* into Solid's tracking graph. Every computation will be wrapped so that the
|
|
12
|
+
* external library can track its own dependencies alongside Solid's.
|
|
13
|
+
*
|
|
14
|
+
* Multiple calls pipe together: each new factory wraps the previous one.
|
|
15
|
+
*
|
|
16
|
+
* @param config.factory receives `(fn, trigger)` — wrap fn execution in external tracking,
|
|
17
|
+
* call trigger when external deps change. Return `{ track, dispose }`.
|
|
18
|
+
* @param config.untrack optional wrapper for `untrack` — disables external tracking too.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // Bridge an external "subscribe / notify" library into Solid's graph.
|
|
23
|
+
* // `factory` wraps every Solid compute so the external library can attach
|
|
24
|
+
* // its own dependency tracker; `trigger` re-runs the compute on external
|
|
25
|
+
* // change. `untrack` mirrors Solid's `untrack()` into the external library
|
|
26
|
+
* // so that reads inside `untrack(...)` don't get tracked twice.
|
|
27
|
+
* enableExternalSource({
|
|
28
|
+
* factory: (compute, trigger) => {
|
|
29
|
+
* const sub = externalLib.subscribe(trigger);
|
|
30
|
+
* return {
|
|
31
|
+
* track: prev => externalLib.run(() => compute(prev)),
|
|
32
|
+
* dispose: () => sub.unsubscribe()
|
|
33
|
+
* };
|
|
34
|
+
* },
|
|
35
|
+
* untrack: fn => externalLib.untracked(fn)
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
// Wires a freshly created computed through the active external-source bridge.
|
|
40
|
+
// Lives here (installed on GlobalQueue while a config is active) rather than
|
|
41
|
+
// inline in core: esbuild cannot literal-track the mutable config binding the
|
|
42
|
+
// way rollup does, so an inline `if (externalSourceConfig)` block ships in
|
|
43
|
+
// every bundle even though only enableExternalSource() can make it reachable.
|
|
44
|
+
function wireExternalSource(e) {
|
|
45
|
+
const n = signal(undefined, {
|
|
46
|
+
equals: false,
|
|
47
|
+
ownedWrite: true
|
|
48
|
+
});
|
|
49
|
+
const r = externalSourceConfig.factory(e.ot, () => {
|
|
50
|
+
setSignal(n, undefined);
|
|
51
|
+
});
|
|
52
|
+
cleanup(() => r.dispose());
|
|
53
|
+
e.ot = e => {
|
|
54
|
+
read(n);
|
|
55
|
+
return r.track(e);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function externalUntrack(e) {
|
|
60
|
+
return externalSourceConfig.untrack(e);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The hooks mirror the config's liveness exactly (installed on enable,
|
|
64
|
+
// removed on reset) so core's null checks stay equivalent to the old
|
|
65
|
+
// `externalSourceConfig` truthiness checks.
|
|
66
|
+
function syncExternalHooks() {
|
|
67
|
+
GlobalQueue.un = externalSourceConfig ? wireExternalSource : null;
|
|
68
|
+
GlobalQueue.cn = externalSourceConfig ? externalUntrack : null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function enableExternalSource(e) {
|
|
72
|
+
const {factory: n, untrack: r = e => e()} = e;
|
|
73
|
+
if (externalSourceConfig) {
|
|
74
|
+
const {factory: e, untrack: o} = externalSourceConfig;
|
|
75
|
+
externalSourceConfig = {
|
|
76
|
+
factory: (r, o) => {
|
|
77
|
+
const t = e(r, o);
|
|
78
|
+
const a = n(e => t.track(e), o);
|
|
79
|
+
return {
|
|
80
|
+
track: e => a.track(e),
|
|
81
|
+
dispose() {
|
|
82
|
+
a.dispose();
|
|
83
|
+
t.dispose();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
},
|
|
87
|
+
untrack: e => o(() => r(e))
|
|
88
|
+
};
|
|
89
|
+
} else {
|
|
90
|
+
externalSourceConfig = {
|
|
91
|
+
factory: n,
|
|
92
|
+
untrack: r
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
syncExternalHooks();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export { enableExternalSource, externalSourceConfig };
|