@solidjs/signals 2.0.0-rc.7 → 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.
Files changed (134) hide show
  1. package/dist/dev-shared.js +6357 -0
  2. package/dist/dev.attribution.js +2485 -0
  3. package/dist/dev.js +2851 -7027
  4. package/dist/observe/affects.js +129 -0
  5. package/dist/observe/attribution.js +7 -0
  6. package/dist/observe/boundaries.js +641 -0
  7. package/dist/observe/core/action.js +177 -0
  8. package/dist/observe/core/async.js +846 -0
  9. package/dist/observe/core/attribution-costs.js +66 -0
  10. package/dist/observe/core/attribution-feedback.js +282 -0
  11. package/dist/observe/core/attribution-hooks.js +82 -0
  12. package/dist/observe/core/attribution-queries.js +28 -0
  13. package/dist/observe/core/attribution.js +2095 -0
  14. package/dist/observe/core/constants.js +248 -0
  15. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  16. package/dist/observe/core/core.js +1789 -0
  17. package/dist/observe/core/dev.js +293 -0
  18. package/dist/observe/core/effect.js +195 -0
  19. package/dist/observe/core/error-hooks.js +71 -0
  20. package/dist/observe/core/error.js +80 -0
  21. package/dist/observe/core/external.js +98 -0
  22. package/dist/observe/core/graph.js +155 -0
  23. package/dist/observe/core/heap.js +147 -0
  24. package/dist/observe/core/invariants.js +45 -0
  25. package/dist/observe/core/lanes.js +205 -0
  26. package/dist/observe/core/optimistic.js +585 -0
  27. package/dist/observe/core/owner.js +322 -0
  28. package/dist/observe/core/scheduler.js +1428 -0
  29. package/dist/observe/core/verdict.js +669 -0
  30. package/dist/observe/index.js +59 -0
  31. package/dist/observe/map.js +484 -0
  32. package/dist/{types-cjs/signals.d.cts → observe/signals.js} +311 -317
  33. package/dist/observe/store/index.js +40 -0
  34. package/dist/observe/store/next/optimistic.js +660 -0
  35. package/dist/observe/store/next/projection.js +255 -0
  36. package/dist/observe/store/next/reconcile.js +375 -0
  37. package/dist/observe/store/next/store.js +2327 -0
  38. package/dist/observe/store/next/target.js +51 -0
  39. package/dist/observe/store/store.js +325 -0
  40. package/dist/observe/store/storePath.js +103 -0
  41. package/dist/observe/store/utils.js +1023 -0
  42. package/dist/prod/attribution.js +41 -0
  43. package/dist/prod/boundaries.js +128 -76
  44. package/dist/prod/core/action.js +65 -37
  45. package/dist/prod/core/async.js +324 -172
  46. package/dist/prod/core/constants.js +57 -1
  47. package/dist/prod/core/context.js +3 -3
  48. package/dist/prod/core/core.js +1003 -364
  49. package/dist/prod/core/dev.js +17 -1
  50. package/dist/prod/core/effect.js +76 -42
  51. package/dist/prod/core/error-hooks.js +71 -0
  52. package/dist/prod/core/external.js +4 -4
  53. package/dist/prod/core/graph.js +37 -37
  54. package/dist/prod/core/heap.js +61 -56
  55. package/dist/prod/core/lanes.js +107 -63
  56. package/dist/prod/core/optimistic.js +374 -93
  57. package/dist/prod/core/owner.js +62 -46
  58. package/dist/prod/core/scheduler.js +653 -286
  59. package/dist/prod/core/verdict.js +245 -127
  60. package/dist/prod/index.js +15 -5
  61. package/dist/prod/map.js +292 -141
  62. package/dist/prod/signals.js +29 -16
  63. package/dist/prod/store/next/optimistic.js +77 -55
  64. package/dist/prod/store/next/projection.js +31 -20
  65. package/dist/prod/store/next/reconcile.js +87 -84
  66. package/dist/prod/store/next/store.js +718 -401
  67. package/dist/prod/store/next/target.js +32 -10
  68. package/dist/prod/store/store.js +12 -14
  69. package/dist/prod/store/utils.js +950 -130
  70. package/dist/types/attribution.d.ts +20 -0
  71. package/dist/types/attribution.prod.d.ts +22 -0
  72. package/dist/types/boundaries.d.ts +10 -1
  73. package/dist/types/core/action.d.ts +12 -5
  74. package/dist/types/core/async.d.ts +1 -1
  75. package/dist/types/core/attribution-costs.d.ts +35 -0
  76. package/dist/types/core/attribution-feedback.d.ts +133 -0
  77. package/dist/types/core/attribution-hooks.d.ts +147 -9
  78. package/dist/types/core/attribution-queries.d.ts +10 -0
  79. package/dist/types/core/attribution.d.ts +216 -182
  80. package/dist/types/core/constants.d.ts +56 -0
  81. package/dist/types/core/core.d.ts +190 -2
  82. package/dist/types/core/dev.d.ts +246 -28
  83. package/dist/types/core/effect.d.ts +8 -1
  84. package/dist/types/core/error-hooks.d.ts +71 -0
  85. package/dist/types/core/index.d.ts +4 -1
  86. package/dist/types/core/invariants.d.ts +4 -0
  87. package/dist/types/core/lanes.d.ts +39 -5
  88. package/dist/types/core/scheduler.d.ts +153 -0
  89. package/dist/types/core/types.d.ts +32 -9
  90. package/dist/types/index.d.ts +10 -3
  91. package/dist/types/map.d.ts +2 -0
  92. package/dist/types/signals.d.ts +8 -0
  93. package/dist/types/store/index.d.ts +2 -0
  94. package/dist/types/store/next/optimistic.d.ts +1 -1
  95. package/dist/types/store/next/store.d.ts +11 -5
  96. package/dist/types/store/next/target.d.ts +37 -10
  97. package/dist/types/store/utils.d.ts +178 -0
  98. package/package.json +21 -17
  99. package/dist/node.cjs +0 -10541
  100. package/dist/node.dev.cjs +0 -13724
  101. package/dist/types-cjs/affects.d.cts +0 -47
  102. package/dist/types-cjs/boundaries.d.cts +0 -175
  103. package/dist/types-cjs/core/action.d.cts +0 -64
  104. package/dist/types-cjs/core/async.d.cts +0 -23
  105. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -127
  106. package/dist/types-cjs/core/attribution.d.cts +0 -495
  107. package/dist/types-cjs/core/constants.d.cts +0 -159
  108. package/dist/types-cjs/core/core.d.cts +0 -185
  109. package/dist/types-cjs/core/dev.d.cts +0 -136
  110. package/dist/types-cjs/core/effect.d.cts +0 -30
  111. package/dist/types-cjs/core/error.d.cts +0 -56
  112. package/dist/types-cjs/core/external.d.cts +0 -15
  113. package/dist/types-cjs/core/graph.d.cts +0 -28
  114. package/dist/types-cjs/core/heap.d.cts +0 -24
  115. package/dist/types-cjs/core/index.d.cts +0 -13
  116. package/dist/types-cjs/core/invariants.d.cts +0 -59
  117. package/dist/types-cjs/core/lanes.d.cts +0 -54
  118. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  119. package/dist/types-cjs/core/owner.d.cts +0 -124
  120. package/dist/types-cjs/core/scheduler.d.cts +0 -236
  121. package/dist/types-cjs/core/types.d.cts +0 -204
  122. package/dist/types-cjs/core/verdict.d.cts +0 -2
  123. package/dist/types-cjs/index.d.cts +0 -10
  124. package/dist/types-cjs/map.d.cts +0 -69
  125. package/dist/types-cjs/package.json +0 -3
  126. package/dist/types-cjs/store/index.d.cts +0 -18
  127. package/dist/types-cjs/store/next/optimistic.d.cts +0 -25
  128. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  129. package/dist/types-cjs/store/next/reconcile.d.cts +0 -10
  130. package/dist/types-cjs/store/next/store.d.cts +0 -121
  131. package/dist/types-cjs/store/next/target.d.cts +0 -166
  132. package/dist/types-cjs/store/store.d.cts +0 -143
  133. package/dist/types-cjs/store/storePath.d.cts +0 -58
  134. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -0,0 +1,293 @@
1
+ import { currentOrigin, 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
+ currentOrigin: currentOrigin
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
+
93
+ const OBSERVE = {
94
+ diagnostics: diagnostics,
95
+ records: recordsChannel(),
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: {},
101
+ subjectOf(e) {
102
+ return eventSubjects.get(e);
103
+ },
104
+ exclude(e) {
105
+ excludedOwners.add(e);
106
+ hasExclusions = true;
107
+ },
108
+ isExcluded: isExcluded
109
+ };
110
+
111
+ // --- Excluded owners ---------------------------------------------------------------
112
+
113
+ // An observer that lives inside the observed app (an adapter's panel,
114
+ // devtools) marks its root; both channels check the subject's owner chain —
115
+ // the same walk `ownerPath` already makes — and stay silent under it. The
116
+ // flag short-circuits the walk for the common case of no exclusions.
117
+ const excludedOwners = new WeakSet;
118
+
119
+ let hasExclusions = false;
120
+
121
+ /** Events built for an excluded subject: never delivered, never reported. */ const suppressedEvents = new WeakSet;
122
+
123
+ function isExcluded(e) {
124
+ if (!hasExclusions || !e) return false;
125
+ let t = "_parent" in e ? e : e.nt ?? null;
126
+ for (;t !== null; t = t._parent) if (excludedOwners.has(t)) return true;
127
+ return false;
128
+ }
129
+
130
+ /** For engines that cache the verdict per node: is anything excluded at all? */ function anyExcluded() {
131
+ return hasExclusions;
132
+ }
133
+
134
+ /** Was `entry` built for an excluded subject? Once-per-key reporters must not spend their slot on it. */ function isSuppressed(e) {
135
+ return suppressedEvents.has(e);
136
+ }
137
+
138
+ const DEV = undefined;
139
+
140
+ /**
141
+ * Root-first names of the owners enclosing `subject` (inclusive when the
142
+ * subject is itself a named owner). Signals hop to their registering owner
143
+ * (`_owner`, set by registerGraph). Unnamed owners are skipped so the path
144
+ * reads as the component tree plus the scope: `<App> › <TodoRow> › effect`.
145
+ */ function ownerPath(e) {
146
+ if (!e) return undefined;
147
+ let t = "_parent" in e ? e : e.nt ?? null;
148
+ const n = [];
149
+ for (;t !== null; t = t._parent) {
150
+ const e = t._name;
151
+ if (typeof e === "string" && e.length) n.push(e);
152
+ }
153
+ return n.length ? n.reverse() : undefined;
154
+ }
155
+
156
+ /**
157
+ * Records a diagnostic on the structured channel (listeners, captures) and
158
+ * returns the entry. `subject` locates it: the current reactive `context` by
159
+ * default (right for the synchronous rule checks — they fire inside the
160
+ * scope that misbehaved); pass the node for scheduler-time findings whose
161
+ * ambient context is the flush, or `null` for events that have no location
162
+ * by nature. An `ownerPath` already on the event wins over the subject walk
163
+ * (hosts whose owners are not signals' owners compute their own). Console
164
+ * output is a separate, dev-tier step — see `reportDiagnostic`.
165
+ */ function emitDiagnostic(e, t = context) {
166
+ const n = {
167
+ sequence: ++diagnosticSequence,
168
+ ...e
169
+ };
170
+ // The observer's own subtree: build the entry (the caller may throw its
171
+ // message) but tell nobody.
172
+ if (isExcluded(t)) {
173
+ suppressedEvents.add(n);
174
+ return n;
175
+ }
176
+ if (n.ownerPath === undefined) {
177
+ const e = ownerPath(t);
178
+ if (e) n.ownerPath = e;
179
+ }
180
+ if (t) eventSubjects.set(n, t);
181
+ for (const e of diagnosticListeners) e(n);
182
+ for (const e of diagnosticCaptures) e.push(n);
183
+ return n;
184
+ }
185
+
186
+ /**
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.
197
+ */ const eventSubjects = new WeakMap;
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
+
207
+ /**
208
+ * The console face of a diagnostic — ONE entry per finding: the message, the
209
+ * owner path (`in <App> › <TodoRow> › effect`) so a human can locate it, the
210
+ * once-per-code footer as trailing lines, and — when the subject is a
211
+ * binding effect the rendering runtime tagged — the element it writes, as a
212
+ * second console argument (hover highlights it, click jumps to Elements).
213
+ * Severity picks the console method. Call sites report the entry
214
+ * `emitDiagnostic` returned so the structured and console channels never
215
+ * disagree. Dev-tier: in an observe build this is a no-op, so wiring paths
216
+ * that both emit and report (graph-size warnings) reach the channel only —
217
+ * production observability never writes to the console.
218
+ */ function reportDiagnostic(e) {
219
+ return;
220
+ }
221
+
222
+ /**
223
+ * Observe-tier: stamp a signal with its creating owner so `ownerPath` can
224
+ * locate signal subjects. The per-owner `_signals` list and the devtools
225
+ * `onGraph` hook are dev-tier — the observe build pays one property write.
226
+ */ function registerGraph(e, t) {
227
+ e.nt = t;
228
+ }
229
+
230
+ /**
231
+ * Graph-size warnings are once per node, re-warning only when the count has
232
+ * grown by GRAPH_SIZE_WARN_EVERY since the last one — off-node, so the
233
+ * pathological handful of nodes that ever reach the threshold are the only
234
+ * ones that cost anything, and no node carries a bookkeeping field for it.
235
+ */ const graphSizeWarnedAt = new WeakMap;
236
+
237
+ function shouldWarnGraphSize(e, t) {
238
+ const n = graphSizeWarnedAt.get(e);
239
+ if (n !== undefined && t < n + GRAPH_SIZE_WARN_EVERY) return false;
240
+ graphSizeWarnedAt.set(e, t);
241
+ return true;
242
+ }
243
+
244
+ /**
245
+ * Observe-tier: a committed change on `node` is about to re-run `count`
246
+ * subscribers (the notify walk in `insertSubs` counted them as it went —
247
+ * fan-out costs exactly one local increment in a loop that already visits
248
+ * every edge, and nothing at link time). Fires from GRAPH_SIZE_WARN_AT up,
249
+ * on the write rather than the link: a fan-out that is never written costs
250
+ * nothing, and one that is re-runs every subscriber this flush. Always-on
251
+ * wherever the channel exists — unlike the opt-in attribution engine, a
252
+ * graph-size pathology should surface without asking.
253
+ */ function noteFanOut(e, t) {
254
+ if (!shouldWarnGraphSize(e, t)) return;
255
+ const n = e._name;
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.`;
257
+ reportDiagnostic(emitDiagnostic({
258
+ code: "HUGE_FAN_OUT",
259
+ kind: "graph",
260
+ severity: "warn",
261
+ message: r,
262
+ nodeName: n,
263
+ ownerId: e.id,
264
+ ownerName: n,
265
+ data: {
266
+ count: t
267
+ }
268
+ }, e));
269
+ }
270
+
271
+ /**
272
+ * Observe-tier: a recompute pass of `node` tracked `count` distinct sources
273
+ * (its trimmed dep list, walked once at the end of the pass — see recompute;
274
+ * no per-link work, no pass bracket). Fires from GRAPH_SIZE_WARN_AT up.
275
+ */ function noteFanIn(e, t) {
276
+ if (!shouldWarnGraphSize(e, t)) return;
277
+ const n = e._name;
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.`;
279
+ reportDiagnostic(emitDiagnostic({
280
+ code: "HUGE_FAN_IN",
281
+ kind: "graph",
282
+ severity: "warn",
283
+ message: r,
284
+ nodeName: n,
285
+ ownerId: e.id,
286
+ ownerName: n,
287
+ data: {
288
+ count: t
289
+ }
290
+ }, e));
291
+ }
292
+
293
+ export { DEV, GRAPH_SIZE_WARN_AT, GRAPH_SIZE_WARN_EVERY, OBSERVE, anyExcluded, emitDiagnostic, isExcluded, isSuppressed, noteFanIn, noteFanOut, ownerPath, recordSubject, registerGraph, reportDiagnostic, subjectOf };
@@ -0,0 +1,195 @@
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
+
3
+ import { setEffectStatusNotify, ext, createEffectNode, recompute, computed, staleValues } from "./core.js";
4
+
5
+ import { attrHooks } from "./attribution-hooks.js";
6
+
7
+ import "./dev.js";
8
+
9
+ import { unwrapStatusError, StatusError } from "./error.js";
10
+
11
+ import { trimStaleDeps } from "./graph.js";
12
+
13
+ import { enqueueSub } from "./heap.js";
14
+
15
+ import { GlobalQueue, currentTransition, activeTransition, haltReactivity, schedule } from "./scheduler.js";
16
+
17
+ /**
18
+ * Effects are the leaf nodes of our reactive graph. When their sources change, they are
19
+ * automatically added to the queue of effects to re-execute, which will cause them to fetch their
20
+ * sources and recompute
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));
29
+ }
30
+
31
+ function notifyEffectStatus(t, e) {
32
+ // Use passed values if provided, otherwise read from node
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) {
38
+ // The error handler is the error arm of the effect phase (#2840 ruling):
39
+ // queue it like the effect function. It runs in the same imperative,
40
+ // writable scope, throws escalate the same way, and a held transition
41
+ // (or optimistic lane) defers it exactly as it defers the success arm.
42
+ // No payload is queued — the node already carries `_statusFlags`/`_error`,
43
+ // and the runner dispatches on them, so a recovery before the effect
44
+ // phase takes the success arm instead. Blocked forwards (explicit
45
+ // `status` arg without node-state writes) don't queue: the status
46
+ // re-propagates unblocked at commit.
47
+ if (this.S & STATUS_ERROR) {
48
+ this.Nt = true;
49
+ this.T.enqueue(this.Pe, this.Ut ??= runEffect.bind(null, this));
50
+ }
51
+ return;
52
+ }
53
+ if (!this.T.notify(this, STATUS_ERROR, STATUS_ERROR)) {
54
+ haltReactivity(unwrapStatusError(E));
55
+ throw E;
56
+ }
57
+ } else if (this.Pe === EFFECT_RENDER) {
58
+ this.T.notify(this, STATUS_PENDING | STATUS_ERROR, r, E);
59
+ }
60
+ }
61
+
62
+ function runEffect(t, e) {
63
+ if (!t.Nt || t.ft & REACTIVE_DISPOSED) return;
64
+ // Ownership (#3319): a value computed under a transaction is applied by that
65
+ // transaction's commit. The ordinary effect phase runs with a transaction
66
+ // active only when the flush's finalize ENTERED one (every other path parks
67
+ // or settles first): leave a run owned by a still-held transaction queued —
68
+ // `_modified` stays set — and the next gate stashes it with the owner.
69
+ // Mainline-owned runs (null) apply now. Lanes are exempt by design (they
70
+ // apply their own effects ahead of their transaction — the optimistic view)
71
+ // and mark their runs with LANE_RUN.
72
+
73
+ // Lane exemption has one exception (#3331): a lane runner for an effect that
74
+ // no longer rides a lane — its optimistic source was superseded, so the lane
75
+ // has no optimistic view left to apply, and the value this effect now
76
+ // carries (or will, once its plain recompute lands) belongs to the still-held
77
+ // transaction. Hand the run to the regular queue, where the transaction's
78
+ // gate stashes it with the owner. Lane-less runners with no live owner
79
+ // (reverts, wake-only lanes) apply now.
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);
82
+ return;
83
+ }
84
+ // Error arm (#2840), user effects only: a compute-phase error that is still
85
+ // the node's settled state at effect time runs the bundle's error handler in
86
+ // this same imperative, writable scope. Unwrap the StatusError used for
87
+ // source tracking — user code gets the error it threw, as boundaries do. No
88
+ // handler: log and keep the system alive (the run was skipped). A handler
89
+ // (or logging) consumes the error; a handler throw falls to the shared
90
+ // catch below and escalates boundary-or-halt like any effect-phase throw.
91
+ // Render effects bypass: their errors route to boundaries synchronously in
92
+ // notifyEffectStatus, and a runner queued by an earlier valueChanged in the
93
+ // same flush must not be hijacked by a later-arriving error status.
94
+ if (t.S & STATUS_ERROR && t.Pe === EFFECT_USER) {
95
+ const e = unwrapStatusError(t.o?._);
96
+ t.$t = t.Ae;
97
+ t.Nt = false;
98
+ try {
99
+ t.un ? t.un(e, () => {
100
+ const e = t.an;
101
+ t.an = undefined;
102
+ e?.();
103
+ }) : console.error(e);
104
+ } catch (e) {
105
+ if (!t.T.notify(t, STATUS_ERROR, STATUS_ERROR)) {
106
+ haltReactivity(e);
107
+ throw e;
108
+ }
109
+ }
110
+ return;
111
+ }
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;
117
+ try {
118
+ E?.();
119
+ const e = t.ln(t.Ae, t.$t);
120
+ if (false && e !== undefined && typeof e !== "function") ;
121
+ // The final cleanup is invoked by disposeChildren at true disposal.
122
+ t.an = e;
123
+ } catch (e) {
124
+ ext(t)._ = new StatusError(t, e);
125
+ t.S |= STATUS_ERROR;
126
+ if (!t.T.notify(t, STATUS_ERROR, STATUS_ERROR)) {
127
+ haltReactivity(e);
128
+ throw e;
129
+ }
130
+ } finally {
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);
139
+ }
140
+ // Outside the try (see the rule in attribution-hooks.ts). Reached whether or
141
+ // not the callback threw — a throw that escapes the catch above halts.
142
+ if (attrHooks !== null) attrHooks.effectRunEnd(t);
143
+ }
144
+
145
+ GlobalQueue.Lt = runEffect;
146
+
147
+ /**
148
+ * Internal tracked effect - bypasses heap, goes directly to effect queue.
149
+ * Runs as a leaf owner: child primitives and onCleanup are forbidden (false throws).
150
+ * Uses stale reads.
151
+ */ function trackedEffect(t, e) {
152
+ const run = () => {
153
+ // `_modified` is NOT redundant with the heap: the heap dedups within a
154
+ // pass, but a held transition's passes each enqueue `_run` into the same
155
+ // user queue, and this gate is what collapses them into one run at commit.
156
+ if (!r.Nt || r.ft & REACTIVE_DISPOSED) return;
157
+ try {
158
+ r.Nt = false;
159
+ recompute(r);
160
+ } finally {}
161
+ };
162
+ const r = computed(() => {
163
+ const e = r.an;
164
+ r.an = undefined;
165
+ e?.();
166
+ const E = staleValues(t);
167
+ r.an = E;
168
+ }, {
169
+ ...e,
170
+ lazy: true
171
+ });
172
+ r.an = undefined;
173
+ r.C = r.C & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
174
+ r.Nt = true;
175
+ r.Pe = EFFECT_TRACKED;
176
+ // Observe-tier label: the computed literal defaulted its `_name` slot to
177
+ // "computed"; relabel by kind (a store into the slot, not a new field).
178
+ if (e?.name === undefined) r._name = "trackedEffect";
179
+ // Status dispatch rides the SHARED notifier (statusNotifierOf keys off
180
+ // _type): its error arm is behavior-identical to the closure that used to
181
+ // live here, without the per-node NodeExtension allocation.
182
+ r.Et = run;
183
+ // The first run rides the heap like every wake (GlobalQueue._update), so a
184
+ // tracked effect created inside a render-effect callback runs after that
185
+ // pass's staged writes commit, not before.
186
+ enqueueSub(r);
187
+ schedule();
188
+ }
189
+
190
+ // Install the shared effect status notifier (statusNotifierOf serves it to
191
+ // every effect node) — module-scope: any bundle that creates effects
192
+ // evaluates this module.
193
+ setEffectStatusNotify(notifyEffectStatus);
194
+
195
+ 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 };
@@ -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 };