@solidjs/signals 2.0.0-rc.6 → 2.0.0-rc.8

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 (131) hide show
  1. package/dist/dev-shared.js +5243 -0
  2. package/dist/dev.attribution.js +2333 -0
  3. package/dist/dev.js +1758 -6621
  4. package/dist/observe/affects.js +127 -0
  5. package/dist/observe/attribution.js +1 -0
  6. package/dist/observe/boundaries.js +586 -0
  7. package/dist/observe/core/action.js +167 -0
  8. package/dist/observe/core/async.js +736 -0
  9. package/dist/observe/core/attribution-hooks.js +60 -0
  10. package/dist/observe/core/attribution.js +2318 -0
  11. package/dist/{types-cjs/core/constants.d.cts → observe/core/constants.js} +135 -71
  12. package/dist/{types-cjs/core/context.d.cts → observe/core/context.js} +37 -12
  13. package/dist/observe/core/core.js +1289 -0
  14. package/dist/observe/core/dev.js +232 -0
  15. package/dist/observe/core/effect.js +179 -0
  16. package/dist/observe/core/error.js +80 -0
  17. package/dist/observe/core/external.js +98 -0
  18. package/dist/observe/core/graph.js +155 -0
  19. package/dist/observe/core/heap.js +147 -0
  20. package/dist/observe/core/invariants.js +43 -0
  21. package/dist/observe/core/lanes.js +168 -0
  22. package/dist/observe/core/optimistic.js +438 -0
  23. package/dist/observe/core/owner.js +308 -0
  24. package/dist/observe/core/scheduler.js +1190 -0
  25. package/dist/observe/core/verdict.js +551 -0
  26. package/dist/observe/index.js +55 -0
  27. package/dist/observe/map.js +482 -0
  28. package/dist/{types-cjs/signals.d.cts → observe/signals.js} +305 -317
  29. package/dist/observe/store/index.js +38 -0
  30. package/dist/observe/store/next/optimistic.js +651 -0
  31. package/dist/observe/store/next/projection.js +242 -0
  32. package/dist/observe/store/next/reconcile.js +373 -0
  33. package/dist/observe/store/next/store.js +2213 -0
  34. package/dist/observe/store/next/target.js +51 -0
  35. package/dist/observe/store/store.js +323 -0
  36. package/dist/observe/store/storePath.js +103 -0
  37. package/dist/observe/store/utils.js +210 -0
  38. package/dist/prod/attribution.js +32 -0
  39. package/dist/prod/boundaries.js +3 -1
  40. package/dist/prod/core/action.js +52 -32
  41. package/dist/prod/core/async.js +177 -128
  42. package/dist/prod/core/attribution-hooks.js +3 -0
  43. package/dist/prod/core/constants.js +32 -1
  44. package/dist/prod/core/context.js +10 -16
  45. package/dist/prod/core/core.js +505 -286
  46. package/dist/prod/core/dev.js +2 -0
  47. package/dist/prod/core/effect.js +72 -43
  48. package/dist/prod/core/external.js +2 -2
  49. package/dist/prod/core/graph.js +40 -36
  50. package/dist/prod/core/heap.js +50 -51
  51. package/dist/prod/core/lanes.js +43 -22
  52. package/dist/prod/core/optimistic.js +224 -80
  53. package/dist/prod/core/owner.js +43 -39
  54. package/dist/prod/core/scheduler.js +347 -232
  55. package/dist/prod/core/verdict.js +71 -74
  56. package/dist/prod/index.js +9 -5
  57. package/dist/prod/map.js +311 -150
  58. package/dist/prod/signals.js +52 -38
  59. package/dist/prod/store/next/optimistic.js +127 -131
  60. package/dist/prod/store/next/projection.js +3 -3
  61. package/dist/prod/store/next/reconcile.js +149 -294
  62. package/dist/prod/store/next/store.js +694 -380
  63. package/dist/prod/store/next/target.js +32 -10
  64. package/dist/prod/store/store.js +12 -14
  65. package/dist/prod/store/utils.js +36 -27
  66. package/dist/types/attribution.d.ts +15 -0
  67. package/dist/types/attribution.prod.d.ts +13 -0
  68. package/dist/types/core/async.d.ts +1 -1
  69. package/dist/types/core/attribution-hooks.d.ts +183 -6
  70. package/dist/types/core/attribution.d.ts +435 -24
  71. package/dist/types/core/constants.d.ts +31 -0
  72. package/dist/types/core/core.d.ts +19 -3
  73. package/dist/types/core/dev.d.ts +165 -26
  74. package/dist/types/core/effect.d.ts +8 -1
  75. package/dist/types/core/heap.d.ts +5 -3
  76. package/dist/types/core/index.d.ts +2 -1
  77. package/dist/types/core/invariants.d.ts +1 -1
  78. package/dist/types/core/lanes.d.ts +17 -0
  79. package/dist/types/core/scheduler.d.ts +69 -4
  80. package/dist/types/core/types.d.ts +29 -9
  81. package/dist/types/index.d.ts +9 -2
  82. package/dist/types/map.d.ts +2 -0
  83. package/dist/types/signals.d.ts +10 -0
  84. package/dist/types/store/index.d.ts +4 -6
  85. package/dist/types/store/next/optimistic.d.ts +4 -2
  86. package/dist/types/store/next/reconcile.d.ts +5 -12
  87. package/dist/types/store/next/store.d.ts +8 -9
  88. package/dist/types/store/next/target.d.ts +56 -55
  89. package/dist/types/store/store.d.ts +14 -9
  90. package/dist/types/store/utils.d.ts +7 -0
  91. package/package.json +21 -16
  92. package/dist/node.cjs +0 -11121
  93. package/dist/prod/store/next/patch-hooks.js +0 -13
  94. package/dist/prod/store/next/patch.js +0 -614
  95. package/dist/types/store/next/patch-hooks.d.ts +0 -41
  96. package/dist/types/store/next/patch.d.ts +0 -91
  97. package/dist/types-cjs/affects.d.cts +0 -47
  98. package/dist/types-cjs/boundaries.d.cts +0 -175
  99. package/dist/types-cjs/core/action.d.cts +0 -64
  100. package/dist/types-cjs/core/async.d.cts +0 -23
  101. package/dist/types-cjs/core/attribution-hooks.d.cts +0 -63
  102. package/dist/types-cjs/core/attribution.d.cts +0 -239
  103. package/dist/types-cjs/core/core.d.cts +0 -176
  104. package/dist/types-cjs/core/dev.d.cts +0 -95
  105. package/dist/types-cjs/core/effect.d.cts +0 -30
  106. package/dist/types-cjs/core/error.d.cts +0 -56
  107. package/dist/types-cjs/core/external.d.cts +0 -15
  108. package/dist/types-cjs/core/graph.d.cts +0 -28
  109. package/dist/types-cjs/core/heap.d.cts +0 -22
  110. package/dist/types-cjs/core/index.d.cts +0 -13
  111. package/dist/types-cjs/core/invariants.d.cts +0 -59
  112. package/dist/types-cjs/core/lanes.d.cts +0 -44
  113. package/dist/types-cjs/core/optimistic.d.cts +0 -6
  114. package/dist/types-cjs/core/owner.d.cts +0 -124
  115. package/dist/types-cjs/core/scheduler.d.cts +0 -231
  116. package/dist/types-cjs/core/types.d.cts +0 -204
  117. package/dist/types-cjs/core/verdict.d.cts +0 -2
  118. package/dist/types-cjs/index.d.cts +0 -10
  119. package/dist/types-cjs/map.d.cts +0 -69
  120. package/dist/types-cjs/package.json +0 -3
  121. package/dist/types-cjs/store/index.d.cts +0 -21
  122. package/dist/types-cjs/store/next/optimistic.d.cts +0 -23
  123. package/dist/types-cjs/store/next/patch-hooks.d.cts +0 -41
  124. package/dist/types-cjs/store/next/patch.d.cts +0 -91
  125. package/dist/types-cjs/store/next/projection.d.cts +0 -8
  126. package/dist/types-cjs/store/next/reconcile.d.cts +0 -17
  127. package/dist/types-cjs/store/next/store.d.cts +0 -127
  128. package/dist/types-cjs/store/next/target.d.cts +0 -192
  129. package/dist/types-cjs/store/store.d.cts +0 -138
  130. package/dist/types-cjs/store/storePath.d.cts +0 -58
  131. package/dist/types-cjs/store/utils.d.cts +0 -74
@@ -1,239 +0,0 @@
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 produced a changed value. A PLAIN memo run with
64
- * `changed: false` was pure waste — the equality cutoff stopped it from
65
- * notifying anyone. Effects run with `_equals: false` in core (their
66
- * effect phase re-fires on every recompute), so the engine derives this
67
- * fact itself: an effect run whose compute output is identical to the
68
- * previous run's reports `changed: false` — the phase re-fired with the
69
- * same input, pure waste. Side-effect-only computes (`undefined` output)
70
- * are exempt: identity of `undefined` proves nothing about their work.
71
- * Summed as `wastedMs` in costs() (plain, non-held runs only — see
72
- * `phase`).
73
- */
74
- changed: boolean;
75
- /**
76
- * Which posture this run executed under. "optimistic" = under an
77
- * optimistic lane (overlay recompute); "transition" = a transition was
78
- * active or owns the node (the run may be replayed/settled later);
79
- * "plain" = an ordinary committed run. Overlay runs are real work (they
80
- * count toward time budgets) but are never blamed as waste, and costs()
81
- * reports their time separately as `overlayMs`.
82
- */
83
- phase: "plain" | "transition" | "optimistic";
84
- /**
85
- * The changed value was held in `_pendingValue` (a transition hold) rather
86
- * than committed directly; its reveal happens on the transition's own
87
- * schedule. Held runs are excluded from waste accounting.
88
- */
89
- held: boolean;
90
- }
91
- export interface AttributionOptions {
92
- /** Pretty-print each re-run to the console (default true). */
93
- log?: boolean;
94
- /** Capture the user stack frame of each write — slow (default false). */
95
- stacks?: boolean;
96
- /** Ring-buffer size for `history()` (default 200). */
97
- historyLimit?: number;
98
- /**
99
- * Hot-scope warning: emit a diagnostic when one scope re-runs `count`
100
- * times within `windowMs` (default 120 runs / 1000ms — deliberately above
101
- * animation-frame cadence, so a legitimate rAF-driven scope at 60/s does
102
- * not cry wolf). `false` disables.
103
- */
104
- hotRuns?: {
105
- count: number;
106
- windowMs: number;
107
- } | false;
108
- /**
109
- * Wide-scope warning: emit a diagnostic when a scope's dependency count
110
- * reaches this (default 30) — the coarse-read / helper-leak signature.
111
- * Re-warns only if the count then grows by another 50%. `false` disables.
112
- */
113
- wideDeps?: number | false;
114
- /**
115
- * Time-budget warning: emit a diagnostic when one scope's summed self-time
116
- * inside `windowMs` exceeds `budgetMs` (default 8ms / 1000ms — half a frame
117
- * spent in one scope). Unlike `hotRuns` this catches the few-but-expensive
118
- * scope that run counts miss. `false` disables.
119
- */
120
- hotTime?: {
121
- budgetMs: number;
122
- windowMs: number;
123
- } | false;
124
- /**
125
- * Unstable-output warning: emit a diagnostic when a memo commits a
126
- * referentially-new but shallowly-equivalent plain object/array on this
127
- * many consecutive runs (default 4). Such a memo's equality gate never
128
- * closes — every subscriber re-runs on every upstream change — which makes
129
- * it a fan-out amplifier that is otherwise only findable by profiling.
130
- * `false` disables.
131
- */
132
- unstableMemos?: number | false;
133
- /**
134
- * Written-fan-out warning: emit a diagnostic when a committed root
135
- * invalidation (write, refresh, async landing) reaches a node with at
136
- * least this many subscribers (default 250). Complements the always-on
137
- * HUGE_FAN_OUT graph-size warning, specced against it deliberately:
138
- * HUGE_FAN_OUT fires at LINK time from GRAPH_SIZE_WARN_AT (2000) up —
139
- * static structure so large it warns even if never written — while this
140
- * fires at WRITE time from a much lower bar, because fan-out only costs
141
- * anything when the node actually changes. Once per node, re-warning only
142
- * on 2x subscriber growth, so the two never spam the same node. `false`
143
- * disables.
144
- */
145
- wideWrites?: number | false;
146
- /**
147
- * Async-waterfall warning: emit a diagnostic when an async flight that
148
- * could only start after an upstream flight resolved (its recompute's
149
- * cause chain reaches the upstream's async landing, and its origin
150
- * post-dates that landing) forms a sequential chain of 2+ flights, each
151
- * of which took at least `minFlightMs` (default 50ms). The duration gate
152
- * is one safety valve for what the graph cannot see: a settled
153
- * preload/cache hit resolves fast and never warns. In-flight preloads are
154
- * absolved by origin: `markFlight()` stamps (and first-seen identity)
155
- * prove work predated the upstream landing — parallel, not sequential.
156
- * Chains of 2 emit at `info` severity, structured channel only (a
157
- * dependent fetch is sometimes intrinsic, and unmarked external preloads
158
- * are invisible); 3+ escalate to `warn` with console output. `false`
159
- * disables.
160
- */
161
- waterfalls?: {
162
- minFlightMs: number;
163
- } | false;
164
- }
165
- export interface ScopeCost {
166
- name: string;
167
- kind: "effect" | "memo";
168
- runs: number;
169
- selfMs: number;
170
- /**
171
- * Self-time of PLAIN, non-held runs that produced an unchanged value —
172
- * the recoverable number. Overlay runs (optimistic/transition) are never
173
- * counted here: an optimistic recompute landing back on the committed
174
- * value is the mechanism working, not waste.
175
- */
176
- wastedMs: number;
177
- /** Self-time spent in optimistic/transition (overlay) runs. */
178
- overlayMs: number;
179
- }
180
- export interface WriteCost {
181
- /** Root cause name (a signal write, async landing, or refresh target). */
182
- name: string;
183
- /** Number of downstream re-runs this root triggered. */
184
- runs: number;
185
- /** Summed self-time of every downstream re-run it caused. */
186
- downstreamMs: number;
187
- }
188
- export declare function formatRerun(event: RerunEvent): string;
189
- export interface Attribution {
190
- enable(opts?: AttributionOptions): void;
191
- disable(): void;
192
- subscribe(listener: (event: RerunEvent) => void): () => void;
193
- history(): readonly RerunEvent[];
194
- /** Re-run history for one node — pass a memo/effect accessor or raw node. */
195
- why(target: unknown): RerunEvent[];
196
- /** Current dependency names of one scope — the devtools subscription view. */
197
- subscriptions(target: unknown): string[];
198
- /**
199
- * Aggregated cost tables since enable(): `scopes` ranked by self-time
200
- * (with `wastedMs` = time spent on unchanged-value runs), `writes` ranked
201
- * by total downstream re-run time each root write caused.
202
- */
203
- costs(): {
204
- scopes: ScopeCost[];
205
- writes: WriteCost[];
206
- };
207
- /**
208
- * Every graph-provable sequential flight chain observed since enable()
209
- * (ring-buffered like history()). Facts, not verdicts: chains are recorded
210
- * regardless of the duration gate — the ASYNC_WATERFALL diagnostic is the
211
- * thresholded view of the same data.
212
- */
213
- waterfalls(): readonly WaterfallRecord[];
214
- /**
215
- * Cooperative preload declaration: stamp a flight object (promise or async
216
- * iterable) with its true kickoff time BEFORE the reactive graph sees it.
217
- * A route preloader or query cache calls this on the promise it hands out
218
- * (on the WRAPPER it mints, with the original kickoff time — wrapping
219
- * defeats identity tracking otherwise); any dependent that later awaits it
220
- * is then judged against the real start — work already in the air when its
221
- * upstream landed is parallel, never a waterfall link. Callable while
222
- * attribution is disabled (marks made at navigation time must survive a
223
- * later enable()). Dev-only, like the whole DEV surface.
224
- */
225
- markFlight(flight: object, startedAt?: number): void;
226
- format: typeof formatRerun;
227
- }
228
- /** One landed flight: its node name, wall duration, and upstream chain. */
229
- export interface FlightLink {
230
- name: string;
231
- ms: number;
232
- }
233
- export interface WaterfallRecord {
234
- /** Sequential flights, oldest first, ending at the flight that landed. */
235
- chain: FlightLink[];
236
- /** Summed wall time of the chain — the serialized cost. */
237
- sequentialMs: number;
238
- }
239
- export declare const attribution: Attribution;
@@ -1,176 +0,0 @@
1
- import { type OptimisticLane } from "./lanes.cjs";
2
- import type { Computed, FirewallSignal, NodeExtension, NodeOptions, Owner, Signal } from "./types.cjs";
3
- export declare const PRIMITIVE_IN_FORBIDDEN_SCOPE_MESSAGE = "[PRIMITIVE_IN_FORBIDDEN_SCOPE] Cannot create reactive primitives inside createTrackedEffect or owner-backed onSettled";
4
- export declare const REACTIVE_WRITE_IN_OWNED_SCOPE_SIGNAL_MESSAGE: string;
5
- export declare const REACTIVE_WRITE_IN_OWNED_SCOPE_REFRESH_MESSAGE: string;
6
- export declare let tracking: boolean;
7
- /** @internal verdict-module glue */
8
- export declare function setPendingCheckActive(v: boolean): void;
9
- /** @internal verdict-module glue */
10
- export declare function setLatestReadActive(v: boolean): void;
11
- /** @internal verdict-module glue */
12
- export declare function setContextInternal(v: Owner | null): void;
13
- export declare let stale: boolean;
14
- export declare let pendingCheckActive: boolean;
15
- export declare let latestReadActive: boolean;
16
- export declare let context: Owner | null;
17
- export declare let currentOptimisticLane: OptimisticLane | null;
18
- export declare let snapshotCaptureActive: boolean;
19
- export declare let snapshotSources: Set<any> | null;
20
- export declare function setSnapshotCapture(active: boolean): void;
21
- export declare function markSnapshotScope(owner: Owner): void;
22
- export declare function releaseSnapshotScope(owner: Owner): void;
23
- export declare function clearSnapshots(): void;
24
- export declare function recompute(el: Computed<any>, create?: boolean): void;
25
- export declare function computed<T>(fn: (prev?: T) => T | PromiseLike<T> | AsyncIterable<T>): Computed<T>;
26
- export declare function computed<T>(fn: (prev: T) => T | PromiseLike<T> | AsyncIterable<T>, options?: NodeOptions<T>): Computed<T>;
27
- /** Lazily allocate a node's cold extension (ONE shape for signals and
28
- * computeds — `_x` access stays monomorphic). Installers write through
29
- * this; hot paths read `el._x?._field` gated by the _config presence bits.
30
- * Never call ext() just to store a field's default. */
31
- export declare function ext(el: {
32
- _x: NodeExtension | null;
33
- }): NodeExtension;
34
- /**
35
- * Build an Effect node with all effect-specific fields baked into a single object literal,
36
- * so V8 sees the full hidden class shape at construction time. Effects always run in lazy
37
- * mode (recompute is called explicitly by `effect()`), so we hardcode the lazy bits and skip
38
- * the auto-dispose CONFIG bit (effect() previously cleared it post-construction).
39
- */
40
- export declare function createEffectNode<T>(fn: (prev?: T) => T, effectFn: (val: T, prev: T | undefined) => void | (() => void), errorFn: ((err: unknown, cleanup: () => void) => void | (() => void)) | undefined, type: number, options: NodeOptions<T> | undefined): any;
41
- /**
42
- * The shared status notifier for effect nodes, installed once by effect.ts
43
- * at module evaluation (`this`-dispatched — one function serves every
44
- * effect, so nodes never store it). Boundary computeds keep their own
45
- * per-node channel on `_x._notifyStatus`, which takes precedence.
46
- */
47
- export declare let effectStatusNotify: ((this: any, status?: number, error?: any) => void) | null;
48
- export declare function setEffectStatusNotify(fn: NonNullable<typeof effectStatusNotify>): void;
49
- /** Resolve a node's status notifier: an own `_x` channel (boundaries) wins;
50
- * effect nodes (`_type` — EFFECT_PURE is 0, and only effect literals carry
51
- * the field) fall back to the shared notifier. Presence doubles as the
52
- * "display consumer" membership test in the status walks, exactly as the
53
- * per-node field did when every effect carried one. */
54
- export declare function statusNotifierOf(el: any): ((this: any, status?: number, error?: any) => void) | undefined;
55
- export declare function signal<T>(v: T, options?: NodeOptions<T>): Signal<T>;
56
- export declare function signal<T>(v: T, options?: NodeOptions<T>, firewall?: Computed<any>): FirewallSignal<T>;
57
- export declare function optimisticSignal<T>(v: T, options?: NodeOptions<T>): Signal<T>;
58
- export declare function optimisticComputed<T>(fn: (prev?: T) => T | PromiseLike<T> | AsyncIterable<T>, options?: NodeOptions<T>): Computed<T>;
59
- export declare function isEqual<T>(a: T, b: T): boolean;
60
- /**
61
- * When set to a component name string, any reactive read that is not inside a nested tracking
62
- * scope will log a dev-mode warning. Managed automatically by `untrack(fn, strictReadLabel)`.
63
- */
64
- export declare let strictRead: string | false;
65
- export declare function setStrictRead(v: string | false): string | false;
66
- /**
67
- * Runs `fn` outside of any reactive tracking — reads inside `fn` will not
68
- * subscribe the current scope. Returns whatever `fn` returns.
69
- *
70
- * Use `untrack` inside a memo or effect when you need to read a signal once
71
- * without making the surrounding computation depend on its future changes.
72
- *
73
- * Pass a `strictReadLabel` string to enable a dev-mode warning: any reactive
74
- * read inside `fn` that isn't inside a nested tracking scope will log a
75
- * warning naming the label.
76
- *
77
- * @example
78
- * ```ts
79
- * createEffect(
80
- * () => trigger(), // tracks `trigger` only
81
- * () => {
82
- * const snapshot = untrack(() => state); // read once, untracked
83
- * log(snapshot);
84
- * }
85
- * );
86
- * ```
87
- */
88
- export declare function untrack<T>(fn: () => T, strictReadLabel?: string | false): T;
89
- /**
90
- * Bring a computed to a readable state: lazy/disposed nodes are (re)computed;
91
- * an isPending() probe (`refresh`) additionally pulls the node fully up to
92
- * date so its status flags reflect the current graph.
93
- */
94
- export declare function prepareComputed(comp: Computed<unknown>, refresh: boolean): void;
95
- /**
96
- * Sentinel returned by readNodeFast when the plain-signal fast path does not
97
- * apply and the caller must fall back to the full read().
98
- */
99
- export declare const READ_SLOW: unique symbol;
100
- /**
101
- * read()'s plain-signal fast path as a standalone entry for hot callers
102
- * (store traps). Safe to substitute for read() only because the bail
103
- * conditions mirror read()'s prelude and fast-path guard exactly: the
104
- * latestRead and pendingCheck windows run side-effectful hooks before the
105
- * fast path, `_fn` nodes need prepareComputed, and firewall / override /
106
- * snapshot / transition / lane / dev-strictRead state all take the full
107
- * resolution. Anything slow returns READ_SLOW; the caller then calls read().
108
- */
109
- /**
110
- * Wake only authoritative-view readers (until() predicates) subscribed to `el`.
111
- * The A17-silent ack paths — an authoritative arrival equal to the active
112
- * override — use this so the predicate re-evaluates without re-firing
113
- * ordinary subscribers whose visible (override) value did not change.
114
- * Pay-for-use: reached through GlobalQueue._notifyAuthoritativeObservers,
115
- * installed at first until() call — apps that never use until() shake it.
116
- */
117
- export declare function notifyAuthoritativeObservers(el: Signal<any> | Computed<any>): void;
118
- /** Installs the until() machinery hook. Idempotent; called by until() before
119
- * any authoritative-view read happens (same late-binding contract as the
120
- * optimistic engine). */
121
- export declare function installAuthoritativeRead(): void;
122
- export declare function readNodeFast<T>(el: Signal<T>): T | typeof READ_SLOW;
123
- export declare function read<T>(el: Signal<T> | Computed<T>): T;
124
- /**
125
- * Store-rewrite setter guard: the rewrite parks writes in a pending backing
126
- * (no setSignal at write time), so the owned-scope write protection must
127
- * fire at the setter entry instead. Mirrors setSignal's guard condition
128
- * minus the node-specific exemptions (ownedWrite/firewall), which don't
129
- * apply to plain store setters.
130
- */
131
- export declare function devGuardStoreSetterWrite(): void;
132
- export declare function setSignal<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)): T;
133
- /**
134
- * Suppresses automatic recomputation of `el` until the scheduler drains. Used
135
- * when a manual write should win over dependency changes queued in the same
136
- * tick. The MANUAL_WRITE flag is cleared by the pending-node drain; projection
137
- * computeds don't commit values, but they still need the same end-of-tick
138
- * cleanup point.
139
- */
140
- export declare function suppressComputedRecompute(el: Computed<unknown>): void;
141
- /**
142
- * User-facing setter for the memo form of `createSignal(fn)`. Behaves like
143
- * `setSignal`, but also cancels any pending recompute of the memo so the
144
- * manual value wins over a value that would otherwise be produced by an
145
- * upstream change in the same tick.
146
- */
147
- export declare function setMemo<T>(el: Computed<T>, v: T | ((prev: T) => T)): T;
148
- /**
149
- * Executes `fn` with the given `owner` set as the current owner. Any reactive
150
- * primitives (`createSignal`, `createMemo`, `createEffect`, `onCleanup`,
151
- * `cleanup`, etc.) created inside `fn` are attached to that owner, so they
152
- * are disposed when the owner is disposed.
153
- *
154
- * The classic pattern: capture the current owner with `getOwner()` inside a
155
- * component, then re-enter it from a callback (event handler, async resolve,
156
- * setTimeout) so disposables created in the callback get cleaned up with the
157
- * component.
158
- *
159
- * @example
160
- * ```ts
161
- * function delayed<T>(ms: number, fn: () => T) {
162
- * const owner = getOwner();
163
- * setTimeout(() => runWithOwner(owner, fn), ms);
164
- * }
165
- * ```
166
- */
167
- export declare function runWithOwner<T>(owner: Owner | null, fn: () => T): T;
168
- export declare function staleValues<T>(fn: () => T, set?: boolean): T;
169
- /**
170
- * Core marking half of `refresh()` (the public wrapper lives in signals.ts —
171
- * it validates the target, marks through here, then builds the quiescence
172
- * promise on the resolve()/until() effect machinery). Flags the node's next
173
- * recompute as a quiet re-ask and schedules it; no-ops for non-derived or
174
- * disposed targets and for same-tick manual writes.
175
- */
176
- export declare function markRefresh(node: Computed<any>): void;
@@ -1,95 +0,0 @@
1
- import { type Attribution } from "./attribution.cjs";
2
- import type { Computed, Link, Owner, Signal } from "./types.cjs";
3
- export interface DevHooks {
4
- onOwner?: (owner: Owner) => void;
5
- onGraph?: (value: any, owner: Owner | null) => void;
6
- onUpdate?: () => void;
7
- onStoreNodeUpdate?: (state: any, property: PropertyKey, value: any, prev: any) => void;
8
- }
9
- /**
10
- * `info` is the advisory tier: a structural fact worth surfacing that is not
11
- * presumptively a bug (e.g. a 2-deep sequential fetch chain, which may be an
12
- * intrinsic data dependency). Budget/assertion consumers should treat only
13
- * `warn`/`error` as failures unless they opt in to `info`.
14
- */
15
- export type DiagnosticSeverity = "info" | "warn" | "error";
16
- 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" | "SETTLE_WALK_UNINITIALIZED_SOURCE" | "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" | "ASYNC_WATERFALL" | "HOT_SCOPE_FANOUT";
17
- export type DiagnosticKind = "strict-read" | "async" | "write" | "lifecycle" | "owner" | "error" | "perf" | "graph";
18
- /** First warning when a node's live edge count reaches this size. */
19
- export declare const GRAPH_SIZE_WARN_AT = 2000;
20
- /** Repeat the warning at this interval after the first. */
21
- export declare const GRAPH_SIZE_WARN_EVERY = 500;
22
- export interface DiagnosticEvent {
23
- sequence: number;
24
- code: DiagnosticCode;
25
- kind: DiagnosticKind;
26
- severity: DiagnosticSeverity;
27
- message: string;
28
- ownerId?: string;
29
- ownerName?: string;
30
- nodeName?: string;
31
- data?: Record<string, unknown>;
32
- }
33
- export type DiagnosticListener = (event: DiagnosticEvent) => void;
34
- export interface DiagnosticCapture {
35
- readonly events: readonly DiagnosticEvent[];
36
- clear(): void;
37
- stop(): DiagnosticEvent[];
38
- }
39
- export interface Diagnostics {
40
- subscribe(listener: DiagnosticListener): () => void;
41
- capture(): DiagnosticCapture;
42
- /**
43
- * Registers a console footer printed after the first console report of
44
- * each diagnostic code — a discovery pointer to deeper guidance (e.g.
45
- * solid-js registers its shipped repair skill). Returning undefined for
46
- * an event suppresses the footer. Passing undefined unregisters and
47
- * resets the once-per-code memory.
48
- */
49
- setConsoleFooter(footer: ((event: DiagnosticEvent) => string | undefined) | undefined): void;
50
- }
51
- export interface Dev {
52
- hooks: DevHooks;
53
- diagnostics: Diagnostics;
54
- /** "Why did this run" re-run attribution — see attribution.ts. */
55
- attribution: Attribution;
56
- getChildren: typeof getChildren;
57
- getSignals: typeof getSignals;
58
- getParent: typeof getParent;
59
- getSources: typeof getSources;
60
- getObservers: typeof getObservers;
61
- }
62
- export declare const DEV: Dev;
63
- /**
64
- * Dev-mode internal consistency check. A failure means the reactive system
65
- * contradicted itself (not that user code misbehaved) — see
66
- * INTERNALS-ASYNC-STATE.md for the invariant catalog. Throws under __TEST__
67
- * so the suite (and fuzzing) treats any violation as a hard failure; logs in
68
- * dev builds so user apps degrade instead of crashing.
69
- */
70
- export declare function assertInvariant(condition: boolean, name: string, message: string): void;
71
- export declare function emitDiagnostic(event: Omit<DiagnosticEvent, "sequence">): DiagnosticEvent;
72
- /**
73
- * Shared strict-read diagnostics for core read() and the store proxy traps.
74
- * Single source for the message text — the #2897 safeguard parity between
75
- * memos and stores is exactly these firing identically from both paths.
76
- */
77
- export declare function throwPendingUntrackedRead(strictReadLabel: string, fields?: Partial<Omit<DiagnosticEvent, "sequence" | "data">>): never;
78
- export declare function warnStrictReadUntracked(strictReadLabel: string, fields?: Partial<Omit<DiagnosticEvent, "sequence">>): void;
79
- export declare function registerGraph(value: any, owner: Owner | null): void;
80
- export declare function clearSignals(node: Owner): void;
81
- export declare function getChildren(owner: Owner): Owner[];
82
- export declare function getSignals(owner: Owner): any[];
83
- export declare function getParent(owner: Owner): Owner | null;
84
- export declare function getSources(computation: Computed<any>): (Signal<any> | Computed<any>)[];
85
- export declare function getObservers(node: Signal<any> | Computed<any>): Computed<any>[];
86
- /**
87
- * DEV-only: bump live edge counts after a new graph link and warn when a
88
- * node grows an unusually large fan-out (many subscribers on one source) or
89
- * fan-in (many sources on one computation). Repeat-reads that `link()`
90
- * dedupes never reach here. Always-on in dev — unlike the opt-in attribution
91
- * engine, a graph-size pathology should surface without asking.
92
- */
93
- export declare function noteGraphLink(dep: Signal<any> | Computed<any>, sub: Computed<any>): void;
94
- /** DEV-only: drop live edge counts when a link is removed. */
95
- export declare function unnoteGraphLink(link: Link): void;
@@ -1,30 +0,0 @@
1
- import type { Computed, NodeOptions, Owner } from "./types.cjs";
2
- export interface Effect<T> extends Computed<T>, Owner {
3
- _effectFn: (val: T, prev: T | undefined) => void | (() => void);
4
- _errorFn?: (err: unknown, cleanup: () => void) => void;
5
- _modified: boolean;
6
- _prevValue: T | undefined;
7
- _type: number;
8
- _boundRunEffect?: () => void;
9
- }
10
- /**
11
- * Effects are the leaf nodes of our reactive graph. When their sources change, they are
12
- * automatically added to the queue of effects to re-execute, which will cause them to fetch their
13
- * sources and recompute
14
- */
15
- export declare function effect<T>(compute: (prev: T | undefined) => T, effect: (val: T, prev: T | undefined) => void | (() => void), error?: (err: unknown, cleanup: () => void) => void | (() => void), options?: NodeOptions<any> & {
16
- user?: boolean;
17
- defer?: boolean;
18
- schedule?: boolean;
19
- }): void;
20
- export interface TrackedEffect extends Computed<void> {
21
- _modified: boolean;
22
- _type: number;
23
- _run: () => void;
24
- }
25
- /**
26
- * Internal tracked effect - bypasses heap, goes directly to effect queue.
27
- * Runs as a leaf owner: child primitives and onCleanup are forbidden (__DEV__ throws).
28
- * Uses stale reads.
29
- */
30
- export declare function trackedEffect(fn: () => void | (() => void), options?: NodeOptions<any>): void;
@@ -1,56 +0,0 @@
1
- /**
2
- * Thrown by a tracked read whose value is currently pending (an async memo /
3
- * `createSignal(asyncFn)` / projection / store derivation that hasn't settled
4
- * yet). Surfacing through the reactive graph is what suspends the consumer
5
- * scope — the nearest enclosing `<Loading>` boundary catches the throw and
6
- * renders its fallback until the source resolves.
7
- *
8
- * App code rarely catches this directly; `<Loading>` is the canonical
9
- * handler. The error type is exposed for advanced cases — e.g. interop layers
10
- * that bridge Solid's pending-throw protocol to a different async strategy,
11
- * or tests that want to assert on the suspension shape.
12
- *
13
- * @example
14
- * ```ts
15
- * // Advanced: distinguish "not ready yet" from a real error in custom
16
- * // boundary plumbing. App code should rely on `<Loading>` / `<Errored>`.
17
- * try {
18
- * const value = readReactiveSource();
19
- * } catch (err) {
20
- * if (err instanceof NotReadyError) throw err; // re-throw to suspend
21
- * reportError(err);
22
- * }
23
- * ```
24
- */
25
- export declare class NotReadyError extends Error {
26
- /**
27
- * Tags a visibility-only notification on the affects() boundary channel:
28
- * boundaries update display state from it, but the root queue never
29
- * registers a reporter — marks are invisible to completion accounting by
30
- * construction.
31
- */
32
- _markVisual?: boolean;
33
- source: any;
34
- constructor(source: any);
35
- }
36
- export declare class StatusError extends Error {
37
- source: any;
38
- constructor(source: any, original: any);
39
- }
40
- /** Return the user's error from an internal status wrapper. */
41
- export declare function unwrapStatusError(error: unknown): unknown;
42
- /**
43
- * Rejection value of `until(fn, { timeout })` when the predicate does not turn
44
- * truthy within the window. Inside an `action()`, the rejection is thrown back
45
- * in at the `yield` point — catchable there, or the action fails and its
46
- * optimistic state reverts.
47
- */
48
- export declare class TimeoutError extends Error {
49
- constructor(message?: string);
50
- }
51
- export declare class NoOwnerError extends Error {
52
- constructor();
53
- }
54
- export declare class ContextNotFoundError extends Error {
55
- constructor();
56
- }
@@ -1,15 +0,0 @@
1
- export type ExternalSourceFactory = (fn: (prev: any) => any, trigger: () => void) => ExternalSource;
2
- export interface ExternalSource {
3
- track: (prev: any) => any;
4
- dispose: () => void;
5
- }
6
- export interface ExternalSourceConfig {
7
- factory: ExternalSourceFactory;
8
- untrack?: <T>(fn: () => T) => T;
9
- }
10
- export declare let externalSourceConfig: {
11
- factory: ExternalSourceFactory;
12
- untrack: <T>(fn: () => T) => T;
13
- } | null;
14
- export declare function enableExternalSource(config: ExternalSourceConfig): void;
15
- export declare function _resetExternalSourceConfig(): void;
@@ -1,28 +0,0 @@
1
- import type { Computed, Link, Signal } from "./types.cjs";
2
- export declare function unlinkSubs(link: Link): Link | null;
3
- export declare function trimStaleDeps(el: Computed<any>): void;
4
- export declare function clearDeps(el: Computed<unknown>): void;
5
- export declare function unobserved(el: Computed<unknown>): void;
6
- /**
7
- * Deferred dormancy for never-observed auto-dispose computeds (#3078).
8
- *
9
- * An untracked top-level read of a subscriber-less observation-lifecycle memo
10
- * used to call unobserved() inline at the end of read(). That kept the leak
11
- * closed (the compute links the memo into its deps' sub lists — without a
12
- * teardown point a never-observed memo is retained by its sources forever;
13
- * upstream alien-signals has exactly this retention), but it made reads
14
- * destructive: each read disposed the node, the next read revived it with a
15
- * full recompute in whatever ambient transition/lane context happened to be
16
- * current, so consecutive reads could return different answers with no write
17
- * in between.
18
- *
19
- * Instead, reads queue the node here and the scheduler sweeps at the top of
20
- * the next flush (before runHeap, so a same-tick dirtying is reclaimed
21
- * instead of recomputed). Reads become idempotent within a tick (the node
22
- * stays alive and serves its cache, uniform with observed memos) while
23
- * reclamation still happens within one microtask — the enqueue site arms
24
- * schedule(), so a flush is guaranteed even when no other work is queued.
25
- */
26
- export declare const dormantNodes: Set<Computed<unknown>>;
27
- export declare function sweepDormant(): void;
28
- export declare function link(dep: Signal<any> | Computed<any>, sub: Computed<any>, pendingObserver?: boolean): void;
@@ -1,22 +0,0 @@
1
- import type { Computed } from "./types.cjs";
2
- /** The queue a node belongs to, picked from its own zombie flag. */
3
- export declare function queueFor(n: Computed<any>): Heap;
4
- /**
5
- * Schedule one subscriber to re-run on the next flush: tracked effects bypass
6
- * the heap and go directly to their effect queue; everything else is inserted
7
- * into its own (zombie-flag-routed) heap with the `_min` cursor pulled down.
8
- */
9
- export declare function enqueueSub(node: Computed<any>): void;
10
- export interface Heap {
11
- _heap: (Computed<unknown> | undefined)[];
12
- _marked: boolean;
13
- _min: number;
14
- _max: number;
15
- }
16
- export declare function increaseHeapSize(n: number, heap: Heap): void;
17
- export declare function insertIntoHeap(n: Computed<any>, heap: Heap): void;
18
- export declare function insertIntoHeapHeight(n: Computed<unknown>, heap: Heap): void;
19
- export declare function deleteFromHeap(n: Computed<unknown>, heap: Heap): void;
20
- export declare function markHeap(heap: Heap): void;
21
- export declare function markNode(el: Computed<unknown>, newState?: number): void;
22
- export declare function runHeap(heap: Heap, recompute: (el: Computed<unknown>) => void): void;