@solidjs/signals 2.0.0-rc.2 → 2.0.0-rc.20

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 (198) hide show
  1. package/dist/dev-shared.js +6505 -0
  2. package/dist/dev.attribution.js +3484 -0
  3. package/dist/dev.js +10227 -9508
  4. package/dist/observe/affects-marks.js +86 -0
  5. package/dist/observe/affects.js +112 -0
  6. package/dist/observe/attribution.js +7 -0
  7. package/dist/observe/boundaries.js +696 -0
  8. package/dist/observe/core/action.js +182 -0
  9. package/dist/observe/core/async.js +824 -0
  10. package/dist/observe/core/attribution-costs.js +66 -0
  11. package/dist/observe/core/attribution-feedback.js +280 -0
  12. package/dist/observe/core/attribution-hooks.js +83 -0
  13. package/dist/observe/core/attribution-queries.js +43 -0
  14. package/dist/observe/core/attribution.js +3079 -0
  15. package/dist/observe/core/constants.js +269 -0
  16. package/dist/observe/core/context.js +63 -0
  17. package/dist/observe/core/copies.js +10 -0
  18. package/dist/observe/core/core.js +1707 -0
  19. package/dist/observe/core/dev.js +394 -0
  20. package/dist/observe/core/effect.js +193 -0
  21. package/dist/observe/core/error-hooks.js +71 -0
  22. package/dist/observe/core/error.js +82 -0
  23. package/dist/observe/core/external.js +97 -0
  24. package/dist/observe/core/graph.js +162 -0
  25. package/dist/observe/core/heap.js +124 -0
  26. package/dist/observe/core/identities.js +62 -0
  27. package/dist/observe/core/invariants.js +12 -0
  28. package/dist/observe/core/lanes.js +972 -0
  29. package/dist/observe/core/owner.js +371 -0
  30. package/dist/observe/core/scheduler.js +1157 -0
  31. package/dist/observe/core/truth.js +47 -0
  32. package/dist/observe/core/verdict.js +470 -0
  33. package/dist/observe/deferred.js +186 -0
  34. package/dist/observe/flatten.js +79 -0
  35. package/dist/observe/from.js +248 -0
  36. package/dist/observe/index.js +71 -0
  37. package/dist/observe/map.js +593 -0
  38. package/dist/observe/reveal.js +212 -0
  39. package/dist/observe/signals.js +717 -0
  40. package/dist/observe/store/affects.js +142 -0
  41. package/dist/observe/store/edges.js +39 -0
  42. package/dist/observe/store/hooks.js +16 -0
  43. package/dist/observe/store/index.js +47 -0
  44. package/dist/observe/store/optimistic.js +713 -0
  45. package/dist/observe/store/projection.js +345 -0
  46. package/dist/observe/store/reconcile.js +281 -0
  47. package/dist/observe/store/store.js +2127 -0
  48. package/dist/observe/store/storePath.js +103 -0
  49. package/dist/observe/store/target.js +46 -0
  50. package/dist/observe/store/types.js +83 -0
  51. package/dist/observe/store/utils.js +1063 -0
  52. package/dist/prod/affects-marks.js +86 -0
  53. package/dist/prod/affects.js +98 -112
  54. package/dist/prod/attribution.js +45 -0
  55. package/dist/prod/boundaries.js +578 -468
  56. package/dist/prod/core/action.js +92 -59
  57. package/dist/prod/core/async.js +522 -336
  58. package/dist/prod/core/attribution-hooks.js +3 -0
  59. package/dist/prod/core/constants.js +168 -44
  60. package/dist/prod/core/context.js +12 -16
  61. package/dist/prod/core/copies.js +10 -0
  62. package/dist/prod/core/core.js +1345 -627
  63. package/dist/prod/core/dev.js +123 -1
  64. package/dist/prod/core/effect.js +113 -80
  65. package/dist/prod/core/error-hooks.js +71 -0
  66. package/dist/prod/core/error.js +18 -4
  67. package/dist/prod/core/external.js +6 -7
  68. package/dist/prod/core/graph.js +119 -72
  69. package/dist/prod/core/heap.js +85 -109
  70. package/dist/prod/core/identities.js +62 -0
  71. package/dist/prod/core/invariants.js +1 -32
  72. package/dist/prod/core/lanes.js +931 -132
  73. package/dist/prod/core/owner.js +192 -129
  74. package/dist/prod/core/scheduler.js +948 -642
  75. package/dist/prod/core/truth.js +47 -0
  76. package/dist/prod/core/verdict.js +409 -420
  77. package/dist/prod/deferred.js +184 -0
  78. package/dist/prod/flatten.js +77 -0
  79. package/dist/prod/from.js +248 -0
  80. package/dist/prod/index.js +40 -16
  81. package/dist/prod/map.js +481 -211
  82. package/dist/prod/reveal.js +212 -0
  83. package/dist/prod/signals.js +401 -84
  84. package/dist/prod/store/affects.js +142 -0
  85. package/dist/prod/store/edges.js +39 -0
  86. package/dist/prod/store/hooks.js +16 -0
  87. package/dist/prod/store/index.js +27 -18
  88. package/dist/prod/store/optimistic.js +707 -0
  89. package/dist/prod/store/projection.js +331 -0
  90. package/dist/prod/store/reconcile.js +281 -0
  91. package/dist/prod/store/store.js +1952 -267
  92. package/dist/prod/store/storePath.js +1 -1
  93. package/dist/prod/store/target.js +43 -0
  94. package/dist/prod/store/types.js +83 -0
  95. package/dist/prod/store/utils.js +997 -138
  96. package/dist/types/affects-marks.d.ts +14 -0
  97. package/dist/types/affects.d.ts +12 -30
  98. package/dist/types/attribution.d.ts +19 -0
  99. package/dist/types/attribution.prod.d.ts +22 -0
  100. package/dist/types/boundaries.d.ts +99 -124
  101. package/dist/types/carved.d.ts +1 -0
  102. package/dist/types/core/action.d.ts +23 -9
  103. package/dist/types/core/async.d.ts +34 -6
  104. package/dist/types/core/attribution-costs.d.ts +35 -0
  105. package/dist/types/core/attribution-feedback.d.ts +133 -0
  106. package/dist/types/core/attribution-hooks.d.ts +307 -8
  107. package/dist/types/core/attribution-queries.d.ts +24 -0
  108. package/dist/types/core/attribution.d.ts +802 -72
  109. package/dist/types/core/constants.d.ts +195 -38
  110. package/dist/types/core/copies.d.ts +54 -0
  111. package/dist/types/core/core.d.ts +295 -65
  112. package/dist/types/core/dev.d.ts +509 -22
  113. package/dist/types/core/effect.d.ts +1 -1
  114. package/dist/types/core/error-hooks.d.ts +71 -0
  115. package/dist/types/core/error.d.ts +18 -1
  116. package/dist/types/core/graph.d.ts +40 -1
  117. package/dist/types/core/heap.d.ts +5 -5
  118. package/dist/types/core/identities.d.ts +17 -0
  119. package/dist/types/core/index.d.ts +11 -7
  120. package/dist/types/core/invariants.d.ts +1 -26
  121. package/dist/types/core/lanes.d.ts +74 -43
  122. package/dist/types/core/owner.d.ts +27 -9
  123. package/dist/types/core/scheduler.d.ts +353 -102
  124. package/dist/types/core/truth.d.ts +18 -0
  125. package/dist/types/core/types.d.ts +97 -71
  126. package/dist/types/core/verdict.d.ts +35 -0
  127. package/dist/types/deferred.d.ts +28 -0
  128. package/dist/types/flatten.d.ts +8 -0
  129. package/dist/types/from.d.ts +47 -0
  130. package/dist/types/index.d.ts +33 -7
  131. package/dist/types/map.d.ts +4 -2
  132. package/dist/types/reveal.d.ts +19 -0
  133. package/dist/types/signals.d.ts +196 -45
  134. package/dist/types/store/affects.d.ts +12 -0
  135. package/dist/types/store/edges.d.ts +9 -0
  136. package/dist/types/store/hooks.d.ts +62 -0
  137. package/dist/types/store/index.d.ts +42 -15
  138. package/dist/types/store/optimistic.d.ts +24 -45
  139. package/dist/types/store/projection.d.ts +17 -68
  140. package/dist/types/store/reconcile.d.ts +3 -46
  141. package/dist/types/store/store.d.ts +133 -136
  142. package/dist/types/store/storePath.d.ts +1 -1
  143. package/dist/types/store/target.d.ts +166 -0
  144. package/dist/types/store/types.d.ts +105 -0
  145. package/dist/types/store/utils.d.ts +188 -0
  146. package/package.json +31 -26
  147. package/dist/node.cjs +0 -8745
  148. package/dist/prod/core/optimistic.js +0 -265
  149. package/dist/prod/store/next/optimistic.js +0 -385
  150. package/dist/prod/store/next/projection.js +0 -172
  151. package/dist/prod/store/next/reconcile.js +0 -331
  152. package/dist/prod/store/next/store.js +0 -1499
  153. package/dist/prod/store/next/target.js +0 -20
  154. package/dist/types/core/optimistic.d.ts +0 -6
  155. package/dist/types/store/next/optimistic.d.ts +0 -20
  156. package/dist/types/store/next/projection.d.ts +0 -8
  157. package/dist/types/store/next/reconcile.d.ts +0 -3
  158. package/dist/types/store/next/store.d.ts +0 -77
  159. package/dist/types/store/next/target.d.ts +0 -117
  160. package/dist/types-cjs/affects.d.cts +0 -47
  161. package/dist/types-cjs/boundaries.d.cts +0 -175
  162. package/dist/types-cjs/core/action.d.cts +0 -64
  163. package/dist/types-cjs/core/async.d.cts +0 -21
  164. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -52
  165. package/dist/types-cjs/core/attribution.d.cts +0 -186
  166. package/dist/types-cjs/core/constants.d.cts +0 -97
  167. package/dist/types-cjs/core/context.d.cts +0 -36
  168. package/dist/types-cjs/core/core.d.cts +0 -163
  169. package/dist/types-cjs/core/dev.d.cts +0 -81
  170. package/dist/types-cjs/core/effect.d.cts +0 -30
  171. package/dist/types-cjs/core/error.d.cts +0 -47
  172. package/dist/types-cjs/core/external.d.cts +0 -15
  173. package/dist/types-cjs/core/graph.d.cts +0 -6
  174. package/dist/types-cjs/core/heap.d.cts +0 -22
  175. package/dist/types-cjs/core/index.d.cts +0 -13
  176. package/dist/types-cjs/core/invariants.d.cts +0 -59
  177. package/dist/types-cjs/core/lanes.d.cts +0 -44
  178. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  179. package/dist/types-cjs/core/owner.d.cts +0 -124
  180. package/dist/types-cjs/core/scheduler.d.cts +0 -180
  181. package/dist/types-cjs/core/types.d.cts +0 -192
  182. package/dist/types-cjs/core/verdict.d.cts +0 -2
  183. package/dist/types-cjs/index.d.cts +0 -10
  184. package/dist/types-cjs/map.d.cts +0 -69
  185. package/dist/types-cjs/package.json +0 -3
  186. package/dist/types-cjs/signals.d.cts +0 -624
  187. package/dist/types-cjs/store/index.d.cts +0 -19
  188. package/dist/types-cjs/store/next/optimistic.d.cts +0 -20
  189. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  190. package/dist/types-cjs/store/next/reconcile.d.cts +0 -3
  191. package/dist/types-cjs/store/next/store.d.cts +0 -77
  192. package/dist/types-cjs/store/next/target.d.cts +0 -117
  193. package/dist/types-cjs/store/optimistic.d.cts +0 -45
  194. package/dist/types-cjs/store/projection.d.cts +0 -70
  195. package/dist/types-cjs/store/reconcile.d.cts +0 -46
  196. package/dist/types-cjs/store/store.d.cts +0 -138
  197. package/dist/types-cjs/store/storePath.d.cts +0 -58
  198. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -0,0 +1,394 @@
1
+ import { currentOrigin, withOrigin, withInteraction, 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
+ /**
16
+ * Registers the console footer appended to the first console report of
17
+ * each diagnostic code — a discovery pointer to deeper guidance. Reported
18
+ * events carry it as trailing lines of the same console entry; events that
19
+ * surface as a thrown error instead get it as a follow-up line. Returning
20
+ * undefined for an event suppresses the footer. Passing undefined
21
+ * unregisters and resets the once-per-code memory.
22
+ *
23
+ * @internal A seam for `solid-js`, which owns the repair skill the footer
24
+ * names and installs it from both of its entries; not part of `DEV`. No-op
25
+ * outside dev builds, where nothing reports to the console.
26
+ */ function setConsoleFooter(e) {
27
+ return;
28
+ }
29
+
30
+ const diagnostics = {
31
+ subscribe(e) {
32
+ diagnosticListeners.add(e);
33
+ return () => diagnosticListeners.delete(e);
34
+ },
35
+ emit(e, n = null) {
36
+ return emitDiagnostic(e, n);
37
+ },
38
+ capture() {
39
+ const e = [];
40
+ diagnosticCaptures.add(e);
41
+ return {
42
+ get events() {
43
+ return e;
44
+ },
45
+ clear() {
46
+ e.length = 0;
47
+ },
48
+ stop() {
49
+ diagnosticCaptures.delete(e);
50
+ return [ ...e ];
51
+ }
52
+ };
53
+ }
54
+ };
55
+
56
+ // Flight identity → earliest declared start (see `AttributionSlot.markFlight`).
57
+ // Weak: a stamp must not keep a settled promise alive.
58
+ const flightOrigins = new WeakMap;
59
+
60
+ const attributionSlot = {
61
+ get installed() {
62
+ return attrHooks;
63
+ },
64
+ withInteraction: withInteraction,
65
+ withOrigin: withOrigin,
66
+ currentOrigin: currentOrigin,
67
+ markFlight(e, n = performance.now()) {
68
+ // Earliest wins (`undefined <= n` is false: the first mark always lands).
69
+ if (!(flightOrigins.get(e) <= n)) flightOrigins.set(e, n);
70
+ },
71
+ flightOrigin: e => flightOrigins.get(e)
72
+ };
73
+
74
+ const RECORDS = Symbol.for("@solidjs/signals/observe/records");
75
+
76
+ function recordsChannel() {
77
+ const e = globalThis;
78
+ if (e[RECORDS]) return e[RECORDS];
79
+ const n = new Map;
80
+ const t = new Map;
81
+ return e[RECORDS] = {
82
+ subscribe(e, i, o) {
83
+ const r = n.get(e);
84
+ // Set semantics: one entry per function, however often it is passed —
85
+ // the first subscription's options stand for it.
86
+ if (r === undefined || !r.includes(i)) {
87
+ n.set(e, r === undefined ? [ i ] : [ ...r, i ]);
88
+ if (o !== undefined && o.bodies) {
89
+ let n = t.get(e);
90
+ if (n === undefined) t.set(e, n = new Set);
91
+ n.add(i);
92
+ }
93
+ }
94
+ return () => {
95
+ const o = n.get(e);
96
+ if (o === undefined || !o.includes(i)) return;
97
+ const r = o.filter(e => e !== i);
98
+ if (r.length > 0) n.set(e, r); else n.delete(e);
99
+ const s = t.get(e);
100
+ if (s !== undefined && s.delete(i) && s.size === 0) t.delete(e);
101
+ };
102
+ },
103
+ observed(e, i) {
104
+ return i === "bodies" ? t.has(e) : n.has(e);
105
+ },
106
+ emit(e, t, i) {
107
+ const o = n.get(e);
108
+ if (o === undefined) return;
109
+ // A throwing listener is reported and the rest still hear the record.
110
+ // The try/catch per call allocates nothing unless something throws.
111
+ for (let e = 0; e < o.length; e++) {
112
+ try {
113
+ o[e](t, i);
114
+ } catch (e) {
115
+ console.error(e);
116
+ }
117
+ }
118
+ }
119
+ };
120
+ }
121
+
122
+ const OBSERVE = {
123
+ diagnostics: diagnostics,
124
+ records: recordsChannel(),
125
+ attribution: attributionSlot,
126
+ // Replaced by solid-js's server entry (see `ServerObserve`); on the
127
+ // client the slot stays this placeholder. The cast: the interface is
128
+ // empty HERE and gains its members by augmentation downstream.
129
+ server: {},
130
+ exclude(e) {
131
+ markedOwners.set(e, true);
132
+ hasExclusions = true;
133
+ },
134
+ include(e) {
135
+ // No flag flip: with nothing excluded there is nothing to re-admit,
136
+ // and the walk stays short-circuited.
137
+ markedOwners.set(e, false);
138
+ },
139
+ isExcluded: isExcluded,
140
+ ownerPath: ownerPath
141
+ };
142
+
143
+ // --- Excluded owners ---------------------------------------------------------------
144
+
145
+ // An observer that lives inside the observed app (an adapter's panel,
146
+ // devtools) marks its root; both channels check the subject's owner chain —
147
+ // the same walk `ownerPath` already makes — and stay silent under it. An
148
+ // observer that WRAPS the app (a toolbar around it) excludes its own root
149
+ // and includes the app's back: one map, `true` excluded / `false` included,
150
+ // and the nearest marker up the chain decides. The flag short-circuits the
151
+ // walk for the common case of no exclusions (an include with nothing
152
+ // excluded changes no verdict, so it does not flip it).
153
+ const markedOwners = new WeakMap;
154
+
155
+ let hasExclusions = false;
156
+
157
+ /** Events built for an excluded subject: never delivered, never reported. */ const suppressedEvents = new WeakSet;
158
+
159
+ function isExcluded(e) {
160
+ if (!hasExclusions || !e) return false;
161
+ let n = "_parent" in e ? e : e.H ?? null;
162
+ for (;n !== null; n = n._parent) {
163
+ const e = markedOwners.get(n);
164
+ if (e !== undefined) return e;
165
+ }
166
+ return false;
167
+ }
168
+
169
+ /** For engines that cache the verdict per node: is anything excluded at all? */ function anyExcluded() {
170
+ return hasExclusions;
171
+ }
172
+
173
+ /** Was `entry` built for an excluded subject? Once-per-key reporters must not spend their slot on it. */ function isSuppressed(e) {
174
+ return suppressedEvents.has(e);
175
+ }
176
+
177
+ const DEV = undefined;
178
+
179
+ /**
180
+ * Root-first names of the owners enclosing `subject` (inclusive when the
181
+ * subject is itself a named owner). Signals hop to their registering owner
182
+ * (`_owner`, set by registerGraph). Unnamed owners are skipped so the path
183
+ * reads as the component tree plus the scope: `<App> › <TodoRow> › effect`.
184
+ * Public as `OBSERVE.ownerPath`; the core's own sites import it directly.
185
+ */ function ownerPath(e) {
186
+ if (!e) return undefined;
187
+ let n = "_parent" in e ? e : e.H ?? null;
188
+ const t = [];
189
+ for (;n !== null; n = n._parent) {
190
+ const e = n._name;
191
+ if (typeof e === "string" && e.length) t.push(e);
192
+ }
193
+ return t.length ? t.reverse() : undefined;
194
+ }
195
+
196
+ /**
197
+ * The innermost source location on the subject's chain: the subject's own
198
+ * `_loc` (a signal or computation created with `{ loc }`), else the first
199
+ * `_loc` up the owners — a signal hops to its registering owner, then
200
+ * `_parent` upward (a component root carries its JSX site). The same walk
201
+ * `ownerPath` makes; `undefined` when nothing on the chain was located.
202
+ */ function locationOf(e) {
203
+ // Owners have a `_parent` key (null on a root); a signal has none and hops
204
+ // to its registering `_owner` instead.
205
+ for (let n = e; n; n = n._parent !== undefined ? n._parent : n.H) if (n._loc) return n._loc;
206
+ return undefined;
207
+ }
208
+
209
+ /**
210
+ * Records a diagnostic on the structured channel (listeners, captures) and
211
+ * returns the entry. `subject` locates it: the current reactive `context` by
212
+ * default (right for the synchronous rule checks — they fire inside the
213
+ * scope that misbehaved); pass the node for scheduler-time findings whose
214
+ * ambient context is the flush, or `null` for events that have no location
215
+ * by nature. An `ownerPath` (or `loc`) already on the event wins over the
216
+ * subject walk (hosts whose owners are not signals' owners compute their
217
+ * own). Console output is a separate, dev-tier step — see `reportDiagnostic`.
218
+ */ function emitDiagnostic(e, n = context) {
219
+ const t = {
220
+ sequence: ++diagnosticSequence,
221
+ ...e
222
+ };
223
+ // The observer's own subtree: build the entry (the caller may throw its
224
+ // message) but tell nobody.
225
+ if (isExcluded(n)) {
226
+ suppressedEvents.add(t);
227
+ return t;
228
+ }
229
+ if (t.ownerPath === undefined) {
230
+ const e = ownerPath(n);
231
+ if (e) t.ownerPath = e;
232
+ }
233
+ if (t.loc === undefined) {
234
+ const e = locationOf(n);
235
+ if (e !== undefined) t.loc = e;
236
+ }
237
+ const i = n ?? undefined;
238
+ if (i !== undefined) eventSubjects.set(t, i);
239
+ for (const e of diagnosticListeners) e(t, i);
240
+ for (const e of diagnosticCaptures) e.push(t);
241
+ return t;
242
+ }
243
+
244
+ /**
245
+ * The subject each emitted event was about, for the console step, which
246
+ * runs after `emitDiagnostic` returned and can show what the node knows: a
247
+ * rendering runtime may stamp a binding effect with the DOM element it
248
+ * writes (`_devElement`), and a live element reference beside the message
249
+ * is the most addressable pointer a console can print. Listeners get the
250
+ * subject as their second argument instead; the map exists only to carry
251
+ * it from `emitDiagnostic` to `reportDiagnostic` across the call site's
252
+ * `reportDiagnostic(emitDiagnostic(…))`. Weak, keyed by the entry.
253
+ */ const eventSubjects = new WeakMap;
254
+
255
+ /**
256
+ * The console face of a diagnostic — ONE entry per finding: the message, the
257
+ * owner path (`in <App> › <TodoRow> › effect`) so a human can locate it, the
258
+ * source location (`at src/App.tsx:18:3` — see `locationLine`) when a node on
259
+ * the chain was compiled with one, the once-per-code footer as trailing
260
+ * lines, and — when the subject is a binding effect the rendering runtime
261
+ * tagged — the element it writes, as a second console argument (hover
262
+ * highlights it, click jumps to Elements).
263
+ * Severity picks the console method. Call sites report the entry
264
+ * `emitDiagnostic` returned so the structured and console channels never
265
+ * disagree. Dev-tier: in an observe build this is a no-op, so wiring paths
266
+ * that both emit and report (graph-size warnings) reach the channel only —
267
+ * production observability never writes to the console.
268
+ */ function reportDiagnostic(e) {
269
+ return;
270
+ }
271
+
272
+ /**
273
+ * Observe-tier: stamp a signal with its creating owner so `ownerPath` can
274
+ * locate signal subjects. The per-owner `_signals` list and the devtools
275
+ * `onGraph` hook are dev-tier — the observe build pays one property write.
276
+ */ function registerGraph(e, n) {
277
+ e.H = n;
278
+ }
279
+
280
+ /**
281
+ * Observe-tier: the live top-level roots — owners created with no parent
282
+ * (`render()`'s root, a `createRoot()` at module scope, a devtools panel).
283
+ * Held weakly so an undisposed root nothing references still collects; a
284
+ * root a subscription keeps alive is exactly the leak `graphSize()` exists
285
+ * to count. Registered by `createOwner` and released by its disposal, so
286
+ * the cost is one Set write per top-level root, never per node.
287
+ */ const liveRoots = new Set;
288
+
289
+ const rootRefs = new WeakMap;
290
+
291
+ const rootReaper = typeof FinalizationRegistry === "function" ? new FinalizationRegistry(e => liveRoots.delete(e)) : null;
292
+
293
+ function registerRoot(e) {
294
+ // Observe-tier bodies: folded to a bare return in prod so the mangler and
295
+ // the bundle never see the walk.
296
+ if (typeof WeakRef !== "function") return;
297
+ const n = new WeakRef(e);
298
+ rootRefs.set(e, n);
299
+ liveRoots.add(n);
300
+ rootReaper?.register(e, n, n);
301
+ }
302
+
303
+ function unregisterRoot(e) {
304
+ const n = rootRefs.get(e);
305
+ if (n === undefined) return;
306
+ rootRefs.delete(e);
307
+ liveRoots.delete(n);
308
+ rootReaper?.unregister(n);
309
+ }
310
+
311
+ /**
312
+ * The live top-level roots, for a walk of the owner tree (the engine's
313
+ * `graphSize`): dead refs are dropped as they are met. Empty in prod.
314
+ */ function liveRootOwners() {
315
+ const e = [];
316
+ for (const n of liveRoots) {
317
+ const t = n.deref();
318
+ if (t === undefined) liveRoots.delete(n); else e.push(t);
319
+ }
320
+ return e;
321
+ }
322
+
323
+ /**
324
+ * Graph-size warnings are once per node, re-warning only when the count has
325
+ * grown by GRAPH_SIZE_WARN_EVERY since the last one — off-node, so the
326
+ * pathological handful of nodes that ever reach the threshold are the only
327
+ * ones that cost anything, and no node carries a bookkeeping field for it.
328
+ */ const graphSizeWarnedAt = new WeakMap;
329
+
330
+ function shouldWarnGraphSize(e, n) {
331
+ const t = graphSizeWarnedAt.get(e);
332
+ if (t !== undefined && n < t + GRAPH_SIZE_WARN_EVERY) return false;
333
+ graphSizeWarnedAt.set(e, n);
334
+ return true;
335
+ }
336
+
337
+ /**
338
+ * Observe-tier: a committed change on `node` is about to re-run `count`
339
+ * subscribers. Two reporters, one finding, one dedupe: the core counts the
340
+ * notify walk in `insertSubs` as it goes (fan-out costs exactly one local
341
+ * increment in a loop that already visits every edge, and nothing at link
342
+ * time) and fires from GRAPH_SIZE_WARN_AT up, always-on wherever the
343
+ * channel exists — a graph-size pathology should surface without asking.
344
+ * The attribution engine, while enabled, reports the same code from its
345
+ * lower `fanOut` threshold (default 250) on the root writes it stamps, with
346
+ * the write kind it knows, and hands over to the core at
347
+ * GRAPH_SIZE_WARN_AT so one change never carries two findings. Both fire on
348
+ * the write rather than the link: a fan-out that is never written costs
349
+ * nothing, and one that is re-runs every subscriber this flush. Once per
350
+ * node, re-warning only once the count has grown by GRAPH_SIZE_WARN_EVERY.
351
+ */ function noteFanOut(e, n, t) {
352
+ if (!shouldWarnGraphSize(e, n)) return;
353
+ const i = e._name;
354
+ const o = `[HUGE_FAN_OUT] ${i ? `Signal "${i}"` : "A signal"} changed with ${n} 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.`;
355
+ reportDiagnostic(emitDiagnostic({
356
+ code: "HUGE_FAN_OUT",
357
+ kind: "graph",
358
+ severity: "warn",
359
+ message: o,
360
+ nodeName: i,
361
+ ownerId: e.id,
362
+ ownerName: i,
363
+ data: t === undefined ? {
364
+ count: n
365
+ } : {
366
+ count: n,
367
+ write: t
368
+ }
369
+ }, e));
370
+ }
371
+
372
+ /**
373
+ * Observe-tier: a recompute pass of `node` tracked `count` distinct sources
374
+ * (its trimmed dep list, walked once at the end of the pass — see recompute;
375
+ * no per-link work, no pass bracket). Fires from GRAPH_SIZE_WARN_AT up.
376
+ */ function noteFanIn(e, n) {
377
+ if (!shouldWarnGraphSize(e, n)) return;
378
+ const t = e._name;
379
+ const i = `[HUGE_FAN_IN] ${t ? `Computation "${t}"` : "A computation"} tracked ${n} 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.`;
380
+ reportDiagnostic(emitDiagnostic({
381
+ code: "HUGE_FAN_IN",
382
+ kind: "graph",
383
+ severity: "warn",
384
+ message: i,
385
+ nodeName: t,
386
+ ownerId: e.id,
387
+ ownerName: t,
388
+ data: {
389
+ count: n
390
+ }
391
+ }, e));
392
+ }
393
+
394
+ export { DEV, GRAPH_SIZE_WARN_AT, GRAPH_SIZE_WARN_EVERY, OBSERVE, anyExcluded, emitDiagnostic, isExcluded, isSuppressed, liveRootOwners, noteFanIn, noteFanOut, ownerPath, registerGraph, registerRoot, reportDiagnostic, setConsoleFooter, unregisterRoot };
@@ -0,0 +1,193 @@
1
+ import { NOT_PENDING, EFFECT_USER, CONFIG_AUTO_DISPOSE, CONFIG_CHILDREN_FORBIDDEN, EFFECT_TRACKED, EFFECT_RENDER, REACTIVE_DISPOSED, STATUS_ERROR, STATUS_PENDING } from "./constants.js";
2
+
3
+ import { createEffectNode, recompute, computed, staleValues, ext, setEffectStatusNotify } 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, schedule, heldRunHook, haltReactivity, GlobalQueue } 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, o, r) {
22
+ const u = !!r?.user;
23
+ const E = createEffectNode(t, e, o, u ? EFFECT_USER : EFFECT_RENDER, r);
24
+ recompute(E, true);
25
+ // A first pass that read a staged value was staged itself (recompute: born
26
+ // staged); the flush's commit replays this effect. Its first run is not this
27
+ // creation's (A29). A lane's node likewise: its run is the lane's, queued
28
+ // by the pass and released at the reveal (lanes.ts).
29
+ !r?.defer && E.ue === NOT_PENDING && !E.T?.Je?.V && (E.i === EFFECT_USER || r?.schedule ? globalQueue.enqueue(E.i, runEffect.bind(null, E)) : // Type 0: the synchronous first render, not a queued run (D-19).
30
+ runEffect(E, 0));
31
+ }
32
+
33
+ function notifyEffectStatus() {
34
+ const t = this.m;
35
+ const e = this.T?.U;
36
+ if (t & STATUS_ERROR) {
37
+ globalQueue.notify(this, STATUS_PENDING, 0);
38
+ if (this.i === EFFECT_USER) {
39
+ // The error handler is the error arm of the effect phase (#2840 ruling):
40
+ // queue it like the effect function. It runs in the same imperative,
41
+ // writable scope and throws escalate the same way. No payload is queued — the node already carries `_statusFlags`/`_error`,
42
+ // and the runner dispatches on them, so a recovery before the effect
43
+ // phase takes the success arm instead. (Re-read: the boundary
44
+ // notify above can run a redraw.)
45
+ if (this.m & STATUS_ERROR) {
46
+ this.Qe = true;
47
+ globalQueue.enqueue(this.i, this.W ??= runEffect.bind(null, this));
48
+ }
49
+ return;
50
+ }
51
+ // Dev locates the halt at the node that threw: the StatusError's
52
+ // source, upstream of this effect when a computed failed. The rethrow is
53
+ // the user's error, not the wrapper: the wrapper's `source` is a node, and
54
+ // a reporter that serializes the throw walks the reactive graph.
55
+ escalate(this, unwrapStatusError(e), this);
56
+ } else if (this.i === EFFECT_RENDER) {
57
+ globalQueue.notify(this, STATUS_PENDING | STATUS_ERROR, t, e);
58
+ }
59
+ }
60
+
61
+ /** An effect's error no boundary takes halts the system (boundary-or-halt):
62
+ * halted with `cause` and rethrown; dev locates it at `subject`. */ function escalate(t, e, o = t) {
63
+ if (!globalQueue.notify(t, STATUS_ERROR, STATUS_ERROR)) {
64
+ haltReactivity(e);
65
+ throw e;
66
+ }
67
+ }
68
+
69
+ function runEffect(t, e) {
70
+ if (!t.Qe || t.R & REACTIVE_DISPOSED) return;
71
+ // A queued run behind a fallback (boundaries.ts) waits for the reveal: a
72
+ // user effect's, which would read a DOM that is not attached, and a render
73
+ // effect's update too (maintainer, 2026-10-02: "we held the queue but let
74
+ // the sync renders through… we definitely shouldn't be showing portals
75
+ // early") — a Portal's or head-tag's render effect writes outside the
76
+ // hidden subtree. The synchronous first render on creation (`type` 0) is
77
+ // not a queued run and goes through, whichever boundary above is on its
78
+ // fallback then — an outer one about to reveal in this flush included
79
+ // (#4343). `_modified` stays set; the boundary re-queues the run
80
+ // (`release`).
81
+ if (e && heldRunHook?.(t)) return;
82
+ // Error arm (#2840), user effects only: a compute-phase error that is still
83
+ // the node's settled state at effect time runs the bundle's error handler in
84
+ // this same imperative, writable scope. Unwrap the StatusError used for
85
+ // source tracking — user code gets the error it threw, as boundaries do. No
86
+ // handler: log and keep the system alive (the run was skipped). A handler
87
+ // (or logging) consumes the error; a handler throw falls to the shared
88
+ // catch below and escalates boundary-or-halt like any effect-phase throw.
89
+ // Render effects bypass: their errors route to boundaries synchronously in
90
+ // notifyEffectStatus, and a runner queued by an earlier valueChanged in the
91
+ // same flush must not be hijacked by a later-arriving error status.
92
+ if (t.m & STATUS_ERROR && t.i === EFFECT_USER) {
93
+ const e = unwrapStatusError(t.T?.U);
94
+ t.It = t.le;
95
+ t.Qe = false;
96
+ try {
97
+ t.kt ? t.kt(e, () => {
98
+ const e = t.Vt;
99
+ t.Vt = undefined;
100
+ e?.();
101
+ }) : console.error(e);
102
+ } catch (e) {
103
+ escalate(t, e);
104
+ }
105
+ return;
106
+ }
107
+ // Captured before the callback: its own throw errors the node below, but
108
+ // the compute pass that produced `_value` was clean, so its tail still goes.
109
+ const o = t.T?.U == null;
110
+ // Observe tier, like its `effectRunEnd` twin below: the frame the engine
111
+ // opens here is what stamps the callback's writes as the effect's (the
112
+ // cascade an observer reports) and what times the callback (the `effect`
113
+ // record) — facts a production observer needs, not only a dev console.
114
+ if (attrHooks !== null) attrHooks.effectRunStart(t);
115
+ const r = t.Vt;
116
+ t.Vt = undefined;
117
+ try {
118
+ r?.();
119
+ const e = t.Ge(t.le, t.It);
120
+ if (false && e !== undefined && typeof e !== "function") ;
121
+ // The final cleanup is invoked by disposeChildren at true disposal.
122
+ t.Vt = e;
123
+ } catch (e) {
124
+ ext(t).U = new StatusError(t, e);
125
+ t.m |= STATUS_ERROR;
126
+ escalate(t, e);
127
+ } finally {
128
+ t.It = t.le;
129
+ t.Qe = false;
130
+ // The run applied: this is the frame now, so the dependency tail the
131
+ // compute pass left linked goes (A30, #3438 — `recompute` defers an
132
+ // effect's trim while a run is owed; the twin of `commitPendingNode`'s
133
+ // trim for a staged pass). An errored compute kept its full list with
134
+ // `_depsTail` marking where it stopped; leave it, as the commit does.
135
+ if (o) trimStaleDeps(t);
136
+ }
137
+ // Outside the try (see the rule in attribution-hooks.ts). Reached whether or
138
+ // not the callback threw — a throw that escapes the catch above halts.
139
+ if (attrHooks !== null) attrHooks.effectRunEnd(t);
140
+ }
141
+
142
+ GlobalQueue.q = runEffect;
143
+
144
+ /**
145
+ * Internal tracked effect - bypasses heap, goes directly to effect queue.
146
+ * Runs as a leaf owner: child primitives and onCleanup are forbidden (false throws).
147
+ * Uses stale reads.
148
+ */ function trackedEffect(t, e) {
149
+ const run = () => {
150
+ // `_modified` is NOT redundant with the heap: the heap dedups within a
151
+ // pass, but several passes in one flush each enqueue `_run` into the same
152
+ // user queue, and this gate is what collapses them into one run.
153
+ if (!o.Qe || o.R & REACTIVE_DISPOSED) return;
154
+ if (heldRunHook?.(o)) return;
155
+ try {
156
+ o.Qe = false;
157
+ recompute(o);
158
+ } finally {}
159
+ };
160
+ const o = computed(() => {
161
+ const e = o.Vt;
162
+ o.Vt = undefined;
163
+ e?.();
164
+ const r = staleValues(t);
165
+ o.Vt = r;
166
+ }, {
167
+ ...e,
168
+ lazy: true
169
+ });
170
+ o.Vt = undefined;
171
+ o.l = o.l & ~CONFIG_AUTO_DISPOSE | CONFIG_CHILDREN_FORBIDDEN;
172
+ o.Qe = true;
173
+ o.i = EFFECT_TRACKED;
174
+ // Observe-tier label: the computed literal defaulted its `_name` slot to
175
+ // "computed"; relabel by kind (a store into the slot, not a new field).
176
+ if (e?.name === undefined) o._name = "trackedEffect";
177
+ // Status dispatch rides the SHARED notifier (statusNotifierOf keys off
178
+ // _type): its error arm is behavior-identical to the closure that used to
179
+ // live here, without the per-node NodeExtension allocation.
180
+ o.Z = run;
181
+ // The first run rides the heap like every wake (GlobalQueue._update), so a
182
+ // tracked effect created inside a render-effect callback runs after that
183
+ // pass's staged writes commit, not before.
184
+ enqueueSub(o);
185
+ schedule();
186
+ }
187
+
188
+ // Install the shared effect status notifier (statusNotifierOf serves it to
189
+ // every effect node) — module-scope: any bundle that creates effects
190
+ // evaluates this module.
191
+ setEffectStatusNotify(notifyEffectStatus);
192
+
193
+ 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 };