@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,5 +1,5 @@
1
- import { STORE_SNAPSHOT_PROPS, type Computed, type Refreshable, type Signal } from "../core/index.js";
2
- import { type Transition } from "../core/scheduler.js";
1
+ import { type Signal } from "../core/index.js";
2
+ import type { Refreshable } from "../core/index.js";
3
3
  /** A read-only view of a store's value as seen by consumers. Mutate it via the paired `StoreSetter`. */
4
4
  export type Store<T> = Readonly<T>;
5
5
  /**
@@ -58,21 +58,14 @@ type DataNodes = Record<PropertyKey, DataNode>;
58
58
  * @internal
59
59
  */
60
60
  export declare const $TRACK: unique symbol, $TARGET: unique symbol, $PROXY: unique symbol, $DELETED: unique symbol, $AFFECTS: unique symbol;
61
- export declare const STORE_VALUE = "v", STORE_OVERRIDE = "o", STORE_OPTIMISTIC_OVERRIDE = "x", STORE_NODE = "n", STORE_HAS = "h", STORE_CUSTOM_PROTO = "c", STORE_WRAP = "w", STORE_LOOKUP = "l", STORE_FIREWALL = "f", STORE_OPTIMISTIC = "p", STORE_OPTIMISTIC_OWNERS = "t", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
61
+ export declare const STORE_VALUE = "v", STORE_NODE = "n", STORE_HAS = "h", STORE_PARENT = "u", STORE_DESC = "d", STORE_SHALLOW = "s";
62
+ /** Structural view of a store target as shared machinery sees it (the real
63
+ * shape is `StoreNextTarget` in ./next/target.ts). */
62
64
  export type StoreNode = {
63
65
  [$PROXY]: any;
64
66
  [STORE_VALUE]: Record<PropertyKey, any>;
65
- [STORE_OVERRIDE]?: Record<PropertyKey, any>;
66
- [STORE_OPTIMISTIC_OVERRIDE]?: Record<PropertyKey, any>;
67
- [STORE_OPTIMISTIC_OWNERS]?: Record<PropertyKey, Transition | null>;
68
67
  [STORE_NODE]?: DataNodes;
69
68
  [STORE_HAS]?: DataNodes;
70
- [STORE_CUSTOM_PROTO]?: boolean;
71
- [STORE_WRAP]?: (value: any, target?: StoreNode) => any;
72
- [STORE_LOOKUP]?: WeakMap<any, any>;
73
- [STORE_FIREWALL]?: Computed<any>;
74
- [STORE_OPTIMISTIC]?: boolean;
75
- [STORE_SNAPSHOT_PROPS]?: Record<PropertyKey, any>;
76
69
  [STORE_PARENT]?: StoreNode;
77
70
  [STORE_SHALLOW]?: boolean;
78
71
  [STORE_DESC]?: boolean;
@@ -82,10 +75,6 @@ export declare namespace SolidStore {
82
75
  }
83
76
  }
84
77
  export type NotWrappable = string | number | bigint | symbol | boolean | Function | null | undefined | SolidStore.Unwrappable[keyof SolidStore.Unwrappable];
85
- export declare function createStoreProxy<T extends object>(value: T, traps?: ProxyHandler<StoreNode>, extend?: (target: StoreNode) => void): any;
86
- export declare const storeLookup: WeakMap<WeakKey, any>;
87
- export declare const symbolKeyedRecords: WeakSet<object>;
88
- export declare function lookupTarget(value: any, lookup?: WeakMap<any, any>): StoreNode | undefined;
89
78
  /**
90
79
  * Marks a value as raw: no store will ever wrap it — every store presents it
91
80
  * as-is, tracked by reference at whatever slot holds it and updated by
@@ -96,25 +85,33 @@ export declare function lookupTarget(value: any, lookup?: WeakMap<any, any>): St
96
85
  export declare let rawValuesUsed: boolean;
97
86
  export declare function isRawValue(value: any): boolean;
98
87
  export declare function markRaw<T>(value: T): T;
88
+ export declare function markRawOne(v: any): void;
99
89
  export declare function markRawIngest(container: any): void;
100
- export declare function wrap<T extends Record<PropertyKey, any>>(value: T, target?: StoreNode): T;
101
- export declare function wrapShallow<T extends Record<PropertyKey, any>>(value: T): T;
102
90
  export declare function isWrappable<T>(obj: T | NotWrappable): obj is T;
103
91
  export declare function setWriteOverride(value: boolean): void;
92
+ export declare function getWriteOverride(): boolean;
104
93
  export declare function ownEnumerableKeys(o: object): (string | symbol)[];
105
94
  /**
106
- * Single chokepoint for the store's layered value resolution: returns the
107
- * override layer (optimistic first, then regular) that shadows `property`, or
108
- * `undefined` when the base `STORE_VALUE` is authoritative. Every trap must
109
- * resolve through this hand-inlining the layer order is how the optimistic
110
- * layer gets missed (#2850).
95
+ * Scope inheritance for late-created nodes: every live mark whose identity
96
+ * scope contains the owning record's raw — and, for keyed marks, whose key
97
+ * is this property gets counted on the new node. Inherited marks live
98
+ * exactly as long as the scope's carrier the release hook below drops
99
+ * them with the entry.
111
100
  */
112
- export declare function getOverlayLayer(target: StoreNode, property: PropertyKey): Record<PropertyKey, any> | undefined;
113
- /**
114
- * The value a store leaf's backing signal currently shows to readers: active
115
- * override, else held pending value, else committed value.
116
- */
117
- export declare function visibleNodeValue(node: DataNode): any;
101
+ export declare function inheritAffectsMarks(node: DataNode, raw: object, property: PropertyKey): void;
102
+ /** Next-store node factory for affects carriers/slots: injected by the
103
+ * rewrite module (next targets alias the legacy field names, so everything
104
+ * here EXCEPT node creation works on them structurally). */
105
+ export declare let nextAffectsNodeResolver: ((target: any, key: PropertyKey) => DataNode) | null;
106
+ export declare function setNextAffectsNodeResolver(fn: (target: any, key: PropertyKey) => DataNode): void;
107
+ /** Next-store optimistic view for the declaration walk (optimistic rows
108
+ * pushed before the declaration are in motion too — legacy reads its write
109
+ * overlays; next composes armed-node overrides). */
110
+ export declare let nextOptimisticViewResolver: ((target: any, raw: any) => any) | null;
111
+ export declare function setNextOptimisticViewResolver(fn: (target: any, raw: any) => any): void;
112
+ /** @internal birth inheritance for nodes created inside a live mark window —
113
+ * exported for the rewrite's node factories. */
114
+ export declare function affectsScopesLive(): boolean;
118
115
  /**
119
116
  * Witness live mark coverage of a record into the active isPending() probe.
120
117
  * Tracked reads don't need this — they go through real signal nodes, which
@@ -138,76 +135,4 @@ export declare function witnessAffectsMark(target: StoreNode, property?: Propert
138
135
  * @internal
139
136
  */
140
137
  export declare function getStoreAffectsNodes(target: StoreNode, key?: PropertyKey): DataNode[];
141
- export declare function trackSelf(target: StoreNode, symbol?: symbol): void;
142
- export declare function notifySelf(target: StoreNode): void;
143
- /**
144
- * The write overlay a walk must read through: optimistic writes shadow
145
- * regular pending writes, the same resolution order as every proxy trap and
146
- * `reconcile` (#2850). Merging allocates only in the rare both-present case
147
- * (a derived optimistic store with an in-flight projection commit).
148
- */
149
- export declare function mergedOverlay(target: StoreNode): Record<PropertyKey, any> | undefined;
150
- export declare function getKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, enumerable?: boolean): PropertyKey[];
151
- export declare function getStoreKeys(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined): PropertyKey[];
152
- export declare function getStoreSymbols(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined): symbol[];
153
- export declare function getPropertyDescriptor(source: Record<PropertyKey, any>, override: Record<PropertyKey, any> | undefined, property: PropertyKey): PropertyDescriptor | undefined;
154
- export declare const storeTraps: ProxyHandler<StoreNode>;
155
- export declare function storeSetter<T extends object>(store: Store<T>, fn: (draft: T) => T | void): void;
156
- /**
157
- * Creates a deeply-reactive store backed by a Proxy. Reads track each property
158
- * accessed; only the parts that change trigger updates.
159
- *
160
- * Store properties hold **plain values**, not accessors. The proxy already
161
- * tracks reads per-property — wrapping a value in `() => state.foo` produces
162
- * a getter that *won't* track when called, which looks like a reactivity bug
163
- * but is just a category error. If you have a signal-shaped piece of state,
164
- * make it a property of the store (`{ foo: 1 }`) rather than nesting an
165
- * accessor inside (`{ foo: () => signal() }`).
166
- *
167
- * The setter takes a **draft-mutating** function — mutate the draft in place
168
- * (canonical). The callback may also return a new value: arrays are replaced
169
- * by index (length adjusted), objects are shallow-diffed at the top level
170
- * (keys present in the returned value are written, missing keys deleted). Use
171
- * the return form for shapes where mutation is awkward — most commonly
172
- * removing items via `filter`. The setter does **not** do keyed reconciliation;
173
- * for that, use the derived/projection form (or `createProjection`).
174
- *
175
- * - Plain form: `createStore(initialValue)` — wraps a value in a reactive
176
- * proxy.
177
- * - Derived form: `createStore(fn, seed, options?)` — a *projection store*
178
- * whose contents are computed by `fn(draft)`. `fn` may be sync, async, or
179
- * an `AsyncIterable`; the projection's result reconciles against the
180
- * existing store by `options.key` (default `"id"`) for stable identity.
181
- *
182
- * @example
183
- * ```ts
184
- * const [state, setState] = createStore({
185
- * user: { name: "Ada", age: 36 },
186
- * todos: [] as { id: string; text: string; done: boolean }[]
187
- * });
188
- *
189
- * // Canonical: mutate the draft in place.
190
- * setState(s => { s.user.age = 37; });
191
- * setState(s => { s.todos.push({ id: "1", text: "x", done: false }); });
192
- *
193
- * // Return form: reach for it when mutation is awkward.
194
- * setState(s => s.todos.filter(t => !t.done)); // remove items
195
- * setState(s => ({ ...s, user: { name: "Grace", age: 85 } })); // shallow replace
196
- * ```
197
- *
198
- * @example
199
- * ```ts
200
- * // Derived store — auto-fetches & reconciles by `id`.
201
- * const [users] = createStore(
202
- * async () => fetch("/users").then(r => r.json()),
203
- * [] as User[]
204
- * );
205
- * ```
206
- *
207
- * @returns `[store: Store<T>, setStore: StoreSetter<T>]`
208
- */
209
- export declare function createStore<T extends object = {}>(store: NoFn<T> | Store<NoFn<T>>, options?: StoreOptions & {
210
- shallow?: boolean;
211
- }): StoreReturn<T>;
212
- export declare function createStore<T extends object = {}>(fn: (store: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, store: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): ProjectionStoreReturn<T>;
213
138
  export {};
@@ -1,43 +1,3 @@
1
- /**
2
- * Returns a plain (non-proxy, non-reactive) deep copy of a store value.
3
- * Reading via `snapshot` does **not** subscribe to changes — use this when you
4
- * need to hand a stable plain object to non-reactive code (logging,
5
- * serialization, structured-clone, network payloads, etc.).
6
- *
7
- * Returns the original object identity for any sub-tree that wasn't modified
8
- * relative to the proxy's underlying source.
9
- *
10
- * @example
11
- * ```ts
12
- * const [state] = createStore({ user: { name: "Ada" }, todos: [] });
13
- *
14
- * console.log(JSON.stringify(snapshot(state))); // safe, non-reactive copy
15
- * ```
16
- */
17
- export declare function snapshot<T>(item: T): T;
18
- export declare function snapshot<T>(item: T, map?: Map<unknown, unknown>, lookup?: WeakMap<any, any>): T;
19
- /**
20
- * Returns a plain (non-proxy) deep copy **and** subscribes the current
21
- * tracking scope to every nested change in the source store. Any write
22
- * anywhere in the subtree invalidates the consumer.
23
- *
24
- * Use this when you need plain data inside a reactive scope and want to
25
- * react to deep mutations (e.g. passing a snapshot to `reconcile()` or to a
26
- * memo that should rerun on any nested change). For most read paths, prefer
27
- * direct property access — Solid stores already track per-property reads
28
- * with no `deep()` wrapper needed.
29
- *
30
- * @example
31
- * ```ts
32
- * const [state] = createStore({ a: { b: { c: 1 } } });
33
- *
34
- * createEffect(
35
- * () => deep(state), // reruns on any nested change
36
- * plain => sendToWorker(plain) // worker gets a non-proxy copy
37
- * );
38
- * ```
39
- */
40
- export declare function deep<T extends object>(store: T): T;
41
1
  type DistributeOverride<T, F> = T extends undefined ? F : T;
42
2
  type Override<T, U> = T extends any ? U extends any ? {
43
3
  [K in keyof T]: K extends keyof U ? DistributeOverride<U[K], T[K]> : T[K];
@@ -0,0 +1,52 @@
1
+ import type { Computed, Signal } from "./types.cjs";
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.cjs";
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.cjs";
2
2
  import { type OptimisticLane } from "./lanes.cjs";
3
- import type { Computed, FirewallSignal, NodeOptions, Owner, Signal } from "./types.cjs";
3
+ import type { Computed, FirewallSignal, NodeExtension, NodeOptions, Owner, Signal } from "./types.cjs";
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
@@ -1,4 +1,5 @@
1
- import type { Computed, Owner, Signal } from "./types.cjs";
1
+ import { type Attribution } from "./attribution.cjs";
2
+ import type { Computed, Link, Owner, Signal } from "./types.cjs";
2
3
  export interface DevHooks {
3
4
  onOwner?: (owner: Owner) => void;
4
5
  onGraph?: (value: any, owner: Owner | null) => void;
@@ -6,8 +7,12 @@ export interface DevHooks {
6
7
  onStoreNodeUpdate?: (state: any, property: PropertyKey, value: any, prev: any) => void;
7
8
  }
8
9
  export type DiagnosticSeverity = "warn" | "error";
9
- export type DiagnosticCode = "STRICT_READ_UNTRACKED" | "PENDING_ASYNC_UNTRACKED_READ" | "PENDING_ASYNC_FORBIDDEN_SCOPE" | "REACTIVE_WRITE_IN_OWNED_SCOPE" | "ACTION_CALLED_IN_OWNED_SCOPE" | "RUN_WITH_DISPOSED_OWNER" | "NO_OWNER_CLEANUP" | "CLEANUP_IN_FORBIDDEN_SCOPE" | "SETTLED_CLEANUP_UNOWNED" | "PRIMITIVE_IN_FORBIDDEN_SCOPE" | "NO_OWNER_EFFECT" | "NO_OWNER_BOUNDARY" | "ASYNC_OUTSIDE_LOADING_BOUNDARY" | "INVALID_REFRESH_TARGET" | "INVALID_AFFECTS_TARGET" | "MISSING_EFFECT_FN" | "SYNC_NODE_RECEIVED_ASYNC" | "REACTIVITY_HALTED" | "INVARIANT_VIOLATION";
10
- export type DiagnosticKind = "strict-read" | "async" | "write" | "lifecycle" | "owner" | "error";
10
+ export type DiagnosticCode = "STRICT_READ_UNTRACKED" | "PENDING_ASYNC_UNTRACKED_READ" | "PENDING_ASYNC_FORBIDDEN_SCOPE" | "REACTIVE_WRITE_IN_OWNED_SCOPE" | "ACTION_CALLED_IN_OWNED_SCOPE" | "RUN_WITH_DISPOSED_OWNER" | "NO_OWNER_CLEANUP" | "CLEANUP_IN_FORBIDDEN_SCOPE" | "SETTLED_CLEANUP_UNOWNED" | "FLUSH_IN_EFFECT_CALLBACK" | "PRIMITIVE_IN_FORBIDDEN_SCOPE" | "NO_OWNER_EFFECT" | "NO_OWNER_BOUNDARY" | "ASYNC_OUTSIDE_LOADING_BOUNDARY" | "INVALID_REFRESH_TARGET" | "INVALID_AFFECTS_TARGET" | "MISSING_EFFECT_FN" | "SYNC_NODE_RECEIVED_ASYNC" | "REACTIVITY_HALTED" | "INVARIANT_VIOLATION" | "HUGE_FAN_OUT" | "HUGE_FAN_IN" | "HOT_SCOPE_RERUNS" | "HOT_SCOPE_TIME" | "WIDE_SCOPE_DEPS" | "UNSTABLE_MEMO_OUTPUT" | "WIDE_WRITE";
11
+ export type DiagnosticKind = "strict-read" | "async" | "write" | "lifecycle" | "owner" | "error" | "perf" | "graph";
12
+ /** First warning when a node's live edge count reaches this size. */
13
+ export declare const GRAPH_SIZE_WARN_AT = 2000;
14
+ /** Repeat the warning at this interval after the first. */
15
+ export declare const GRAPH_SIZE_WARN_EVERY = 500;
11
16
  export interface DiagnosticEvent {
12
17
  sequence: number;
13
18
  code: DiagnosticCode;
@@ -32,6 +37,8 @@ export interface Diagnostics {
32
37
  export interface Dev {
33
38
  hooks: DevHooks;
34
39
  diagnostics: Diagnostics;
40
+ /** "Why did this run" re-run attribution — see attribution.ts. */
41
+ attribution: Attribution;
35
42
  getChildren: typeof getChildren;
36
43
  getSignals: typeof getSignals;
37
44
  getParent: typeof getParent;
@@ -62,3 +69,13 @@ export declare function getSignals(owner: Owner): any[];
62
69
  export declare function getParent(owner: Owner): Owner | null;
63
70
  export declare function getSources(computation: Computed<any>): (Signal<any> | Computed<any>)[];
64
71
  export declare function getObservers(node: Signal<any> | Computed<any>): Computed<any>[];
72
+ /**
73
+ * DEV-only: bump live edge counts after a new graph link and warn when a
74
+ * node grows an unusually large fan-out (many subscribers on one source) or
75
+ * fan-in (many sources on one computation). Repeat-reads that `link()`
76
+ * dedupes never reach here. Always-on in dev — unlike the opt-in attribution
77
+ * engine, a graph-size pathology should surface without asking.
78
+ */
79
+ export declare function noteGraphLink(dep: Signal<any> | Computed<any>, sub: Computed<any>): void;
80
+ /** DEV-only: drop live edge counts when a link is removed. */
81
+ export declare function unnoteGraphLink(link: Link): void;
@@ -1,5 +1,6 @@
1
1
  import type { Computed, Link, Signal } from "./types.cjs";
2
2
  export declare function unlinkSubs(link: Link): Link | null;
3
3
  export declare function trimStaleDeps(el: Computed<any>): void;
4
+ export declare function clearDeps(el: Computed<unknown>): void;
4
5
  export declare function unobserved(el: Computed<unknown>): void;
5
6
  export declare function link(dep: Signal<any> | Computed<any>, sub: Computed<any>, pendingObserver?: boolean): void;
@@ -31,26 +31,14 @@ export declare function mergeLanes(lane1: OptimisticLane, lane2: OptimisticLane)
31
31
  /**
32
32
  * Resolve a node's lane: follow union-find chain, verify active, clear if stale.
33
33
  */
34
- export declare function resolveLane(el: {
35
- _optimisticLane?: OptimisticLane;
36
- }): OptimisticLane | undefined;
37
- export declare function resolveTransition(el: {
38
- _optimisticLane?: OptimisticLane;
39
- _transition?: Transition | null;
40
- _overrideValue?: any;
41
- _overrideOwner?: Transition | null;
42
- }): Transition | null | undefined;
34
+ export declare function resolveLane(el: Signal<any> | Computed<any>): OptimisticLane | undefined;
35
+ export declare function resolveTransition(el: Signal<any> | Computed<any>): Transition | null | undefined;
43
36
  /**
44
37
  * Check if a node has an active optimistic override.
45
38
  */
46
- export declare function hasActiveOverride(el: {
47
- _overrideValue?: any;
48
- }): boolean;
39
+ export declare function hasActiveOverride(el: Signal<any> | Computed<any>): boolean;
49
40
  /**
50
41
  * Assign or merge a lane onto a node. At convergence points (node already has
51
42
  * a different active lane), merge unless the node has an active override.
52
43
  */
53
- export declare function assignOrMergeLane(el: {
54
- _optimisticLane?: OptimisticLane;
55
- _overrideValue?: any;
56
- }, sourceLane: OptimisticLane): void;
44
+ export declare function assignOrMergeLane(el: Signal<any> | Computed<any>, sourceLane: OptimisticLane): void;