@solidjs/signals 2.0.0-rc.1 → 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 (50) hide show
  1. package/dist/dev.js +1661 -361
  2. package/dist/node.cjs +1939 -1331
  3. package/dist/prod/affects.js +16 -16
  4. package/dist/prod/boundaries.js +90 -90
  5. package/dist/prod/core/action.js +3 -3
  6. package/dist/prod/core/async.js +74 -72
  7. package/dist/prod/core/constants.js +39 -1
  8. package/dist/prod/core/core.js +332 -224
  9. package/dist/prod/core/effect.js +56 -56
  10. package/dist/prod/core/external.js +4 -4
  11. package/dist/prod/core/graph.js +65 -54
  12. package/dist/prod/core/heap.js +52 -44
  13. package/dist/prod/core/invariants.js +3 -2
  14. package/dist/prod/core/lanes.js +41 -34
  15. package/dist/prod/core/optimistic.js +63 -60
  16. package/dist/prod/core/owner.js +97 -96
  17. package/dist/prod/core/scheduler.js +243 -194
  18. package/dist/prod/core/verdict.js +184 -77
  19. package/dist/prod/map.js +104 -104
  20. package/dist/prod/signals.js +1 -1
  21. package/dist/prod/store/next/optimistic.js +31 -23
  22. package/dist/prod/store/next/projection.js +3 -3
  23. package/dist/prod/store/next/reconcile.js +78 -74
  24. package/dist/prod/store/next/store.js +357 -90
  25. package/dist/prod/store/store.js +7 -7
  26. package/dist/types/core/attribution-hooks.d.ts +52 -0
  27. package/dist/types/core/attribution.d.ts +186 -0
  28. package/dist/types/core/constants.d.ts +26 -0
  29. package/dist/types/core/core.d.ts +8 -1
  30. package/dist/types/core/dev.d.ts +20 -3
  31. package/dist/types/core/graph.d.ts +1 -0
  32. package/dist/types/core/lanes.d.ts +4 -16
  33. package/dist/types/core/scheduler.d.ts +8 -0
  34. package/dist/types/core/types.d.ts +85 -41
  35. package/dist/types/store/next/projection.d.ts +0 -16
  36. package/dist/types/store/next/store.d.ts +6 -0
  37. package/dist/types/store/next/target.d.ts +18 -0
  38. package/dist/types-cjs/core/attribution-hooks.d.cts +52 -0
  39. package/dist/types-cjs/core/attribution.d.cts +186 -0
  40. package/dist/types-cjs/core/constants.d.cts +26 -0
  41. package/dist/types-cjs/core/core.d.cts +8 -1
  42. package/dist/types-cjs/core/dev.d.cts +20 -3
  43. package/dist/types-cjs/core/graph.d.cts +1 -0
  44. package/dist/types-cjs/core/lanes.d.cts +4 -16
  45. package/dist/types-cjs/core/scheduler.d.cts +8 -0
  46. package/dist/types-cjs/core/types.d.cts +85 -41
  47. package/dist/types-cjs/store/next/projection.d.cts +0 -16
  48. package/dist/types-cjs/store/next/store.d.cts +6 -0
  49. package/dist/types-cjs/store/next/target.d.cts +18 -0
  50. package/package.json +1 -1
@@ -138,8 +138,8 @@ function ownEnumerableKeys(e) {
138
138
  */ function inheritAffectsMarks(e, t, o) {
139
139
  // A live scope exists, so affects.ts already installed the mark engine.
140
140
  for (const [r, s] of affectsScopes) {
141
- if (r.t && s.scope.has(t) && (s.key === undefined || s.key === o)) {
142
- GlobalQueue.M(e);
141
+ if (r.o?.t && s.scope.has(t) && (s.key === undefined || s.key === o)) {
142
+ GlobalQueue.h(e);
143
143
  s.inherited.push(e);
144
144
  }
145
145
  }
@@ -252,18 +252,18 @@ s) {
252
252
  // Callers guard on `pendingCheckActive`, which only flips inside
253
253
  // isPending() — the verdict layer is loaded and its hook installed.
254
254
  const o = e[STORE_NODE]?.[$AFFECTS];
255
- if (o?.t) GlobalQueue.Lt(o);
255
+ if (o?.o?.t) GlobalQueue.Bt(o);
256
256
  if (affectsScopes.size) {
257
257
  // Chained backings (§7b): a wrapper's STORE_VALUE can be another store's
258
258
  // proxy — marks cover by identity of the BASE raw, so resolve the chain
259
259
  // and check every identity along it.
260
260
  let r = e[STORE_VALUE];
261
261
  for (const [e, s] of affectsScopes) {
262
- if (e !== o && e.t && (s.key === undefined || s.key === t)) {
262
+ if (e !== o && e.o?.t && (s.key === undefined || s.key === t)) {
263
263
  let t = r;
264
264
  for (;;) {
265
265
  if (s.scope.has(t)) {
266
- GlobalQueue.Lt(e);
266
+ GlobalQueue.Bt(e);
267
267
  break;
268
268
  }
269
269
  const o = t?.[$TARGET];
@@ -288,11 +288,11 @@ s) {
288
288
  *
289
289
  * @internal
290
290
  */ function getStoreAffectsNodes(e, t) {
291
- GlobalQueue.p ||= e => {
291
+ GlobalQueue.G ||= e => {
292
292
  const t = affectsScopes.get(e);
293
293
  if (!t) return;
294
294
  affectsScopes.delete(e);
295
- for (let e = 0; e < t.inherited.length; e++) GlobalQueue.h(t.inherited[e]);
295
+ for (let e = 0; e < t.inherited.length; e++) GlobalQueue.j(t.inherited[e]);
296
296
  };
297
297
  if (t === undefined) {
298
298
  const t = nextAffectsNodeResolver(e, $AFFECTS);
@@ -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
@@ -1,4 +1,5 @@
1
- import type { Computed, Owner, Signal } from "./types.js";
1
+ import { type Attribution } from "./attribution.js";
2
+ import type { Computed, Link, Owner, Signal } from "./types.js";
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" | "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";
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.js";
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;
@@ -97,6 +97,7 @@ export declare class GlobalQueue extends Queue {
97
97
  static _applyReask: ((el: Computed<any>, hadReask: boolean) => boolean) | null;
98
98
  static _repollVerdicts: ((el: Computed<any>, snap?: boolean) => void) | null;
99
99
  static _witnessAffects: ((node: OptimisticNode) => void) | null;
100
+ static _wakeSuppressedProbes: ((transition: Transition) => void) | null;
100
101
  static _optimisticWrite: (<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)) => T) | null;
101
102
  static _resolveOptimistic: ((nodes: OptimisticNode[]) => void) | null;
102
103
  static _transitionBlocked: ((transition: Transition) => boolean) | null;
@@ -114,6 +115,13 @@ export declare class GlobalQueue extends Queue {
114
115
  initTransition(transition?: Transition | null): void;
115
116
  }
116
117
  export declare function queuePendingNode(node: Signal<any>): void;
118
+ export declare let reaskArmed: boolean;
119
+ /** §12d: bumped by every recompute and every new subscriber edge. A node's
120
+ * staged-rewrite skip is sound only while NOTHING recomputed or linked since
121
+ * its last notify — a mid-batch pull can clean a marked subscriber, and a
122
+ * skipped re-write would leave it stale. */
123
+ export declare let notifyEpoch: number;
124
+ export declare function bumpNotifyEpoch(): void;
117
125
  export declare function armReaskClear(): void;
118
126
  export declare function insertSubs(node: Signal<any> | Computed<any>, optimistic?: boolean): void;
119
127
  export declare let storeCommitHook: (() => void) | null;
@@ -41,19 +41,19 @@ export interface NodeOptions<T> {
41
41
  */
42
42
  loadingValue?: T;
43
43
  }
44
- export interface RawSignal<T> {
45
- _subs: Link | null;
46
- _subsTail: Link | null;
47
- _value: T;
48
- _snapshotValue?: any;
49
- _name?: string;
50
- _equals: false | ((a: T, b: T) => boolean);
51
- _config: number;
52
- _unobserved?: () => void;
53
- _time: number;
54
- _transition: Transition | null;
55
- _pendingValue: T | typeof NOT_PENDING;
56
- _overrideValue?: T | typeof NOT_PENDING;
44
+ /**
45
+ * Cold node extension (stage-3 §12): optional machinery that most nodes
46
+ * never touch lives one hop away so the CORE node literal stays under V8's
47
+ * in-object property boundary (~39 fields measured: past it, every literal
48
+ * allocation spills to an out-of-object backing store and creation cost
49
+ * roughly quadruples — the create0to1 cliff). Allocated lazily by `ext()`
50
+ * on first installer write; ONE shape shared by signals and computeds so
51
+ * `_x` access stays monomorphic. Presence bits on `_config`
52
+ * (CONFIG_OPTIMISTIC / HAS_COMPANIONS / HAS_LANE / HAS_SNAPSHOT) remain the
53
+ * hot-path gates — a bit says "consult _x", never the reverse.
54
+ */
55
+ export interface NodeExtension {
56
+ _overrideValue: unknown | typeof NOT_PENDING;
57
57
  /**
58
58
  * The transaction that owns the active override (stamped at optimistic
59
59
  * write, cleared at settle). Ownership must live on the node: a lane's
@@ -62,21 +62,66 @@ export interface RawSignal<T> {
62
62
  * revert another action's live override. Node-level sibling of the store
63
63
  * layer's STORE_OPTIMISTIC_OWNERS stamps (#2899). `null` = ambient write.
64
64
  */
65
- _overrideOwner?: Transition | null;
66
- _optimisticLane?: OptimisticLane;
67
- _pendingSignal?: Signal<boolean>;
68
- _latestValueComputed?: Computed<T>;
69
- _parentSource?: Signal<any> | Computed<any>;
65
+ _overrideOwner: Transition | null | undefined;
66
+ _optimisticLane: OptimisticLane | undefined;
67
+ _pendingSignal: Signal<boolean> | undefined;
68
+ _latestValueComputed: Computed<any> | undefined;
69
+ _parentSource: Signal<any> | Computed<any> | undefined;
70
70
  /**
71
71
  * Live `affects()` marks on this node (refcount). Non-zero is declared
72
- * motion: the node and, via the verdict layer's dep-graph coverage walk,
73
- * everything derived from it — reads pending regardless of graph state,
74
- * until every declaring transaction settles/reverts and releases its mark.
75
- * This count is the mark's ONLY graph state: the dedicated channel stores
76
- * nothing downstream and never touches status flags, errors, or pending
77
- * sources.
72
+ * motion see affects(); the count is the mark's only graph state.
78
73
  */
79
- _affectsCount?: number;
74
+ _affectsCount: number;
75
+ _inFlight: PromiseLike<any> | AsyncIterable<any> | null;
76
+ _error: unknown;
77
+ _blocked: boolean | undefined;
78
+ _pendingSources: Set<Computed<any>> | undefined;
79
+ _notifyStatus: ((status?: number, error?: any) => void) | undefined;
80
+ /** Question-scoped re-ask classification of the current pending window
81
+ * (see the former Computed._x?._reask doc): set by recompute from
82
+ * REACTIVE_REASK, cleared on landing; meaningless while not pending. */
83
+ _reask: boolean;
84
+ _child: FirewallSignal<any> | null;
85
+ _unobserved: (() => void) | undefined;
86
+ _snapshotValue: any;
87
+ /** Zombie staging (staged disposal): a recompute of an owner that HAS
88
+ * children/disposal parks them here until the flush commits (or a
89
+ * transition reverts). Childless nodes — the common case — never write
90
+ * these. */
91
+ _pendingDisposal: Disposable | Disposable[] | null;
92
+ _pendingFirstChild: Owner | null;
93
+ /** #3038: the firewall children that actually carry isPending()/latest()
94
+ * companions. The post-recompute companion snap iterates THIS set —
95
+ * O(companions asked for) — never the full `_child` chain (one entry per
96
+ * materialized leaf). Populated at companion creation; entries live as
97
+ * long as their companions (which are permanent once created). */
98
+ _companionChildren: Set<FirewallSignal<any>> | undefined;
99
+ }
100
+ export interface RawSignal<T> {
101
+ _subs: Link | null;
102
+ _subsTail: Link | null;
103
+ /**
104
+ * DEV-only live subscriber count. Maintained by `link`/`unlinkSubs` for
105
+ * graph-size diagnostics; undefined in production.
106
+ */
107
+ _subCount?: number;
108
+ _value: T;
109
+ _name?: string;
110
+ _equals: false | ((a: T, b: T) => boolean);
111
+ _config: number;
112
+ _time: number;
113
+ /** IN CORE, not the extension (stage-3 §12c): consulted on EVERY write
114
+ * (setSignal's transition-init check) and on recompute scheduling — the
115
+ * per-write extension chase measurably taxed propagation chains. */
116
+ _transition: Transition | null;
117
+ /** Notify-epoch stamp of the last subscriber walk (§12d). A re-write to an
118
+ * already-staged node whose stamp still equals the global epoch skips the
119
+ * whole walk — marking is idempotent, and the epoch bumps on every
120
+ * recompute and new subscriber edge (either can invalidate the skip). */
121
+ _notifiedAt: number;
122
+ _pendingValue: T | typeof NOT_PENDING;
123
+ /** Cold extension — see NodeExtension. */
124
+ _x: NodeExtension | null;
80
125
  }
81
126
  export interface FirewallSignal<T> extends RawSignal<T> {
82
127
  _firewall: Computed<any>;
@@ -97,35 +142,33 @@ export interface Owner {
97
142
  _firstChild: Owner | null;
98
143
  _nextSibling: Owner | null;
99
144
  _prevSibling: Owner | null;
100
- _pendingDisposal: Disposable | Disposable[] | null;
101
- _pendingFirstChild: Owner | null;
145
+ /** Cold extension see NodeExtension (owners use the zombie-pair slots). */
146
+ _x: NodeExtension | null;
102
147
  }
103
148
  export interface Computed<T> extends RawSignal<T>, Owner {
104
149
  _deps: Link | null;
105
150
  _depsTail: Link | null;
151
+ /**
152
+ * DEV-only live source count. Maintained by `link`/`unlinkSubs` for
153
+ * graph-size diagnostics; undefined in production.
154
+ */
155
+ _depCount?: number;
106
156
  /** Recompute-pass counter; bumped when dep revalidation starts. */
107
157
  _depGen: number;
108
158
  _flags: number;
109
- _blocked?: boolean;
110
- _pendingSources?: Set<Computed<any>>;
111
- _error?: unknown;
112
159
  _statusFlags: number;
113
160
  _height: number;
114
161
  _nextHeap: Computed<any> | undefined;
115
162
  _prevHeap: Computed<any>;
116
163
  _fn: (prev?: T) => T;
117
- _inFlight: PromiseLike<T> | AsyncIterable<T> | null;
118
- _child: FirewallSignal<any> | null;
119
- _notifyStatus?: (status?: number, error?: any) => void;
120
164
  /**
121
- * Question-scoped pending classification of the node's CURRENT pending
122
- * window: `true` means the in-flight recompute is a re-ask of the same
123
- * question (refresh/poll/confirm no tracked input changed value), so the
124
- * shown answer still answers the question and the node reads NOT pending.
125
- * Set by `recompute` from `REACTIVE_REASK`, cleared on landing
126
- * (`clearStatus`). Meaningless while not STATUS_PENDING.
165
+ * Clock tick at which REACTIVE_MANUAL_WRITE was last applied
166
+ * (`suppressComputedRecompute`). Lets `refresh()` distinguish a same-tick
167
+ * manual write (which wins over the refresh, #2692) from a mask carried
168
+ * across ticks by a transaction (which an explicit refresh lifts, #3026).
169
+ * Only meaningful while REACTIVE_MANUAL_WRITE is set.
127
170
  */
128
- _reask: boolean;
171
+ _manualWriteTime?: number;
129
172
  /**
130
173
  * True while a `loadingValue` node's first real answer hasn't landed: the
131
174
  * node was born committed (commit #0 = the loading value) and `handleAsync`
@@ -137,7 +180,8 @@ export interface Computed<T> extends RawSignal<T>, Owner {
137
180
  * return, sync-resolved promise, first iterator yield, async settle); a
138
181
  * real error leaves it set — errors answer reads but don't enter the value
139
182
  * lineage, so a retry serves the loading value again. Once cleared, normal
140
- * pending/refetch semantics apply forever.
183
+ * pending/refetch semantics apply forever. (Stays in CORE: written
184
+ * unconditionally by recompute and every commit.)
141
185
  */
142
186
  _loading: boolean;
143
187
  }
@@ -1,19 +1,3 @@
1
- /**
2
- * Store rewrite — projections (§7/§7b): a projection is a computed store.
3
- * The derive runs inside a computed whose recompute merges its output into
4
- * the projection's backing through the adoption channel (replace-mode root:
5
- * entity changes merge in place, the root proxy is stable for life). Children
6
- * wrap into the projection's own FAMILY (writes land here, never in a source
7
- * family), and every family node carries the projection computed as its
8
- * firewall — reads link the derive's status and lifecycle natively. The §6c
9
- * status gate in the traps makes an uninitialized async derive's seed
10
- * unobservable through every read surface.
11
- *
12
- * Mirrors the legacy runProjectionComputed shape (shadow runs for open
13
- * loading windows, handleAsync landings, commit-through-setter) on next
14
- * primitives; the generic draft write-traps are reused from the legacy
15
- * module unchanged.
16
- */
17
1
  import { type Computed, type Refreshable } from "../../core/index.js";
18
2
  import { type NoFn, type ProjectionOptions, type Store } from "../store.js";
19
3
  export declare function createProjectionNext<T extends object = {}>(fn: (draft: T) => void | T | Promise<void | T> | AsyncIterable<void | T>, seed: Partial<T> | Store<NoFn<T>>, options?: ProjectionOptions): Refreshable<Store<T>>;