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

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 (70) hide show
  1. package/README.md +1 -1
  2. package/dist/dev.js +4287 -2803
  3. package/dist/node.cjs +4563 -3756
  4. package/dist/prod/affects.js +16 -16
  5. package/dist/prod/boundaries.js +90 -90
  6. package/dist/prod/core/action.js +3 -3
  7. package/dist/prod/core/async.js +234 -178
  8. package/dist/prod/core/constants.js +39 -1
  9. package/dist/prod/core/core.js +362 -243
  10. package/dist/prod/core/effect.js +56 -56
  11. package/dist/prod/core/external.js +4 -4
  12. package/dist/prod/core/graph.js +65 -54
  13. package/dist/prod/core/heap.js +47 -39
  14. package/dist/prod/core/invariants.js +3 -2
  15. package/dist/prod/core/lanes.js +41 -34
  16. package/dist/prod/core/optimistic.js +78 -58
  17. package/dist/prod/core/owner.js +101 -100
  18. package/dist/prod/core/scheduler.js +249 -192
  19. package/dist/prod/core/verdict.js +185 -78
  20. package/dist/prod/index.js +7 -7
  21. package/dist/prod/map.js +108 -106
  22. package/dist/prod/signals.js +20 -1
  23. package/dist/prod/store/index.js +36 -0
  24. package/dist/prod/store/next/optimistic.js +385 -0
  25. package/dist/prod/store/next/projection.js +172 -0
  26. package/dist/prod/store/next/reconcile.js +331 -0
  27. package/dist/prod/store/next/store.js +1499 -0
  28. package/dist/prod/store/next/target.js +20 -0
  29. package/dist/prod/store/store.js +126 -882
  30. package/dist/prod/store/utils.js +59 -186
  31. package/dist/types/core/attribution-hooks.d.ts +52 -0
  32. package/dist/types/core/attribution.d.ts +186 -0
  33. package/dist/types/core/constants.d.ts +26 -0
  34. package/dist/types/core/core.d.ts +16 -1
  35. package/dist/types/core/dev.d.ts +20 -3
  36. package/dist/types/core/graph.d.ts +1 -0
  37. package/dist/types/core/lanes.d.ts +4 -16
  38. package/dist/types/core/scheduler.d.ts +12 -2
  39. package/dist/types/core/types.d.ts +85 -41
  40. package/dist/types/signals.d.ts +19 -0
  41. package/dist/types/store/index.d.ts +15 -5
  42. package/dist/types/store/next/optimistic.d.ts +20 -0
  43. package/dist/types/store/next/projection.d.ts +8 -0
  44. package/dist/types/store/next/reconcile.d.ts +3 -0
  45. package/dist/types/store/next/store.d.ts +77 -0
  46. package/dist/types/store/next/target.d.ts +117 -0
  47. package/dist/types/store/store.d.ts +26 -101
  48. package/dist/types/store/utils.d.ts +0 -40
  49. package/dist/types-cjs/core/attribution-hooks.d.cts +52 -0
  50. package/dist/types-cjs/core/attribution.d.cts +186 -0
  51. package/dist/types-cjs/core/constants.d.cts +26 -0
  52. package/dist/types-cjs/core/core.d.cts +16 -1
  53. package/dist/types-cjs/core/dev.d.cts +20 -3
  54. package/dist/types-cjs/core/graph.d.cts +1 -0
  55. package/dist/types-cjs/core/lanes.d.cts +4 -16
  56. package/dist/types-cjs/core/scheduler.d.cts +12 -2
  57. package/dist/types-cjs/core/types.d.cts +85 -41
  58. package/dist/types-cjs/signals.d.cts +19 -0
  59. package/dist/types-cjs/store/index.d.cts +15 -5
  60. package/dist/types-cjs/store/next/optimistic.d.cts +20 -0
  61. package/dist/types-cjs/store/next/projection.d.cts +8 -0
  62. package/dist/types-cjs/store/next/reconcile.d.cts +3 -0
  63. package/dist/types-cjs/store/next/store.d.cts +77 -0
  64. package/dist/types-cjs/store/next/target.d.cts +117 -0
  65. package/dist/types-cjs/store/store.d.cts +26 -101
  66. package/dist/types-cjs/store/utils.d.cts +0 -40
  67. package/package.json +2 -1
  68. package/dist/prod/store/optimistic.js +0 -217
  69. package/dist/prod/store/projection.js +0 -231
  70. package/dist/prod/store/reconcile.js +0 -707
@@ -1,4 +1,4 @@
1
- import { pendingCheckActive } from "../core/core.js";
1
+ import "../core/core.js";
2
2
 
3
3
  import { SUPPORTS_PROXY } from "../core/constants.js";
4
4
 
@@ -12,162 +12,29 @@ import "../core/effect.js";
12
12
 
13
13
  import { createMemo } from "../signals.js";
14
14
 
15
- import { ownEnumerableKeys, $PROXY, isWrappable, $TARGET, lookupTarget, trackSelf, witnessAffectsMark, mergedOverlay, STORE_VALUE, storeLookup, STORE_LOOKUP, $DELETED, wrap, getStoreSymbols, getPropertyDescriptor, getStoreKeys, getKeys, $TRACK, rawValuesUsed, isRawValue } from "./store.js";
16
-
17
- function snapshotImpl(e, t, r, n) {
18
- let o, s, i, c, f, u;
19
- if (!isWrappable(e)) return e;
20
- if (r && r.has(e)) return r.get(e);
21
- if (!r) r = new Map;
22
- if (o = e[$TARGET] || lookupTarget(e, n)) {
23
- if (t) {
24
- trackSelf(o, $TRACK);
25
- // A tracked walk reads THROUGH the record without touching the proxy
26
- // traps — witness the record's affects() channel like a trap read would.
27
- if (pendingCheckActive) witnessAffectsMark(o);
28
- }
29
- i = mergedOverlay(o);
30
- // A derived store's STORE_VALUE is the inner store's live proxy
31
- // (store-in-store: createOptimisticStore/createProjection over a store).
32
- // Without an overlay of its own, the fast path below would map to — and
33
- // could return — that proxy verbatim. Recurse instead so the
34
- // inner store's own target branch unwraps it (chains of any depth).
35
- // With an overlay, a fresh `result` is always built, so the walk over the
36
- // inner proxy already copies plain values.
37
- if (!i && o[STORE_VALUE][$TARGET]) {
38
- f = snapshotImpl(o[STORE_VALUE], t, r, n);
39
- r.set(e, f);
40
- return f;
41
- }
42
- s = Array.isArray(o[STORE_VALUE]);
43
- r.set(e, i ? c = s ? [] : Object.create(Object.getPrototypeOf(o[STORE_VALUE])) : o[STORE_VALUE]);
44
- e = o[STORE_VALUE];
45
- n = o[STORE_LOOKUP] ?? storeLookup;
46
- } else {
47
- s = Array.isArray(e);
48
- r.set(e, e);
49
- }
50
- if (s) {
51
- const s = i?.length ?? e.length;
52
- for (let a = 0; a < s; a++) {
53
- u = i && a in i ? i[a] : e[a];
54
- if (u === $DELETED) continue;
55
- if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
56
- if ((f = snapshotImpl(u, t, r, n)) !== u || c) {
57
- if (!c) r.set(e, c = [ ...e ]);
58
- c[a] = f;
59
- }
60
- }
61
- // Enumerate array symbols separately to avoid scanning indices twice.
62
- // Spread copies omit symbols, so assign them after the numeric walk.
63
- const a = n ? getStoreSymbols(e, i) : [];
64
- for (let s = 0, l = a.length; s < l; s++) {
65
- const l = a[s];
66
- const p = getPropertyDescriptor(e, i, l);
67
- if (!p || p.get) continue;
68
- u = i && l in i ? i[l] : e[l];
69
- if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
70
- f = snapshotImpl(u, t, r, n);
71
- if (f !== u || c) {
72
- if (!c) r.set(e, c = Object.assign([ ...e ], e));
73
- c[l] = f;
74
- }
75
- }
76
- // Deleted trailing slots are skipped above, so restore length to preserve
77
- // holes instead of truncating the copy (#2846) — mirrors unwrapStoreValue.
78
- if (c) c.length = s;
79
- } else if (!i) {
80
- // Specialized walk for the common no-overlay case (from #2756): the own
81
- // descriptor gives the value directly, so each property is read once with
82
- // no overlay membership checks.
83
- // A lookup means this object belongs to an immutable store backing tree,
84
- // even if that nested value has not needed its own proxy yet.
85
- const s = n ? getStoreKeys(e, undefined) : getKeys(e, undefined);
86
- for (let i = 0, a = s.length; i < a; i++) {
87
- const a = s[i];
88
- const l = Object.getOwnPropertyDescriptor(e, a);
89
- if (l.get) continue;
90
- u = l.value;
91
- if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
92
- if ((f = snapshotImpl(u, t, r, n)) !== u || c) {
93
- if (!c) {
94
- c = Object.create(Object.getPrototypeOf(e));
95
- Object.assign(c, e);
96
- }
97
- c[a] = f;
98
- }
99
- }
100
- } else {
101
- // An override only exists on a store record, and the target branch above
102
- // always set `lookup` alongside it — so this branch is always store-keyed.
103
- const s = getStoreKeys(e, i);
104
- for (let a = 0, l = s.length; a < l; a++) {
105
- let l = s[a];
106
- const p = getPropertyDescriptor(e, i, l);
107
- if (p.get) continue;
108
- u = l in i ? i[l] : e[l];
109
- if (t && isWrappable(u) && !(rawValuesUsed && isRawValue(u))) wrap(u, o);
110
- if ((f = snapshotImpl(u, t, r, n)) !== e[l] || c) {
111
- if (!c) {
112
- c = Object.create(Object.getPrototypeOf(e));
113
- Object.assign(c, e);
114
- }
115
- c[l] = f;
116
- }
117
- }
118
- }
119
- return c || e;
120
- }
121
-
122
- function snapshot(e, t, r) {
123
- return snapshotImpl(e, false, t, r);
124
- }
125
-
126
- /**
127
- * Returns a plain (non-proxy) deep copy **and** subscribes the current
128
- * tracking scope to every nested change in the source store. Any write
129
- * anywhere in the subtree invalidates the consumer.
130
- *
131
- * Use this when you need plain data inside a reactive scope and want to
132
- * react to deep mutations (e.g. passing a snapshot to `reconcile()` or to a
133
- * memo that should rerun on any nested change). For most read paths, prefer
134
- * direct property access — Solid stores already track per-property reads
135
- * with no `deep()` wrapper needed.
136
- *
137
- * @example
138
- * ```ts
139
- * const [state] = createStore({ a: { b: { c: 1 } } });
140
- *
141
- * createEffect(
142
- * () => deep(state), // reruns on any nested change
143
- * plain => sendToWorker(plain) // worker gets a non-proxy copy
144
- * );
145
- * ```
146
- */ function deep(e) {
147
- return snapshotImpl(e, true);
148
- }
15
+ import { ownEnumerableKeys, $PROXY } from "./store.js";
149
16
 
150
17
  function trueFn() {
151
18
  return true;
152
19
  }
153
20
 
154
21
  const propTraps = {
155
- get(e, t, r) {
156
- if (t === $PROXY) return r;
157
- return e.get(t);
22
+ get(e, r, t) {
23
+ if (r === $PROXY) return t;
24
+ return e.get(r);
158
25
  },
159
- has(e, t) {
160
- if (t === $PROXY) return true;
161
- return e.has(t);
26
+ has(e, r) {
27
+ if (r === $PROXY) return true;
28
+ return e.has(r);
162
29
  },
163
30
  set: trueFn,
164
31
  deleteProperty: trueFn,
165
- getOwnPropertyDescriptor(e, t) {
32
+ getOwnPropertyDescriptor(e, r) {
166
33
  return {
167
34
  configurable: true,
168
35
  enumerable: true,
169
36
  get() {
170
- return e.get(t);
37
+ return e.get(r);
171
38
  },
172
39
  set: trueFn,
173
40
  deleteProperty: trueFn
@@ -205,36 +72,36 @@ const $SOURCES = Symbol(0);
205
72
  * ```
206
73
  */ function merge(...e) {
207
74
  if (e.length === 1 && typeof e[0] !== "function") return e[0];
208
- let t = false;
209
- const r = [];
75
+ let r = false;
76
+ const t = [];
210
77
  for (let n = 0; n < e.length; n++) {
211
78
  const o = e[n];
212
- t = t || !!o && $PROXY in o;
79
+ r = r || !!o && $PROXY in o;
213
80
  const s = !!o && o[$SOURCES];
214
81
  if (s) {
215
- for (let e = 0; e < s.length; e++) r.push(s[e]);
216
- } else r.push(typeof o === "function" ? (t = true, createMemo(o)) : o);
82
+ for (let e = 0; e < s.length; e++) t.push(s[e]);
83
+ } else t.push(typeof o === "function" ? (r = true, createMemo(o)) : o);
217
84
  }
218
- if (SUPPORTS_PROXY && t) {
85
+ if (SUPPORTS_PROXY && r) {
219
86
  return new Proxy({
220
87
  get(e) {
221
- if (e === $SOURCES) return r;
222
- for (let t = r.length - 1; t >= 0; t--) {
223
- const n = resolveSource(r[t]);
88
+ if (e === $SOURCES) return t;
89
+ for (let r = t.length - 1; r >= 0; r--) {
90
+ const n = resolveSource(t[r]);
224
91
  if (e in n) return n[e];
225
92
  }
226
93
  },
227
94
  has(e) {
228
- for (let t = r.length - 1; t >= 0; t--) {
229
- if (e in resolveSource(r[t])) return true;
95
+ for (let r = t.length - 1; r >= 0; r--) {
96
+ if (e in resolveSource(t[r])) return true;
230
97
  }
231
98
  return false;
232
99
  },
233
100
  keys() {
234
101
  const e = new Set;
235
- for (let t = 0; t < r.length; t++) {
236
- const n = ownEnumerableKeys(resolveSource(r[t]));
237
- for (let t = 0; t < n.length; t++) e.add(n[t]);
102
+ for (let r = 0; r < t.length; r++) {
103
+ const n = ownEnumerableKeys(resolveSource(t[r]));
104
+ for (let r = 0; r < n.length; r++) e.add(n[r]);
238
105
  }
239
106
  return [ ...e ];
240
107
  }
@@ -242,37 +109,37 @@ const $SOURCES = Symbol(0);
242
109
  }
243
110
  const n = Object.create(null);
244
111
  let o = false;
245
- let s = r.length - 1;
112
+ let s = t.length - 1;
246
113
  for (let e = s; e >= 0; e--) {
247
- const t = r[e];
248
- if (!t) {
114
+ const r = t[e];
115
+ if (!r) {
249
116
  e === s && s--;
250
117
  continue;
251
118
  }
252
- const i = Object.getOwnPropertyNames(t);
253
- for (let r = i.length - 1; r >= 0; r--) {
254
- const c = i[r];
119
+ const u = Object.getOwnPropertyNames(r);
120
+ for (let t = u.length - 1; t >= 0; t--) {
121
+ const c = u[t];
255
122
  if (c === "__proto__" || c === "constructor") continue;
256
123
  if (!n[c]) {
257
124
  o = o || e !== s;
258
- const r = Object.getOwnPropertyDescriptor(t, c);
259
- n[c] = r.get ? {
125
+ const t = Object.getOwnPropertyDescriptor(r, c);
126
+ n[c] = t.get ? {
260
127
  enumerable: true,
261
128
  configurable: true,
262
- get: r.get.bind(t)
263
- } : r;
129
+ get: t.get.bind(r)
130
+ } : t;
264
131
  }
265
132
  }
266
133
  }
267
- if (!o) return r[s];
268
- const i = {};
134
+ if (!o) return t[s];
135
+ const u = {};
269
136
  const c = Object.keys(n);
270
137
  for (let e = c.length - 1; e >= 0; e--) {
271
- const t = c[e], r = n[t];
272
- if (r.get) Object.defineProperty(i, t, r); else i[t] = r.value;
138
+ const r = c[e], t = n[r];
139
+ if (t.get) Object.defineProperty(u, r, t); else u[r] = t.value;
273
140
  }
274
- i[$SOURCES] = r;
275
- return i;
141
+ u[$SOURCES] = t;
142
+ return u;
276
143
  }
277
144
 
278
145
  /**
@@ -299,30 +166,36 @@ const $SOURCES = Symbol(0);
299
166
  * );
300
167
  * }
301
168
  * ```
302
- */ function omit(e, ...t) {
169
+ */ function omit(e, ...r) {
303
170
  if (SUPPORTS_PROXY && $PROXY in e) {
304
171
  return new Proxy({
305
- get(r) {
306
- return t.includes(r) ? undefined : e[r];
172
+ get(t) {
173
+ // $SOURCES must not tunnel through the filter: merge() flattens
174
+ // whatever answers it, so forwarding would hand a re-merge the
175
+ // UNFILTERED sources of an underlying merge proxy and the omitted
176
+ // keys leak back in (#3014 — the SSR element-spread path re-merges
177
+ // static attributes with the rest object). Opaque here: merge
178
+ // composes omit proxies through their traps instead.
179
+ return t === $SOURCES || r.includes(t) ? undefined : e[t];
307
180
  },
308
- has(r) {
309
- return !t.includes(r) && r in e;
181
+ has(t) {
182
+ return t !== $SOURCES && !r.includes(t) && t in e;
310
183
  },
311
184
  keys() {
312
- return ownEnumerableKeys(e).filter(e => !t.includes(e));
185
+ return ownEnumerableKeys(e).filter(e => !r.includes(e));
313
186
  }
314
187
  }, propTraps);
315
188
  }
316
- const r = {};
189
+ const t = {};
317
190
  const n = Object.getOwnPropertyNames(e);
318
- const o = t.length > 4 && n.length > t.length ? new Set(t) : undefined;
191
+ const o = r.length > 4 && n.length > r.length ? new Set(r) : undefined;
319
192
  for (const s of n) {
320
- if (o ? !o.has(s) : !t.includes(s)) {
321
- const t = Object.getOwnPropertyDescriptor(e, s);
322
- !t.get && !t.set && t.enumerable && t.writable && t.configurable ? r[s] = t.value : Object.defineProperty(r, s, t);
193
+ if (o ? !o.has(s) : !r.includes(s)) {
194
+ const r = Object.getOwnPropertyDescriptor(e, s);
195
+ !r.get && !r.set && r.enumerable && r.writable && r.configurable ? t[s] = r.value : Object.defineProperty(t, s, r);
323
196
  }
324
197
  }
325
- return r;
198
+ return t;
326
199
  }
327
200
 
328
- export { deep, merge, omit, snapshot };
201
+ export { merge, omit };
@@ -0,0 +1,52 @@
1
+ import type { Computed, Signal } from "./types.js";
2
+ /**
3
+ * Dev-only observability hook points for the reactive core.
4
+ *
5
+ * Core's obligation is to call these with true facts at the moments they
6
+ * happen; ALL attribution semantics (stamps, cause chains, timings, warnings)
7
+ * live in the engine that installs them (attribution.ts — same pattern as the
8
+ * GlobalQueue._* feature slots). `attrHooks` is null unless an engine is
9
+ * installed, so the disabled cost is one null check per site, and prod builds
10
+ * fold every site out behind __DEV__.
11
+ *
12
+ * IMPORTANT for implementers of call sites: a hook call must never sit inside
13
+ * a `try` block — rollup's tryCatchDeoptimization retains functions referenced
14
+ * inside `try` even behind a folded __DEV__ guard, which re-couples the dev
15
+ * engine into prod bundles (#2883 harness). Set a local flag inside the try
16
+ * and call the hook after the catch.
17
+ */
18
+ export interface AttributionHooks {
19
+ /**
20
+ * A recompute is starting; `el._deps` still holds the previous run's links.
21
+ * Always paired with `recomputeEnd` (recompute has no early returns).
22
+ */
23
+ recomputeStart(el: Computed<any>, create: boolean): void;
24
+ /**
25
+ * The recompute finished. `changed` = committed a changed value (false for
26
+ * errored runs); `optimistic` = ran under an optimistic lane / lane-dirty
27
+ * posture; `transition` = a transition was active or owns this node;
28
+ * `held` = the value went to `_pendingValue` (a transition hold) rather
29
+ * than committing directly — its reveal happens later on the transition's
30
+ * own schedule.
31
+ */
32
+ recomputeEnd(el: Computed<any>, create: boolean, changed: boolean, optimistic: boolean, transition: boolean, held: boolean): void;
33
+ /** A non-effect computed committed a changed value during a re-run. */
34
+ derivedChanged(el: Computed<any>): void;
35
+ /** A signal write committed (value passed the equality gate). */
36
+ write(el: Signal<any> | Computed<any>, prev: unknown, value: unknown): void;
37
+ /** refresh() invalidated this node (self-invalidation, no dep changed). */
38
+ refreshed(el: Computed<any>): void;
39
+ /** An async landing is about to apply its value (before any branch). */
40
+ asyncStart(el: Computed<any>): void;
41
+ /**
42
+ * The async landing finished. `direct` = the landing applies the value
43
+ * itself (lane/override paths); false = it went through setSignal, whose
44
+ * own `write` hook already saw any committed change. Fired whether or not
45
+ * the landing committed — call sites cannot carry that fact out of their
46
+ * try blocks (see the try rule above), so the engine derives committed-ness
47
+ * from the node's state against its asyncStart snapshot.
48
+ */
49
+ asyncEnd(el: Computed<any>, prev: unknown, value: unknown, direct: boolean): void;
50
+ }
51
+ export declare let attrHooks: AttributionHooks | null;
52
+ export declare function setAttributionHooks(hooks: AttributionHooks | null): void;
@@ -0,0 +1,186 @@
1
+ import type { Computed } from "./types.js";
2
+ /**
3
+ * Dev-mode "why did this run" attribution.
4
+ *
5
+ * The runtime already knows the full dependency set of every scope; this
6
+ * module surfaces it. Every value commit stamps its node with a ChangeRecord
7
+ * (a write, an async landing, a refresh() invalidation, or a derived change
8
+ * whose `causes` chain back to root writes). When a computation re-executes,
9
+ * the deps whose stamp is newer than the node's last run are its causes, so
10
+ * each re-run can be explained as a chain down to the originating write:
11
+ *
12
+ * [why-run] effect "docTitle" ran (run 4)
13
+ * ← memo "userLabel" changed (#6)
14
+ * ← signal "notifications" write (#5) 2 → 3
15
+ *
16
+ * This module is the attribution ENGINE: all semantics live here, and it is
17
+ * decoupled from the core. `enable()` installs it into the core's narrow
18
+ * dev-only hook points (attribution-hooks.ts); core's only obligation is to
19
+ * call those hooks with true facts. Disabled cost is one null check per hook
20
+ * site; prod builds fold the sites out entirely. The same hook surface is the
21
+ * intended substrate for external consumers (devtools) — one mechanism, two
22
+ * front-ends.
23
+ */
24
+ export type ChangeKind = "write" | "derived" | "async" | "refresh";
25
+ export interface ChangeRecord {
26
+ /** Global monotonic change sequence — orders causes across the app. */
27
+ seq: number;
28
+ kind: ChangeKind;
29
+ name: string;
30
+ /** Short previews of the value transition (writes only). */
31
+ prev?: string;
32
+ value?: string;
33
+ /** First user frames of the triggering write's stack (opt-in). */
34
+ stack?: string[];
35
+ /** For derived changes: the upstream changes that produced this one. */
36
+ causes?: ChangeRecord[];
37
+ }
38
+ export interface RerunEvent {
39
+ /** Global monotonic run sequence. */
40
+ run: number;
41
+ /** How many times this node has re-run since attribution was enabled. */
42
+ nodeRuns: number;
43
+ nodeKind: "effect" | "memo";
44
+ nodeName: string;
45
+ node: Computed<any>;
46
+ /**
47
+ * The deps that changed since this node's previous run. Empty means the
48
+ * re-run was not triggered by a tracked value change (creation-adjacent
49
+ * pull, error retry, or a cause this prototype does not stamp yet).
50
+ */
51
+ causes: ChangeRecord[];
52
+ /** Dependency count after this run. */
53
+ depCount: number;
54
+ /** Names of deps this run subscribed to that the previous run did not. */
55
+ depsAdded: string[];
56
+ /** Names of deps the previous run had that this run dropped. */
57
+ depsRemoved: string[];
58
+ /** Wall time of this run excluding nested recomputes (ms). */
59
+ selfMs: number;
60
+ /** Wall time of this run including nested recomputes (ms). */
61
+ totalMs: number;
62
+ /**
63
+ * Whether the run committed a changed value. A PLAIN memo run with
64
+ * `changed: false` was pure waste — the equality cutoff stopped it from
65
+ * notifying anyone; an effect run with `changed: false` computed without
66
+ * firing its effect phase. Summed as `wastedMs` in costs() (plain,
67
+ * non-held runs only — see `phase`).
68
+ */
69
+ changed: boolean;
70
+ /**
71
+ * Which posture this run executed under. "optimistic" = under an
72
+ * optimistic lane (overlay recompute); "transition" = a transition was
73
+ * active or owns the node (the run may be replayed/settled later);
74
+ * "plain" = an ordinary committed run. Overlay runs are real work (they
75
+ * count toward time budgets) but are never blamed as waste, and costs()
76
+ * reports their time separately as `overlayMs`.
77
+ */
78
+ phase: "plain" | "transition" | "optimistic";
79
+ /**
80
+ * The changed value was held in `_pendingValue` (a transition hold) rather
81
+ * than committed directly; its reveal happens on the transition's own
82
+ * schedule. Held runs are excluded from waste accounting.
83
+ */
84
+ held: boolean;
85
+ }
86
+ export interface AttributionOptions {
87
+ /** Pretty-print each re-run to the console (default true). */
88
+ log?: boolean;
89
+ /** Capture the user stack frame of each write — slow (default false). */
90
+ stacks?: boolean;
91
+ /** Ring-buffer size for `history()` (default 200). */
92
+ historyLimit?: number;
93
+ /**
94
+ * Hot-scope warning: emit a diagnostic when one scope re-runs `count`
95
+ * times within `windowMs` (default 120 runs / 1000ms — deliberately above
96
+ * animation-frame cadence, so a legitimate rAF-driven scope at 60/s does
97
+ * not cry wolf). `false` disables.
98
+ */
99
+ hotRuns?: {
100
+ count: number;
101
+ windowMs: number;
102
+ } | false;
103
+ /**
104
+ * Wide-scope warning: emit a diagnostic when a scope's dependency count
105
+ * reaches this (default 30) — the coarse-read / helper-leak signature.
106
+ * Re-warns only if the count then grows by another 50%. `false` disables.
107
+ */
108
+ wideDeps?: number | false;
109
+ /**
110
+ * Time-budget warning: emit a diagnostic when one scope's summed self-time
111
+ * inside `windowMs` exceeds `budgetMs` (default 8ms / 1000ms — half a frame
112
+ * spent in one scope). Unlike `hotRuns` this catches the few-but-expensive
113
+ * scope that run counts miss. `false` disables.
114
+ */
115
+ hotTime?: {
116
+ budgetMs: number;
117
+ windowMs: number;
118
+ } | false;
119
+ /**
120
+ * Unstable-output warning: emit a diagnostic when a memo commits a
121
+ * referentially-new but shallowly-equivalent plain object/array on this
122
+ * many consecutive runs (default 4). Such a memo's equality gate never
123
+ * closes — every subscriber re-runs on every upstream change — which makes
124
+ * it a fan-out amplifier that is otherwise only findable by profiling.
125
+ * `false` disables.
126
+ */
127
+ unstableMemos?: number | false;
128
+ /**
129
+ * Written-fan-out warning: emit a diagnostic when a committed root
130
+ * invalidation (write, refresh, async landing) reaches a node with at
131
+ * least this many subscribers (default 250). Complements the always-on
132
+ * HUGE_FAN_OUT graph-size warning, specced against it deliberately:
133
+ * HUGE_FAN_OUT fires at LINK time from GRAPH_SIZE_WARN_AT (2000) up —
134
+ * static structure so large it warns even if never written — while this
135
+ * fires at WRITE time from a much lower bar, because fan-out only costs
136
+ * anything when the node actually changes. Once per node, re-warning only
137
+ * on 2x subscriber growth, so the two never spam the same node. `false`
138
+ * disables.
139
+ */
140
+ wideWrites?: number | false;
141
+ }
142
+ export interface ScopeCost {
143
+ name: string;
144
+ kind: "effect" | "memo";
145
+ runs: number;
146
+ selfMs: number;
147
+ /**
148
+ * Self-time of PLAIN, non-held runs that produced an unchanged value —
149
+ * the recoverable number. Overlay runs (optimistic/transition) are never
150
+ * counted here: an optimistic recompute landing back on the committed
151
+ * value is the mechanism working, not waste.
152
+ */
153
+ wastedMs: number;
154
+ /** Self-time spent in optimistic/transition (overlay) runs. */
155
+ overlayMs: number;
156
+ }
157
+ export interface WriteCost {
158
+ /** Root cause name (a signal write, async landing, or refresh target). */
159
+ name: string;
160
+ /** Number of downstream re-runs this root triggered. */
161
+ runs: number;
162
+ /** Summed self-time of every downstream re-run it caused. */
163
+ downstreamMs: number;
164
+ }
165
+ export declare function formatRerun(event: RerunEvent): string;
166
+ export interface Attribution {
167
+ enable(opts?: AttributionOptions): void;
168
+ disable(): void;
169
+ subscribe(listener: (event: RerunEvent) => void): () => void;
170
+ history(): readonly RerunEvent[];
171
+ /** Re-run history for one node — pass a memo/effect accessor or raw node. */
172
+ why(target: unknown): RerunEvent[];
173
+ /** Current dependency names of one scope — the devtools subscription view. */
174
+ subscriptions(target: unknown): string[];
175
+ /**
176
+ * Aggregated cost tables since enable(): `scopes` ranked by self-time
177
+ * (with `wastedMs` = time spent on unchanged-value runs), `writes` ranked
178
+ * by total downstream re-run time each root write caused.
179
+ */
180
+ costs(): {
181
+ scopes: ScopeCost[];
182
+ writes: WriteCost[];
183
+ };
184
+ format: typeof formatRerun;
185
+ }
186
+ export declare const attribution: Attribution;
@@ -18,6 +18,15 @@ export declare const REACTIVE_MANUAL_WRITE: number;
18
18
  * pending window does not read as pending (question-scoped pending model).
19
19
  */
20
20
  export declare const REACTIVE_REASK: number;
21
+ /**
22
+ * A dependency write landed while this subscriber was mid-recompute — a
23
+ * nested pull committed beneath one of its reads (#3037). The heap refuses
24
+ * RECOMPUTING nodes, so recompute's tail consumes this latch and reschedules:
25
+ * values the pass read before the nested commit are stale. Only set for
26
+ * links validated this pass (gen-current): a write to an untouched link is
27
+ * either re-read later in the pass (fresh) or trimmed with it (not a dep).
28
+ */
29
+ export declare const REACTIVE_MISSED_WAKE: number;
21
30
  export declare const CONFIG_OWNED_WRITE: number;
22
31
  export declare const CONFIG_NO_SNAPSHOT: number;
23
32
  export declare const CONFIG_TRANSPARENT: number;
@@ -25,6 +34,23 @@ export declare const CONFIG_IN_SNAPSHOT_SCOPE: number;
25
34
  export declare const CONFIG_CHILDREN_FORBIDDEN: number;
26
35
  export declare const CONFIG_AUTO_DISPOSE: number;
27
36
  export declare const CONFIG_SYNC: number;
37
+ export declare const CONFIG_OPTIMISTIC: number;
38
+ export declare const CONFIG_HAS_COMPANIONS: number;
39
+ export declare const CONFIG_HAS_SNAPSHOT: number;
40
+ export declare const CONFIG_HAS_LANE: number;
41
+ /** Set on a FIREWALL computed when any of its child signals creates an
42
+ * isPending()/latest() companion. Gates the post-recompute child-companion
43
+ * walk (#3038): a store computed's `_child` chain holds one node per
44
+ * materialized leaf, so walking it unconditionally makes every update cost
45
+ * O(all leaves ever read). Sticky — set at companion creation, never
46
+ * cleared; sync-only apps never set it and never pay the walk. */
47
+ export declare const CONFIG_CHILD_COMPANIONS: number;
48
+ /** Set on a computed when its first firewall child signal is installed
49
+ * (projection machinery). Gates markNode's firewall-children walk with one
50
+ * masked read of the always-present _config — the walk's old `_child` read
51
+ * moved into the cold extension (§12), and an unconditional `_x` deref per
52
+ * marked node measurably taxed the propagation hot path (diamond -22%). */
53
+ export declare const CONFIG_FW_CHILDREN: number;
28
54
  export declare const STATUS_NONE = 0;
29
55
  export declare const STATUS_PENDING: number;
30
56
  export declare const STATUS_ERROR: number;
@@ -1,6 +1,6 @@
1
1
  import { type Refreshable } from "./constants.js";
2
2
  import { type OptimisticLane } from "./lanes.js";
3
- import type { Computed, FirewallSignal, NodeOptions, Owner, Signal } from "./types.js";
3
+ import type { Computed, FirewallSignal, NodeExtension, NodeOptions, Owner, Signal } from "./types.js";
4
4
  export declare const PRIMITIVE_IN_FORBIDDEN_SCOPE_MESSAGE = "[PRIMITIVE_IN_FORBIDDEN_SCOPE] Cannot create reactive primitives inside createTrackedEffect or owner-backed onSettled";
5
5
  export declare const REACTIVE_WRITE_IN_OWNED_SCOPE_SIGNAL_MESSAGE: string;
6
6
  export declare const REACTIVE_WRITE_IN_OWNED_SCOPE_REFRESH_MESSAGE: string;
@@ -25,6 +25,13 @@ export declare function clearSnapshots(): void;
25
25
  export declare function recompute(el: Computed<any>, create?: boolean): void;
26
26
  export declare function computed<T>(fn: (prev?: T) => T | PromiseLike<T> | AsyncIterable<T>): Computed<T>;
27
27
  export declare function computed<T>(fn: (prev: T) => T | PromiseLike<T> | AsyncIterable<T>, options?: NodeOptions<T>): Computed<T>;
28
+ /** Lazily allocate a node's cold extension (ONE shape for signals and
29
+ * computeds — `_x` access stays monomorphic). Installers write through
30
+ * this; hot paths read `el._x?._field` gated by the _config presence bits.
31
+ * Never call ext() just to store a field's default. */
32
+ export declare function ext(el: {
33
+ _x: NodeExtension | null;
34
+ }): NodeExtension;
28
35
  /**
29
36
  * Build an Effect node with all effect-specific fields baked into a single object literal,
30
37
  * so V8 sees the full hidden class shape at construction time. Effects always run in lazy
@@ -88,6 +95,14 @@ export declare const READ_SLOW: unique symbol;
88
95
  */
89
96
  export declare function readNodeFast<T>(el: Signal<T>): T | typeof READ_SLOW;
90
97
  export declare function read<T>(el: Signal<T> | Computed<T>): T;
98
+ /**
99
+ * Store-rewrite setter guard: the rewrite parks writes in a pending backing
100
+ * (no setSignal at write time), so the owned-scope write protection must
101
+ * fire at the setter entry instead. Mirrors setSignal's guard condition
102
+ * minus the node-specific exemptions (ownedWrite/firewall), which don't
103
+ * apply to plain store setters.
104
+ */
105
+ export declare function devGuardStoreSetterWrite(): void;
91
106
  export declare function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)): T;
92
107
  /**
93
108
  * Suppresses automatic recomputation of `el` until the scheduler drains. Used