@solidjs/signals 2.0.0-rc.1 → 2.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dev-shared.js +7138 -0
- package/dist/dev.attribution.js +3307 -0
- package/dist/dev.js +5691 -4491
- package/dist/observe/affects.js +129 -0
- package/dist/observe/attribution.js +7 -0
- package/dist/observe/boundaries.js +793 -0
- package/dist/observe/core/action.js +177 -0
- package/dist/observe/core/async.js +849 -0
- package/dist/observe/core/attribution-costs.js +66 -0
- package/dist/observe/core/attribution-feedback.js +280 -0
- package/dist/observe/core/attribution-hooks.js +83 -0
- package/dist/observe/core/attribution-queries.js +43 -0
- package/dist/observe/core/attribution.js +2904 -0
- package/dist/observe/core/constants.js +283 -0
- package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
- package/dist/observe/core/core.js +1999 -0
- package/dist/observe/core/dev.js +343 -0
- package/dist/observe/core/effect.js +200 -0
- package/dist/observe/core/error-hooks.js +71 -0
- package/dist/observe/core/error.js +80 -0
- package/dist/observe/core/external.js +98 -0
- package/dist/observe/core/graph.js +155 -0
- package/dist/observe/core/heap.js +147 -0
- package/dist/observe/core/invariants.js +45 -0
- package/dist/observe/core/lanes.js +205 -0
- package/dist/observe/core/optimistic.js +627 -0
- package/dist/observe/core/owner.js +353 -0
- package/dist/observe/core/scheduler.js +1547 -0
- package/dist/observe/core/verdict.js +674 -0
- package/dist/observe/index.js +59 -0
- package/dist/observe/map.js +484 -0
- package/dist/observe/signals.js +731 -0
- package/dist/observe/store/index.js +44 -0
- package/dist/observe/store/next/optimistic.js +717 -0
- package/dist/observe/store/next/projection.js +266 -0
- package/dist/observe/store/next/reconcile.js +375 -0
- package/dist/observe/store/next/store.js +2480 -0
- package/dist/observe/store/next/target.js +51 -0
- package/dist/observe/store/store.js +331 -0
- package/dist/observe/store/storePath.js +103 -0
- package/dist/observe/store/utils.js +1070 -0
- package/dist/prod/affects.js +10 -9
- package/dist/prod/attribution.js +45 -0
- package/dist/prod/boundaries.js +388 -178
- package/dist/prod/core/action.js +65 -37
- package/dist/prod/core/async.js +378 -163
- package/dist/prod/core/attribution-hooks.js +3 -0
- package/dist/prod/core/constants.js +186 -1
- package/dist/prod/core/context.js +10 -16
- package/dist/prod/core/core.js +1546 -416
- package/dist/prod/core/dev.js +18 -1
- package/dist/prod/core/effect.js +119 -79
- package/dist/prod/core/error-hooks.js +71 -0
- package/dist/prod/core/error.js +13 -1
- package/dist/prod/core/external.js +4 -4
- package/dist/prod/core/graph.js +105 -54
- package/dist/prod/core/heap.js +72 -65
- package/dist/prod/core/invariants.js +3 -2
- package/dist/prod/core/lanes.js +117 -52
- package/dist/prod/core/optimistic.js +458 -104
- package/dist/prod/core/owner.js +131 -84
- package/dist/prod/core/scheduler.js +998 -241
- package/dist/prod/core/verdict.js +417 -112
- package/dist/prod/index.js +20 -8
- package/dist/prod/map.js +312 -151
- package/dist/prod/signals.js +363 -32
- package/dist/prod/store/index.js +2 -0
- package/dist/prod/store/next/optimistic.js +530 -197
- package/dist/prod/store/next/projection.js +142 -57
- package/dist/prod/store/next/reconcile.js +149 -103
- package/dist/prod/store/next/store.js +1470 -346
- package/dist/prod/store/next/target.js +40 -9
- package/dist/prod/store/store.js +23 -19
- package/dist/prod/store/utils.js +997 -130
- package/dist/types/attribution.d.ts +19 -0
- package/dist/types/attribution.prod.d.ts +22 -0
- package/dist/types/boundaries.d.ts +78 -5
- package/dist/types/core/action.d.ts +12 -5
- package/dist/types/core/async.d.ts +3 -1
- package/dist/types/core/attribution-costs.d.ts +35 -0
- package/dist/types/core/attribution-feedback.d.ts +133 -0
- package/dist/types/core/attribution-hooks.d.ts +304 -0
- package/dist/types/core/attribution-queries.d.ts +24 -0
- package/dist/types/core/attribution.d.ts +892 -0
- package/dist/types/core/constants.d.ts +179 -0
- package/dist/types/core/core.d.ts +299 -25
- package/dist/types/core/dev.d.ts +421 -8
- package/dist/types/core/effect.d.ts +8 -1
- package/dist/types/core/error-hooks.d.ts +71 -0
- package/dist/types/core/error.d.ts +9 -0
- package/dist/types/core/graph.d.ts +23 -0
- package/dist/types/core/heap.d.ts +5 -3
- package/dist/types/core/index.d.ts +6 -3
- package/dist/types/core/invariants.d.ts +5 -1
- package/dist/types/core/lanes.d.ts +51 -19
- package/dist/types/core/owner.d.ts +15 -3
- package/dist/types/core/scheduler.d.ts +248 -1
- package/dist/types/core/types.d.ts +124 -41
- package/dist/types/index.d.ts +18 -5
- package/dist/types/map.d.ts +2 -0
- package/dist/types/signals.d.ts +145 -13
- package/dist/types/store/index.d.ts +7 -6
- package/dist/types/store/next/optimistic.d.ts +18 -13
- package/dist/types/store/next/projection.d.ts +5 -2
- package/dist/types/store/next/reconcile.d.ts +7 -0
- package/dist/types/store/next/store.d.ts +83 -11
- package/dist/types/store/next/target.d.ts +108 -11
- package/dist/types/store/store.d.ts +20 -11
- package/dist/types/store/utils.d.ts +188 -0
- package/package.json +31 -26
- package/dist/node.cjs +0 -8137
- package/dist/types/store/optimistic.d.ts +0 -45
- package/dist/types/store/projection.d.ts +0 -70
- package/dist/types/store/reconcile.d.ts +0 -46
- package/dist/types-cjs/affects.d.cts +0 -47
- package/dist/types-cjs/boundaries.d.cts +0 -175
- package/dist/types-cjs/core/action.d.cts +0 -64
- package/dist/types-cjs/core/async.d.cts +0 -21
- package/dist/types-cjs/core/constants.d.cts +0 -71
- package/dist/types-cjs/core/core.d.cts +0 -156
- package/dist/types-cjs/core/dev.d.cts +0 -64
- package/dist/types-cjs/core/effect.d.cts +0 -30
- package/dist/types-cjs/core/error.d.cts +0 -47
- package/dist/types-cjs/core/external.d.cts +0 -15
- package/dist/types-cjs/core/graph.d.cts +0 -5
- package/dist/types-cjs/core/heap.d.cts +0 -22
- package/dist/types-cjs/core/index.d.cts +0 -13
- package/dist/types-cjs/core/invariants.d.cts +0 -59
- package/dist/types-cjs/core/lanes.d.cts +0 -56
- package/dist/types-cjs/core/optimistic.d.cts +0 -6
- package/dist/types-cjs/core/owner.d.cts +0 -124
- package/dist/types-cjs/core/scheduler.d.cts +0 -172
- package/dist/types-cjs/core/types.d.cts +0 -148
- package/dist/types-cjs/core/verdict.d.cts +0 -2
- package/dist/types-cjs/index.d.cts +0 -10
- package/dist/types-cjs/map.d.cts +0 -69
- package/dist/types-cjs/package.json +0 -3
- package/dist/types-cjs/signals.d.cts +0 -624
- package/dist/types-cjs/store/index.d.cts +0 -19
- package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
- package/dist/types-cjs/store/next/projection.d.cts +0 -24
- package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
- package/dist/types-cjs/store/next/store.d.cts +0 -71
- package/dist/types-cjs/store/next/target.d.cts +0 -99
- package/dist/types-cjs/store/optimistic.d.cts +0 -45
- package/dist/types-cjs/store/projection.d.cts +0 -70
- package/dist/types-cjs/store/reconcile.d.cts +0 -46
- package/dist/types-cjs/store/store.d.cts +0 -138
- package/dist/types-cjs/store/storePath.d.cts +0 -58
- package/dist/types-cjs/store/utils.d.cts +0 -74
package/dist/prod/core/dev.js
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
import "./core.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Registers the console footer appended to the first console report of
|
|
5
|
+
* each diagnostic code — a discovery pointer to deeper guidance. Reported
|
|
6
|
+
* events carry it as trailing lines of the same console entry; events that
|
|
7
|
+
* surface as a thrown error instead get it as a follow-up line. Returning
|
|
8
|
+
* undefined for an event suppresses the footer. Passing undefined
|
|
9
|
+
* unregisters and resets the once-per-code memory.
|
|
10
|
+
*
|
|
11
|
+
* @internal A seam for `solid-js`, which owns the repair skill the footer
|
|
12
|
+
* names and installs it from both of its entries; not part of `DEV`. No-op
|
|
13
|
+
* outside dev builds, where nothing reports to the console.
|
|
14
|
+
*/ function setConsoleFooter(o) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
1
18
|
const DEV = undefined;
|
|
2
19
|
|
|
3
|
-
export { DEV };
|
|
20
|
+
export { DEV, setConsoleFooter };
|
package/dist/prod/core/effect.js
CHANGED
|
@@ -1,29 +1,36 @@
|
|
|
1
|
-
import { REACTIVE_DISPOSED, STATUS_ERROR, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED,
|
|
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
|
-
import { createEffectNode, recompute, computed, staleValues } from "./core.js";
|
|
3
|
+
import { setEffectStatusNotify, ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
|
|
4
4
|
|
|
5
5
|
import { unwrapStatusError, StatusError } from "./error.js";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { trimStaleDeps } from "./graph.js";
|
|
8
|
+
|
|
9
|
+
import { enqueueSub } from "./heap.js";
|
|
10
|
+
|
|
11
|
+
import { GlobalQueue, currentTransition, activeTransition, haltReactivity, schedule } from "./scheduler.js";
|
|
8
12
|
|
|
9
13
|
/**
|
|
10
14
|
* Effects are the leaf nodes of our reactive graph. When their sources change, they are
|
|
11
15
|
* automatically added to the queue of effects to re-execute, which will cause them to fetch their
|
|
12
16
|
* sources and recompute
|
|
13
|
-
*/ function effect(t,
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
recompute(
|
|
17
|
-
|
|
17
|
+
*/ function effect(t, e, E, r) {
|
|
18
|
+
const n = !!r?.user;
|
|
19
|
+
const i = createEffectNode(t, e, E, n ? EFFECT_USER : EFFECT_RENDER, r);
|
|
20
|
+
recompute(i, true);
|
|
21
|
+
// A first pass that derived from a live transaction's staged world was
|
|
22
|
+
// staged into that transaction (recompute: born held); the transaction's
|
|
23
|
+
// commit replays this effect. Its first run is not this creation's (A29).
|
|
24
|
+
!r?.defer && i._e === NOT_PENDING && (i.je === EFFECT_USER || r?.schedule ? i.T.enqueue(i.je, runEffect.bind(null, i)) : runEffect(i, LANE_RUN));
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
function notifyEffectStatus(t,
|
|
27
|
+
function notifyEffectStatus(t, e) {
|
|
21
28
|
// Use passed values if provided, otherwise read from node
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
this.
|
|
26
|
-
if (this.
|
|
29
|
+
const E = t !== undefined ? t : this.h;
|
|
30
|
+
const r = e !== undefined ? e : this.o?._;
|
|
31
|
+
if (E & STATUS_ERROR) {
|
|
32
|
+
this.T.notify(this, STATUS_PENDING, 0);
|
|
33
|
+
if (this.je === EFFECT_USER) {
|
|
27
34
|
// The error handler is the error arm of the effect phase (#2840 ruling):
|
|
28
35
|
// queue it like the effect function. It runs in the same imperative,
|
|
29
36
|
// writable scope, throws escalate the same way, and a held transition
|
|
@@ -33,23 +40,43 @@ function notifyEffectStatus(t, E) {
|
|
|
33
40
|
// phase takes the success arm instead. Blocked forwards (explicit
|
|
34
41
|
// `status` arg without node-state writes) don't queue: the status
|
|
35
42
|
// re-propagates unblocked at commit.
|
|
36
|
-
if (this.
|
|
37
|
-
this.
|
|
38
|
-
this.
|
|
43
|
+
if (this.h & STATUS_ERROR) {
|
|
44
|
+
this.Xe = true;
|
|
45
|
+
this.T.enqueue(this.je, this.An ??= runEffect.bind(null, this));
|
|
39
46
|
}
|
|
40
47
|
return;
|
|
41
48
|
}
|
|
42
|
-
if (!this.
|
|
43
|
-
haltReactivity(unwrapStatusError(
|
|
44
|
-
throw
|
|
49
|
+
if (!this.T.notify(this, STATUS_ERROR, STATUS_ERROR)) {
|
|
50
|
+
haltReactivity(unwrapStatusError(r));
|
|
51
|
+
throw r;
|
|
45
52
|
}
|
|
46
|
-
} else if (this.
|
|
47
|
-
this.
|
|
53
|
+
} else if (this.je === EFFECT_RENDER) {
|
|
54
|
+
this.T.notify(this, STATUS_PENDING | STATUS_ERROR, E, r);
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
|
|
51
|
-
function runEffect(t) {
|
|
52
|
-
if (!t.
|
|
58
|
+
function runEffect(t, e) {
|
|
59
|
+
if (!t.Xe || t.oe & REACTIVE_DISPOSED) return;
|
|
60
|
+
// Ownership (#3319): a value computed under a transaction is applied by that
|
|
61
|
+
// transaction's commit. The ordinary effect phase runs with a transaction
|
|
62
|
+
// active only when the flush's finalize ENTERED one (every other path parks
|
|
63
|
+
// or settles first): leave a run owned by a still-held transaction queued —
|
|
64
|
+
// `_modified` stays set — and the next gate stashes it with the owner.
|
|
65
|
+
// Mainline-owned runs (null) apply now. Lanes are exempt by design (they
|
|
66
|
+
// apply their own effects ahead of their transaction — the optimistic view)
|
|
67
|
+
// and mark their runs with LANE_RUN.
|
|
68
|
+
|
|
69
|
+
// Lane exemption has one exception (#3331): a lane runner for an effect that
|
|
70
|
+
// no longer rides a lane — its optimistic source was superseded, so the lane
|
|
71
|
+
// has no optimistic view left to apply, and the value this effect now
|
|
72
|
+
// carries (or will, once its plain recompute lands) belongs to the still-held
|
|
73
|
+
// transaction. Hand the run to the regular queue, where the transaction's
|
|
74
|
+
// gate stashes it with the owner. Lane-less runners with no live owner
|
|
75
|
+
// (reverts, wake-only lanes) apply now.
|
|
76
|
+
if (t.pn !== null && !currentTransition(t.pn).Rn && (e & LANE_RUN ? !t.o?.me : activeTransition !== null)) {
|
|
77
|
+
t.T.enqueue(t.je, t.An);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
53
80
|
// Error arm (#2840), user effects only: a compute-phase error that is still
|
|
54
81
|
// the node's settled state at effect time runs the bundle's error handler in
|
|
55
82
|
// this same imperative, writable scope. Unwrap the StatusError used for
|
|
@@ -60,86 +87,99 @@ function runEffect(t) {
|
|
|
60
87
|
// Render effects bypass: their errors route to boundaries synchronously in
|
|
61
88
|
// notifyEffectStatus, and a runner queued by an earlier valueChanged in the
|
|
62
89
|
// same flush must not be hijacked by a later-arriving error status.
|
|
63
|
-
if (t.
|
|
64
|
-
const
|
|
65
|
-
t.
|
|
66
|
-
t.
|
|
90
|
+
if (t.h & STATUS_ERROR && t.je === EFFECT_USER) {
|
|
91
|
+
const e = unwrapStatusError(t.o?._);
|
|
92
|
+
t.xn = t.ce;
|
|
93
|
+
t.Xe = false;
|
|
67
94
|
try {
|
|
68
|
-
t.
|
|
69
|
-
const
|
|
70
|
-
t.
|
|
71
|
-
|
|
72
|
-
}) : console.error(
|
|
73
|
-
} catch (
|
|
74
|
-
if (!t.
|
|
75
|
-
haltReactivity(
|
|
76
|
-
throw
|
|
95
|
+
t.Mn ? t.Mn(e, () => {
|
|
96
|
+
const e = t.wn;
|
|
97
|
+
t.wn = undefined;
|
|
98
|
+
e?.();
|
|
99
|
+
}) : console.error(e);
|
|
100
|
+
} catch (e) {
|
|
101
|
+
if (!t.T.notify(t, STATUS_ERROR, STATUS_ERROR)) {
|
|
102
|
+
haltReactivity(e);
|
|
103
|
+
throw e;
|
|
77
104
|
}
|
|
78
105
|
}
|
|
79
106
|
return;
|
|
80
107
|
}
|
|
81
|
-
|
|
82
|
-
|
|
108
|
+
// Captured before the callback: its own throw errors the node below, but
|
|
109
|
+
// the compute pass that produced `_value` was clean, so its tail still goes.
|
|
110
|
+
const E = t.o?._ == null;
|
|
111
|
+
const r = t.wn;
|
|
112
|
+
t.wn = undefined;
|
|
83
113
|
try {
|
|
84
|
-
|
|
85
|
-
const e = t.
|
|
114
|
+
r?.();
|
|
115
|
+
const e = t.Qn(t.ce, t.xn);
|
|
86
116
|
if (false && e !== undefined && typeof e !== "function") ;
|
|
87
117
|
// The final cleanup is invoked by disposeChildren at true disposal.
|
|
88
|
-
t.
|
|
89
|
-
} catch (
|
|
90
|
-
t._ = new StatusError(t,
|
|
91
|
-
t.
|
|
92
|
-
if (!t.
|
|
93
|
-
haltReactivity(
|
|
94
|
-
throw
|
|
118
|
+
t.wn = e;
|
|
119
|
+
} catch (e) {
|
|
120
|
+
ext(t)._ = new StatusError(t, e);
|
|
121
|
+
t.h |= STATUS_ERROR;
|
|
122
|
+
if (!t.T.notify(t, STATUS_ERROR, STATUS_ERROR)) {
|
|
123
|
+
haltReactivity(e);
|
|
124
|
+
throw e;
|
|
95
125
|
}
|
|
96
126
|
} finally {
|
|
97
|
-
t.
|
|
98
|
-
t.
|
|
127
|
+
t.xn = t.ce;
|
|
128
|
+
t.Xe = false;
|
|
129
|
+
// The run applied: this is the frame now, so the dependency tail the
|
|
130
|
+
// compute pass left linked goes (A30, #3438 — `recompute` defers an
|
|
131
|
+
// effect's trim while a run is owed; the twin of `commitPendingNode`'s
|
|
132
|
+
// trim for a staged pass). An errored compute kept its full list with
|
|
133
|
+
// `_depsTail` marking where it stopped; leave it, as the commit does.
|
|
134
|
+
if (E) trimStaleDeps(t);
|
|
99
135
|
}
|
|
100
136
|
}
|
|
101
137
|
|
|
102
|
-
GlobalQueue.
|
|
138
|
+
GlobalQueue.Cn = runEffect;
|
|
103
139
|
|
|
104
140
|
/**
|
|
105
141
|
* Internal tracked effect - bypasses heap, goes directly to effect queue.
|
|
106
142
|
* Runs as a leaf owner: child primitives and onCleanup are forbidden (false throws).
|
|
107
143
|
* Uses stale reads.
|
|
108
|
-
*/ function trackedEffect(t,
|
|
144
|
+
*/ function trackedEffect(t, e) {
|
|
109
145
|
const run = () => {
|
|
110
|
-
|
|
146
|
+
// `_modified` is NOT redundant with the heap: the heap dedups within a
|
|
147
|
+
// pass, but a held transition's passes each enqueue `_run` into the same
|
|
148
|
+
// user queue, and this gate is what collapses them into one run at commit.
|
|
149
|
+
if (!E.Xe || E.oe & REACTIVE_DISPOSED) return;
|
|
111
150
|
try {
|
|
112
|
-
|
|
113
|
-
recompute(
|
|
151
|
+
E.Xe = false;
|
|
152
|
+
recompute(E);
|
|
114
153
|
} finally {}
|
|
115
154
|
};
|
|
116
|
-
const
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
155
|
+
const E = computed(() => {
|
|
156
|
+
const e = E.wn;
|
|
157
|
+
E.wn = undefined;
|
|
158
|
+
e?.();
|
|
159
|
+
const r = staleValues(t);
|
|
160
|
+
E.wn = r;
|
|
122
161
|
}, {
|
|
123
|
-
...
|
|
162
|
+
...e,
|
|
124
163
|
lazy: true
|
|
125
164
|
});
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
e.ht = run;
|
|
142
|
-
e.C.enqueue(EFFECT_USER, run);
|
|
165
|
+
E.wn = undefined;
|
|
166
|
+
E.C = E.C & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
|
|
167
|
+
E.Xe = true;
|
|
168
|
+
E.je = EFFECT_TRACKED;
|
|
169
|
+
// Status dispatch rides the SHARED notifier (statusNotifierOf keys off
|
|
170
|
+
// _type): its error arm is behavior-identical to the closure that used to
|
|
171
|
+
// live here, without the per-node NodeExtension allocation.
|
|
172
|
+
E.$e = run;
|
|
173
|
+
// The first run rides the heap like every wake (GlobalQueue._update), so a
|
|
174
|
+
// tracked effect created inside a render-effect callback runs after that
|
|
175
|
+
// pass's staged writes commit, not before.
|
|
176
|
+
enqueueSub(E);
|
|
177
|
+
schedule();
|
|
143
178
|
}
|
|
144
179
|
|
|
180
|
+
// Install the shared effect status notifier (statusNotifierOf serves it to
|
|
181
|
+
// every effect node) — module-scope: any bundle that creates effects
|
|
182
|
+
// evaluates this module.
|
|
183
|
+
setEffectStatusNotify(notifyEffectStatus);
|
|
184
|
+
|
|
145
185
|
export { effect, trackedEffect };
|
|
@@ -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 };
|
package/dist/prod/core/error.js
CHANGED
|
@@ -53,6 +53,18 @@ class StatusError extends Error {
|
|
|
53
53
|
return r instanceof StatusError ? r.cause : r;
|
|
54
54
|
}
|
|
55
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
|
+
|
|
56
68
|
class NoOwnerError extends Error {
|
|
57
69
|
constructor() {
|
|
58
70
|
super("");
|
|
@@ -65,4 +77,4 @@ class ContextNotFoundError extends Error {
|
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
79
|
|
|
68
|
-
export { ContextNotFoundError, NoOwnerError, NotReadyError, StatusError, unwrapStatusError };
|
|
80
|
+
export { ContextNotFoundError, NoOwnerError, NotReadyError, StatusError, TimeoutError, unwrapStatusError };
|
|
@@ -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.he, () => {
|
|
50
50
|
setSignal(n, undefined);
|
|
51
51
|
});
|
|
52
52
|
cleanup(() => r.dispose());
|
|
53
|
-
e.
|
|
53
|
+
e.he = 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.Zn = externalSourceConfig ? wireExternalSource : null;
|
|
68
|
+
GlobalQueue.jn = externalSourceConfig ? externalUntrack : null;
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
function enableExternalSource(e) {
|
package/dist/prod/core/graph.js
CHANGED
|
@@ -1,78 +1,127 @@
|
|
|
1
|
-
import { CONFIG_AUTO_DISPOSE, REACTIVE_ZOMBIE,
|
|
1
|
+
import { CONFIG_AUTO_DISPOSE, STATUS_PENDING, REACTIVE_DISPOSED, REACTIVE_ZOMBIE, CONFIG_SLOT_NODE, REACTIVE_RECOMPUTING_DEPS } from "./constants.js";
|
|
2
|
+
|
|
3
|
+
import { slotUnobservedHook } from "./core.js";
|
|
2
4
|
|
|
3
5
|
import { deleteFromHeap, queueFor } from "./heap.js";
|
|
4
6
|
|
|
5
7
|
import { disposeChildren } from "./owner.js";
|
|
6
8
|
|
|
7
|
-
import "./scheduler.js";
|
|
9
|
+
import { bumpNotifyEpoch } from "./scheduler.js";
|
|
8
10
|
|
|
9
11
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L100
|
|
10
|
-
function unlinkSubs(
|
|
11
|
-
const n =
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const s =
|
|
15
|
-
if (
|
|
16
|
-
if (s !== null) s.
|
|
17
|
-
n.
|
|
18
|
-
if (
|
|
19
|
-
|
|
12
|
+
function unlinkSubs(e) {
|
|
13
|
+
const n = e.Oe;
|
|
14
|
+
const l = e.Ne;
|
|
15
|
+
const o = e.Ae;
|
|
16
|
+
const s = e.el;
|
|
17
|
+
if (o !== null) o.el = s; else n.mn = s;
|
|
18
|
+
if (s !== null) s.Ae = o; else {
|
|
19
|
+
n.u = o;
|
|
20
|
+
if (o === null) {
|
|
21
|
+
// Slot nodes (store leaves) dispatch to the ONE shared hook — no
|
|
22
|
+
// per-node unobserved closure, no NodeExtension to hold it.
|
|
23
|
+
if (n.C & CONFIG_SLOT_NODE) slotUnobservedHook(n); else n.o?.Hn?.();
|
|
20
24
|
// No more subscribers; only tear down if CONFIG_AUTO_DISPOSE is set.
|
|
21
25
|
// A pending node is exempt: its in-flight async work (or the
|
|
22
26
|
// transition holding it) is an observer — tearing down would orphan
|
|
23
27
|
// the work and re-execute it on the next read. The settle path runs
|
|
24
28
|
// this same last-one-out check when that observer releases (the
|
|
25
|
-
// untracked-read
|
|
26
|
-
const
|
|
27
|
-
|
|
29
|
+
// untracked-read dormancy sweep guards on pending identically).
|
|
30
|
+
const e = n;
|
|
31
|
+
e.he && e.C & CONFIG_AUTO_DISPOSE && !(e.oe & REACTIVE_ZOMBIE) && !(e.h & STATUS_PENDING) && unobserved(e);
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
|
-
return
|
|
34
|
+
return l;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
|
-
function trimStaleDeps(
|
|
34
|
-
const n =
|
|
35
|
-
let
|
|
36
|
-
if (
|
|
37
|
+
function trimStaleDeps(e) {
|
|
38
|
+
const n = e.Nn;
|
|
39
|
+
let l = n !== null ? n.Ne : e.Ie;
|
|
40
|
+
if (l !== null) {
|
|
37
41
|
do {
|
|
38
|
-
|
|
39
|
-
} while (
|
|
40
|
-
if (n !== null) n.
|
|
42
|
+
l = unlinkSubs(l);
|
|
43
|
+
} while (l !== null);
|
|
44
|
+
if (n !== null) n.Ne = null; else e.Ie = null;
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
// Shared by unobserved() and the disposeChildren child loop. The truthy guard
|
|
49
|
+
// (not `!== null`) matters: plain Owners in a child chain have no _deps field,
|
|
50
|
+
// and skipping early also avoids adding one (hidden-class churn) via the
|
|
51
|
+
// null-out below.
|
|
52
|
+
function clearDeps(e) {
|
|
53
|
+
let n = e.Ie;
|
|
54
|
+
if (!n) return;
|
|
55
|
+
do {
|
|
48
56
|
n = unlinkSubs(n);
|
|
57
|
+
} while (n !== null);
|
|
58
|
+
e.Ie = null;
|
|
59
|
+
e.Nn = null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function unobserved(e) {
|
|
63
|
+
deleteFromHeap(e, queueFor(e));
|
|
64
|
+
clearDeps(e);
|
|
65
|
+
disposeChildren(e, true);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Deferred dormancy for never-observed auto-dispose computeds (#3078).
|
|
70
|
+
*
|
|
71
|
+
* An untracked top-level read of a subscriber-less observation-lifecycle memo
|
|
72
|
+
* used to call unobserved() inline at the end of read(). That kept the leak
|
|
73
|
+
* closed (the compute links the memo into its deps' sub lists — without a
|
|
74
|
+
* teardown point a never-observed memo is retained by its sources forever;
|
|
75
|
+
* upstream alien-signals has exactly this retention), but it made reads
|
|
76
|
+
* destructive: each read disposed the node, the next read revived it with a
|
|
77
|
+
* full recompute in whatever ambient transition/lane context happened to be
|
|
78
|
+
* current, so consecutive reads could return different answers with no write
|
|
79
|
+
* in between.
|
|
80
|
+
*
|
|
81
|
+
* Instead, reads queue the node here and the scheduler sweeps at the top of
|
|
82
|
+
* the next flush (before runHeap, so a same-tick dirtying is reclaimed
|
|
83
|
+
* instead of recomputed). Reads become idempotent within a tick (the node
|
|
84
|
+
* stays alive and serves its cache, uniform with observed memos) while
|
|
85
|
+
* reclamation still happens within one microtask — the enqueue site arms
|
|
86
|
+
* schedule(), so a flush is guaranteed even when no other work is queued.
|
|
87
|
+
*/ const dormantNodes = new Set;
|
|
88
|
+
|
|
89
|
+
function sweepDormant() {
|
|
90
|
+
if (dormantNodes.size === 0) return;
|
|
91
|
+
for (const e of dormantNodes) {
|
|
92
|
+
// Re-validate at sweep time: the node may have gained a subscriber (its
|
|
93
|
+
// lifecycle is the unlinkSubs cascade now), gone pending (in-flight async
|
|
94
|
+
// is an observer; the settle path re-runs last-one-out), lost its
|
|
95
|
+
// AUTO_DISPOSE bit (owner teardown strips it, #3024), or already been
|
|
96
|
+
// torn down.
|
|
97
|
+
if (!e.u && e.C & CONFIG_AUTO_DISPOSE && !(e.h & STATUS_PENDING) && !(e.oe & (REACTIVE_DISPOSED | REACTIVE_ZOMBIE))) {
|
|
98
|
+
unobserved(e);
|
|
99
|
+
}
|
|
49
100
|
}
|
|
50
|
-
|
|
51
|
-
l.Ye = null;
|
|
52
|
-
disposeChildren(l, true);
|
|
101
|
+
dormantNodes.clear();
|
|
53
102
|
}
|
|
54
103
|
|
|
55
104
|
// https://github.com/stackblitz/alien-signals/blob/v2.0.3/src/system.ts#L52
|
|
56
|
-
function link(
|
|
105
|
+
function link(e, n, l = false) {
|
|
57
106
|
// Repeat touches within one pass AND-combine `_pendingObserver`: a probe
|
|
58
107
|
// read (`isPending(() => x())`) beside a value read of the same dep must
|
|
59
108
|
// not relabel the value dependency as probe-only — the value read is what
|
|
60
109
|
// real-error propagation and affects() coverage key off, regardless of
|
|
61
110
|
// read order within the computation.
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
|
|
111
|
+
const o = n.Nn;
|
|
112
|
+
if (o !== null && o.Oe === e) {
|
|
113
|
+
o.ze &&= l;
|
|
65
114
|
return;
|
|
66
115
|
}
|
|
67
116
|
let s = null;
|
|
68
|
-
const t = n.
|
|
117
|
+
const t = n.oe & REACTIVE_RECOMPUTING_DEPS;
|
|
69
118
|
if (t) {
|
|
70
|
-
s =
|
|
71
|
-
if (s !== null && s.
|
|
72
|
-
s.
|
|
73
|
-
n.
|
|
119
|
+
s = o !== null ? o.Ne : n.Ie;
|
|
120
|
+
if (s !== null && s.Oe === e) {
|
|
121
|
+
s.Be = n.Ye;
|
|
122
|
+
n.Nn = s;
|
|
74
123
|
// First touch of this pass: the previous pass's label is stale.
|
|
75
|
-
s.
|
|
124
|
+
s.ze = l;
|
|
76
125
|
return;
|
|
77
126
|
}
|
|
78
127
|
}
|
|
@@ -81,24 +130,26 @@ function link(l, n, e = false) {
|
|
|
81
130
|
// [deps.._depsTail] prefix — the O(1) equivalent of scanning the dep list
|
|
82
131
|
// (the old alien-signals `isValidLink` walk, O(n²) when a computation
|
|
83
132
|
// re-reads earlier deps non-consecutively, e.g. store leaf reads).
|
|
84
|
-
const
|
|
85
|
-
if (
|
|
133
|
+
const r = e.mn;
|
|
134
|
+
if (r !== null && r.ge === n && (!t || r.Be === n.Ye)) {
|
|
86
135
|
// Gen-matched during a recompute = repeat touch this pass (AND); outside
|
|
87
136
|
// a recompute there is no pass boundary, so the latest read labels it.
|
|
88
|
-
if (t)
|
|
137
|
+
if (t) r.ze &&= l; else r.ze = l;
|
|
89
138
|
return;
|
|
90
139
|
}
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
140
|
+
const u = n.Nn = e.mn = {
|
|
141
|
+
Oe: e,
|
|
142
|
+
ge: n,
|
|
143
|
+
Ne: s,
|
|
144
|
+
el: r,
|
|
145
|
+
Ae: null,
|
|
146
|
+
Be: n.Ye,
|
|
147
|
+
ze: l
|
|
99
148
|
};
|
|
100
|
-
if (
|
|
101
|
-
if (
|
|
149
|
+
if (o !== null) o.Ne = u; else n.Ie = u;
|
|
150
|
+
if (r !== null) r.Ae = u; else e.u = u;
|
|
151
|
+
// New subscriber edge: staged-rewrite skips (§12d) must not miss it.
|
|
152
|
+
bumpNotifyEpoch();
|
|
102
153
|
}
|
|
103
154
|
|
|
104
|
-
export { link, trimStaleDeps, unlinkSubs, unobserved };
|
|
155
|
+
export { clearDeps, dormantNodes, link, sweepDormant, trimStaleDeps, unlinkSubs, unobserved };
|