@solidjs/signals 2.0.0-beta.8 → 2.0.0-rc.0

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 (95) hide show
  1. package/README.md +13 -9
  2. package/dist/dev.js +6078 -1440
  3. package/dist/node.cjs +7684 -3248
  4. package/dist/prod/affects.js +126 -0
  5. package/dist/prod/boundaries.js +572 -0
  6. package/dist/prod/core/action.js +139 -0
  7. package/dist/prod/core/async.js +553 -0
  8. package/dist/prod/core/constants.js +92 -0
  9. package/dist/prod/core/context.js +67 -0
  10. package/dist/prod/core/core.js +817 -0
  11. package/dist/prod/core/dev.js +3 -0
  12. package/dist/prod/core/effect.js +145 -0
  13. package/dist/prod/core/error.js +68 -0
  14. package/dist/prod/core/external.js +98 -0
  15. package/dist/prod/core/graph.js +104 -0
  16. package/dist/prod/core/heap.js +140 -0
  17. package/dist/prod/core/invariants.js +42 -0
  18. package/dist/prod/core/lanes.js +140 -0
  19. package/dist/prod/core/optimistic.js +245 -0
  20. package/dist/prod/core/owner.js +302 -0
  21. package/dist/prod/core/scheduler.js +749 -0
  22. package/dist/prod/core/verdict.js +369 -0
  23. package/dist/prod/index.js +45 -0
  24. package/dist/prod/map.js +317 -0
  25. package/dist/prod/signals.js +375 -0
  26. package/dist/prod/store/optimistic.js +217 -0
  27. package/dist/prod/store/projection.js +231 -0
  28. package/dist/prod/store/reconcile.js +707 -0
  29. package/dist/prod/store/store.js +1081 -0
  30. package/dist/prod/store/storePath.js +103 -0
  31. package/dist/prod/store/utils.js +328 -0
  32. package/dist/types/affects.d.ts +47 -0
  33. package/dist/types/boundaries.d.ts +93 -11
  34. package/dist/types/core/action.d.ts +63 -0
  35. package/dist/types/core/async.d.ts +16 -1
  36. package/dist/types/core/constants.d.ts +46 -0
  37. package/dist/types/core/context.d.ts +10 -2
  38. package/dist/types/core/core.d.ts +111 -17
  39. package/dist/types/core/dev.d.ts +17 -2
  40. package/dist/types/core/effect.d.ts +1 -2
  41. package/dist/types/core/error.d.ts +33 -0
  42. package/dist/types/core/external.d.ts +0 -11
  43. package/dist/types/core/graph.d.ts +2 -1
  44. package/dist/types/core/heap.d.ts +8 -0
  45. package/dist/types/core/index.d.ts +3 -2
  46. package/dist/types/core/invariants.d.ts +59 -0
  47. package/dist/types/core/lanes.d.ts +2 -0
  48. package/dist/types/core/optimistic.d.ts +6 -0
  49. package/dist/types/core/owner.d.ts +101 -3
  50. package/dist/types/core/scheduler.d.ts +97 -9
  51. package/dist/types/core/types.d.ts +68 -6
  52. package/dist/types/core/verdict.d.ts +2 -0
  53. package/dist/types/index.d.ts +4 -3
  54. package/dist/types/map.d.ts +50 -5
  55. package/dist/types/signals.d.ts +424 -19
  56. package/dist/types/store/index.d.ts +1 -1
  57. package/dist/types/store/optimistic.d.ts +39 -13
  58. package/dist/types/store/projection.d.ts +48 -18
  59. package/dist/types/store/reconcile.d.ts +46 -1
  60. package/dist/types/store/store.d.ts +164 -19
  61. package/dist/types/store/storePath.d.ts +28 -0
  62. package/dist/types/store/utils.d.ts +78 -7
  63. package/dist/types-cjs/affects.d.cts +47 -0
  64. package/dist/types-cjs/boundaries.d.cts +93 -11
  65. package/dist/types-cjs/core/action.d.cts +63 -0
  66. package/dist/types-cjs/core/async.d.cts +16 -1
  67. package/dist/types-cjs/core/constants.d.cts +46 -0
  68. package/dist/types-cjs/core/context.d.cts +10 -2
  69. package/dist/types-cjs/core/core.d.cts +111 -17
  70. package/dist/types-cjs/core/dev.d.cts +17 -2
  71. package/dist/types-cjs/core/effect.d.cts +1 -2
  72. package/dist/types-cjs/core/error.d.cts +33 -0
  73. package/dist/types-cjs/core/external.d.cts +0 -11
  74. package/dist/types-cjs/core/graph.d.cts +2 -1
  75. package/dist/types-cjs/core/heap.d.cts +8 -0
  76. package/dist/types-cjs/core/index.d.cts +3 -2
  77. package/dist/types-cjs/core/invariants.d.cts +59 -0
  78. package/dist/types-cjs/core/lanes.d.cts +2 -0
  79. package/dist/types-cjs/core/optimistic.d.cts +6 -0
  80. package/dist/types-cjs/core/owner.d.cts +101 -3
  81. package/dist/types-cjs/core/scheduler.d.cts +97 -9
  82. package/dist/types-cjs/core/types.d.cts +68 -6
  83. package/dist/types-cjs/core/verdict.d.cts +2 -0
  84. package/dist/types-cjs/index.d.cts +4 -3
  85. package/dist/types-cjs/map.d.cts +50 -5
  86. package/dist/types-cjs/signals.d.cts +424 -19
  87. package/dist/types-cjs/store/index.d.cts +1 -1
  88. package/dist/types-cjs/store/optimistic.d.cts +39 -13
  89. package/dist/types-cjs/store/projection.d.cts +48 -18
  90. package/dist/types-cjs/store/reconcile.d.cts +46 -1
  91. package/dist/types-cjs/store/store.d.cts +164 -19
  92. package/dist/types-cjs/store/storePath.d.cts +28 -0
  93. package/dist/types-cjs/store/utils.d.cts +78 -7
  94. package/package.json +14 -11
  95. package/dist/prod.js +0 -3577
@@ -0,0 +1,59 @@
1
+ import type { OptimisticLane } from "./lanes.cjs";
2
+ import type { Computed, Signal } from "./types.cjs";
3
+ /**
4
+ * Test-mode invariant checks for the async/transition/lane machinery.
5
+ * Catalog and rationale: packages/solid-signals/INTERNALS-ASYNC-STATE.md.
6
+ *
7
+ * These are implementation self-consistency checks, not semantic rules: a
8
+ * violation means the reactive system contradicted itself.
9
+ *
10
+ * They are gated on `__TEST__` (not just `__DEV__`): the per-write Set
11
+ * tracking and per-flush quiescence sweep are too expensive for shipped dev
12
+ * builds and for benchmarks (they showed up as a 5-21% hit across the
13
+ * CodSpeed suite when they ran under `__DEV__`). Call sites stay `__DEV__`
14
+ * guarded so production tree-shakes the calls; each entry point here
15
+ * early-returns unless `__TEST__` is set, so dev builds pay only a no-op
16
+ * call. The test suite (vitest run) defines `__TEST__: true`; benchmark mode
17
+ * defines `__TEST__: false`.
18
+ */
19
+ type AnyNode = Signal<any> | Computed<any>;
20
+ /** Wired by core.ts at module init to avoid import cycles. */
21
+ export declare const InvariantHooks: {
22
+ pendingProbeActive: (() => boolean) | null;
23
+ /** Fresh oracle for what an isPending companion SHOULD read right now. */
24
+ computePendingState: ((node: AnyNode) => boolean) | null;
25
+ };
26
+ export declare function devTrackHeldPending(node: AnyNode): void;
27
+ export declare function devTrackCompanionOwner(node: AnyNode): void;
28
+ export declare function devTrackOptimistic(node: AnyNode): void;
29
+ export declare function devTrackAffects(node: AnyNode): void;
30
+ /**
31
+ * Open/close the sanctioned registration window. Call sites are `__DEV__`
32
+ * guarded (no prod cost); the code inside the window must not throw.
33
+ */
34
+ export declare function beginAsyncReporterWrites(): void;
35
+ export declare function endAsyncReporterWrites(): void;
36
+ export declare function createAsyncReporters(): Map<Computed<any>, Set<Computed<any>>>;
37
+ /**
38
+ * INV-2: a node with an *active* override must be registered for reversion in
39
+ * the queue's or a transition's `_optimisticNodes`. An unregistered active
40
+ * override would survive transition completion forever. Runs at the end of
41
+ * every flush (not just quiescence — the invariant holds mid-transition).
42
+ * (There is no revert-target requirement: authoritative values commit
43
+ * silently into `_value` under the override mask — A17 — so reverting is
44
+ * just dropping the override.)
45
+ */
46
+ export declare function devCheckActiveOverrides(isRegisteredForRevert: (node: AnyNode) => boolean): void;
47
+ /** INV-1: an isPending() probe must never leak past its own call. */
48
+ export declare function devCheckFlushStart(): void;
49
+ /** INV-5: a merged lane's work moved to its root on merge and must stay empty. */
50
+ export declare function devCheckMergedLaneEmpty(lane: OptimisticLane): void;
51
+ export declare function devCensusCompanions(isQueuedForCommit?: (node: AnyNode) => boolean): void;
52
+ /**
53
+ * Quiescence checks. Run only when the system is fully drained: nothing
54
+ * scheduled, no active/stashed transitions, no live lanes. At that point no
55
+ * transition-scoped state may survive, and the lazily-created companions must
56
+ * agree with a fresh computation of their owner's state.
57
+ */
58
+ export declare function devCheckQuiescent(isQueuedForCommit: (node: AnyNode) => boolean): void;
59
+ export {};
@@ -37,6 +37,8 @@ export declare function resolveLane(el: {
37
37
  export declare function resolveTransition(el: {
38
38
  _optimisticLane?: OptimisticLane;
39
39
  _transition?: Transition | null;
40
+ _overrideValue?: any;
41
+ _overrideOwner?: Transition | null;
40
42
  }): Transition | null | undefined;
41
43
  /**
42
44
  * Check if a node has an active optimistic override.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Installs the engine's hooks. Idempotent; called by every module that can
3
+ * create optimistic state (verdict.ts at module top level, createOptimistic
4
+ * and createOptimisticStore at first call) BEFORE any optimistic node exists.
5
+ */
6
+ export declare function installOptimisticEngine(): void;
@@ -2,21 +2,119 @@ import type { Computed, Disposable, Owner, Root } from "./types.cjs";
2
2
  export declare function markDisposal(el: Owner): void;
3
3
  export declare function dispose(node: Computed<unknown>): void;
4
4
  export declare function disposeChildren(node: Owner, self?: boolean, zombie?: boolean): void;
5
+ /**
6
+ * Allocates and returns the next stable child id for `owner`. Used by
7
+ * hydration plumbing and `createUniqueId`. Not part of the user-facing API.
8
+ *
9
+ * @internal
10
+ */
5
11
  export declare function getNextChildId(owner: Owner): string;
12
+ /**
13
+ * The id a freshly-created node inherits: an explicit `options.id` wins;
14
+ * transparent nodes share their parent's id; otherwise the parent's next
15
+ * child id is consumed (or `undefined` outside an id-carrying tree).
16
+ */
17
+ export declare function inheritId(options: {
18
+ id?: string;
19
+ } | undefined, transparent: boolean, parent: Owner | null | undefined): string | undefined;
20
+ /**
21
+ * Returns the *next* child id for `owner` without consuming it. Used by
22
+ * hydration plumbing to peek at the id a future child will receive.
23
+ *
24
+ * @internal
25
+ */
6
26
  export declare function peekNextChildId(owner: Owner): string;
27
+ /**
28
+ * Returns the currently-tracking observer (the computation that subscribes to
29
+ * reactive reads at this point), or `null` if reads here would be untracked.
30
+ * Used by reactive primitives that need to know whether they're inside a
31
+ * tracking scope. App code rarely needs this — see `getOwner()` for the
32
+ * lifecycle owner instead.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * // Library predicate: only register a hot-path subscription when the
37
+ * // caller is inside a tracking scope (memo / effect compute / JSX).
38
+ * function trackIfTracked(source: () => unknown) {
39
+ * if (getObserver()) source();
40
+ * }
41
+ * ```
42
+ */
7
43
  export declare function getObserver(): Owner | null;
44
+ /**
45
+ * Returns the current reactive **owner** — the lifecycle node that the next
46
+ * `cleanup()` / `onCleanup()` / `createSignal()` etc. will be attached to.
47
+ *
48
+ * Returns `null` if called outside any owner. Capture the owner with
49
+ * `getOwner()` and re-enter it later with `runWithOwner(owner, fn)` to attach
50
+ * disposables created from a callback (event handler, async resolution, etc.)
51
+ * back to a component's lifecycle.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * function defer<T>(fn: () => T) {
56
+ * const owner = getOwner();
57
+ * queueMicrotask(() => runWithOwner(owner, fn));
58
+ * }
59
+ * ```
60
+ */
8
61
  export declare function getOwner(): Owner | null;
62
+ /**
63
+ * Low-level: registers `fn` as a disposal callback on the current owner.
64
+ * Most code should use `onCleanup()` from `solid-js`, which adds dev-mode
65
+ * checks. `cleanup()` is the unchecked primitive used by internals.
66
+ */
9
67
  export declare function cleanup(fn: Disposable): Disposable;
68
+ /**
69
+ * Returns `true` if the owner has been disposed (or marked zombie pending
70
+ * disposal). Pair with a captured owner to bail out of late callbacks whose
71
+ * surrounding component already unmounted.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * function onSettleSafe(fn: () => void) {
76
+ * const owner = getOwner();
77
+ * queueMicrotask(() => {
78
+ * if (owner && isDisposed(owner)) return; // component unmounted; skip
79
+ * runWithOwner(owner, fn);
80
+ * });
81
+ * }
82
+ * ```
83
+ */
10
84
  export declare function isDisposed(node: Owner): boolean;
85
+ /**
86
+ * Creates a fresh owner attached as a child of the current owner (or as a
87
+ * detached root if there is none). Used by framework internals to group
88
+ * cleanups; app code should use `createRoot()` (host a reactive scope outside
89
+ * a component) or `runWithOwner()` (re-enter a captured owner).
90
+ *
91
+ * @internal
92
+ */
11
93
  export declare function createOwner(options?: {
12
94
  id?: string;
13
95
  transparent?: boolean;
14
96
  }): Root;
15
97
  /**
16
- * Creates a new non-tracked reactive context with manual disposal
98
+ * Creates a detached reactive root. The callback receives a `dispose()`
99
+ * function which, when called, tears down every signal, memo, effect, and
100
+ * `onCleanup` registered inside the root.
101
+ *
102
+ * Use this to host long-lived reactive scopes outside of a component (custom
103
+ * controllers, app bootstrapping, tests). Inside a component, prefer
104
+ * letting Solid's component lifecycle own things.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * const dispose = createRoot(dispose => {
109
+ * const [n, setN] = createSignal(0);
110
+ * createEffect(() => n(), value => console.log(value));
111
+ * setInterval(() => setN(x => x + 1), 1000);
112
+ * return dispose;
113
+ * });
17
114
  *
18
- * @param fn a function in which the reactive state is scoped
19
- * @returns the output of `fn`.
115
+ * // Later, to tear everything down:
116
+ * dispose();
117
+ * ```
20
118
  *
21
119
  * @description https://docs.solidjs.com/reference/reactive-utilities/create-root
22
120
  */
@@ -1,5 +1,5 @@
1
1
  import { type Heap } from "./heap.cjs";
2
- import { activeLanes, assignOrMergeLane, findLane } from "./lanes.cjs";
2
+ import { activeLanes, assignOrMergeLane, findLane, type OptimisticLane } from "./lanes.cjs";
3
3
  import type { Computed, Signal } from "./types.cjs";
4
4
  export { activeLanes, assignOrMergeLane, findLane };
5
5
  export { getOrCreateLane, hasActiveOverride, mergeLanes, resolveLane } from "./lanes.cjs";
@@ -11,8 +11,15 @@ export declare let projectionWriteActive: boolean;
11
11
  export declare let _hitUnhandledAsync: boolean;
12
12
  export declare function registerTransientStoreNode(node: Signal<any>): void;
13
13
  export declare function resetUnhandledAsync(): void;
14
+ /**
15
+ * Toggles the dev-mode "must be inside a `<Loading>` boundary" enforcement
16
+ * window. Only `render()` calls this — wrapping the initial mount so that a
17
+ * top-level uncaught async read surfaces the diagnostic. Not part of the
18
+ * user-facing API.
19
+ *
20
+ * @internal
21
+ */
14
22
  export declare function enforceLoadingBoundary(enabled: boolean): void;
15
- export declare function shouldReadStashedOptimisticValue(node: Signal<any>): boolean;
16
23
  export declare function setProjectionWriteActive(value: boolean): void;
17
24
  export declare function setTrackedQueueCallback(value: boolean): void;
18
25
  export type QueueCallback = (type: number) => void;
@@ -26,12 +33,22 @@ export interface Transition {
26
33
  _asyncReporters: Map<Computed<any>, Set<Computed<any>>>;
27
34
  _pendingNodes: Signal<any>[];
28
35
  _optimisticNodes: OptimisticNode[];
36
+ _affectsNodes: OptimisticNode[];
29
37
  _optimisticStores: Set<any>;
30
38
  _actions: Array<Generator<any, any, any> | AsyncGenerator<any, any, any>>;
31
39
  _queueStash: QueueStub;
32
40
  _done: boolean | Transition;
41
+ _gatedSubs: Set<Computed<any>>;
33
42
  }
34
43
  export declare function schedule(): void;
44
+ /**
45
+ * Permanently halts the reactive system. Called when a user error escapes
46
+ * every boundary — app state is undefined at that point, so scheduling stops
47
+ * entirely rather than limping along with a half-applied update.
48
+ */
49
+ export declare function haltReactivity(cause?: unknown): void;
50
+ /** @internal Test/dev-reload hook. Revives scheduling after a halt. */
51
+ export declare function resetErrorHalt(): void;
35
52
  export interface IQueue {
36
53
  enqueue(type: number, fn: QueueCallback): void;
37
54
  run(type: number): boolean | void;
@@ -47,6 +64,7 @@ export declare class Queue implements IQueue {
47
64
  _parent: IQueue | null;
48
65
  _queues: [QueueCallback[], QueueCallback[]];
49
66
  _children: IQueue[];
67
+ _ranAt: number;
50
68
  created: number;
51
69
  addChild(child: IQueue): void;
52
70
  removeChild(child: IQueue): void;
@@ -58,25 +76,95 @@ export declare class Queue implements IQueue {
58
76
  }
59
77
  export declare class GlobalQueue extends Queue {
60
78
  _running: boolean;
61
- _pendingNodes: Signal<any>[];
62
- _optimisticNodes: OptimisticNode[];
63
- _optimisticStores: Set<any>;
79
+ _batch: Transition;
64
80
  static _update: (el: Computed<unknown>) => void;
65
81
  static _dispose: (el: Computed<unknown>, self: boolean, zombie: boolean) => void;
66
- static _clearOptimisticStore: ((store: any) => void) | null;
82
+ static _runEffect: (el: Computed<unknown>) => void;
83
+ static _clearOptimisticStores: ((stores: Set<any>, completing: Transition | null) => void) | null;
84
+ static _releaseAffectsScope: ((node: OptimisticNode) => void) | null;
85
+ static _releaseAffectsMarks: ((nodes: OptimisticNode[]) => void) | null;
86
+ static _markAffects: ((node: OptimisticNode) => void) | null;
87
+ static _releaseAffectsMark: ((node: OptimisticNode) => void) | null;
88
+ static _wireExternalSource: ((self: Computed<any>) => void) | null;
89
+ static _externalUntrack: (<T>(fn: () => T) => T) | null;
90
+ static _syncCompanions: (<T>(el: Signal<T> | Computed<T>, value: T) => void) | null;
91
+ static _updatePendingSignal: ((el: OptimisticNode) => void) | null;
92
+ static _updateChildCompanions: ((el: Computed<any>) => void) | null;
93
+ static _snapCompanions: ((el: OptimisticNode) => void) | null;
94
+ static _latestRead: (<T>(el: Signal<T> | Computed<T>) => T) | null;
95
+ static _pendingCheck: ((el: OptimisticNode, c: Computed<any> | null, owner: OptimisticNode, firewall: Computed<any> | null) => void) | null;
96
+ static _recordFresh: ((el: OptimisticNode, value: any) => void) | null;
97
+ static _applyReask: ((el: Computed<any>, hadReask: boolean) => boolean) | null;
98
+ static _repollVerdicts: ((el: Computed<any>, snap?: boolean) => void) | null;
99
+ static _witnessAffects: ((node: OptimisticNode) => void) | null;
100
+ static _optimisticWrite: (<T>(el: Signal<T> | Computed<T>, v: T | ((prev: T) => T)) => T) | null;
101
+ static _resolveOptimistic: ((nodes: OptimisticNode[]) => void) | null;
102
+ static _transitionBlocked: ((transition: Transition) => boolean) | null;
103
+ static _cleanupLanes: ((completingTransition: Transition | null) => void) | null;
104
+ static _runLaneEffects: ((type: number) => void) | null;
105
+ static _gatedRead: ((el: Signal<any>, owner: OptimisticNode, c: Computed<any>) => boolean) | null;
106
+ static _laneSuspends: ((owner: OptimisticNode) => boolean) | null;
107
+ static _laneReadsCommitted: ((el: OptimisticNode, owner: OptimisticNode, c: Computed<any>) => boolean) | null;
108
+ static _recomputeLane: ((el: Computed<any>, own: boolean) => OptimisticLane | null) | null;
109
+ static _laneAsyncPending: ((el: Computed<any>) => void) | null;
110
+ static _laneAsyncSettled: ((el: Computed<any>) => void) | null;
111
+ static _trackOptimisticStore: ((store: any) => void) | null;
67
112
  flush(): void;
68
113
  notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean;
69
114
  initTransition(transition?: Transition | null): void;
70
115
  }
116
+ export declare function queuePendingNode(node: Signal<any>): void;
117
+ export declare function armReaskClear(): void;
71
118
  export declare function insertSubs(node: Signal<any> | Computed<any>, optimistic?: boolean): void;
72
119
  export declare function finalizePureQueue(completingTransition?: Transition | null, incomplete?: boolean): void;
73
- export declare function trackOptimisticStore(store: any): void;
120
+ /**
121
+ * Count of live `affects()` registrations across the system (including
122
+ * store-scope inherited marks). Gates the read-path mark check in `read()` so
123
+ * graphs that never use the feature pay one integer compare.
124
+ */
125
+ export declare let activeAffectsMarks: number;
126
+ /**
127
+ * Counter mutation seam for the mark engine in affects.ts: an imported `let`
128
+ * binding is read-only, and the read-path gate above must stay a plain module
129
+ * variable so `read()` pays one integer compare, not a function call.
130
+ *
131
+ * @internal
132
+ */
133
+ export declare function shiftAffectsMarks(delta: 1 | -1): void;
74
134
  export declare const globalQueue: GlobalQueue;
75
135
  /**
76
- * By default, changes are batched on the microtask queue which is an async process. You can flush
77
- * the queue synchronously to get the latest updates by calling `flush()`.
136
+ * Synchronously processes the pending reactive queue, or runs `fn` in a synchronous
137
+ * flush scope before draining the queue.
138
+ *
139
+ * Reactive updates are normally batched onto the microtask queue, so multiple
140
+ * writes in a row collapse into a single update pass. Call `flush()` when you
141
+ * need to *observe* the result of those writes synchronously — most commonly
142
+ * in tests, but also at the boundary of imperative integration code. Pass a
143
+ * callback when the writes themselves should bypass microtask scheduling and
144
+ * drain synchronously when the callback returns.
145
+ *
146
+ * @example
147
+ * ```ts
148
+ * const [count, setCount] = createSignal(0);
149
+ * const doubled = createMemo(() => count() * 2);
150
+ *
151
+ * setCount(5);
152
+ * flush();
153
+ * expect(doubled()).toBe(10);
154
+ *
155
+ * flush(() => setCount(6));
156
+ * expect(doubled()).toBe(12);
157
+ *
158
+ * // Nested flushes drain at each level:
159
+ * flush(() => {
160
+ * setCount(7);
161
+ * flush(() => setCount(8)); // inner drain — effects fire here
162
+ * // outer continues with up-to-date state
163
+ * });
164
+ * ```
78
165
  */
79
166
  export declare function flush(): void;
167
+ export declare function flush<T>(fn: () => T): T;
80
168
  export declare function currentTransition(transition: Transition): Transition;
81
169
  export declare function setActiveTransition(transition: Transition | null): void;
82
170
  export declare function runInTransition<T>(transition: Transition, fn: () => T): T;
@@ -10,6 +10,14 @@ export interface Link {
10
10
  _nextDep: Link | null;
11
11
  _prevSub: Link | null;
12
12
  _nextSub: Link | null;
13
+ /**
14
+ * `_sub._depGen` at the time this link was created or last revalidated
15
+ * in-order. A link stamped with the subscriber's current pass generation is
16
+ * inside the validated `[deps.._depsTail]` prefix — an O(1) replacement for
17
+ * scanning the dep list to answer membership (see `link()`).
18
+ */
19
+ _gen: number;
20
+ _pendingObserver?: boolean;
13
21
  }
14
22
  export interface NodeOptions<T> {
15
23
  id?: string;
@@ -21,6 +29,17 @@ export interface NodeOptions<T> {
21
29
  _noSnapshot?: boolean;
22
30
  unobserved?: () => void;
23
31
  lazy?: boolean;
32
+ sync?: boolean;
33
+ /**
34
+ * Commit #0. When present (checked with `in`, so an explicit `undefined`
35
+ * counts), the node is born committed with this value instead of
36
+ * STATUS_UNINITIALIZED: reads serve it everywhere, nothing suspends to
37
+ * Loading boundaries, transitions are never held, and the window is
38
+ * verdict-quiet (`isPending` stays false — commit #0 answers the question
39
+ * by declaration; first-load affordances live in the value itself). After
40
+ * the first real answer lands, normal refetch/pending semantics apply.
41
+ */
42
+ loadingValue?: T;
24
43
  }
25
44
  export interface RawSignal<T> {
26
45
  _subs: Link | null;
@@ -29,17 +48,35 @@ export interface RawSignal<T> {
29
48
  _snapshotValue?: any;
30
49
  _name?: string;
31
50
  _equals: false | ((a: T, b: T) => boolean);
32
- _ownedWrite?: boolean;
33
- _noSnapshot?: boolean;
51
+ _config: number;
34
52
  _unobserved?: () => void;
35
53
  _time: number;
36
54
  _transition: Transition | null;
37
55
  _pendingValue: T | typeof NOT_PENDING;
38
56
  _overrideValue?: T | typeof NOT_PENDING;
57
+ /**
58
+ * The transaction that owns the active override (stamped at optimistic
59
+ * write, cleared at settle). Ownership must live on the node: a lane's
60
+ * _transition is a scheduling affinity that a shared subscriber can merge
61
+ * across transactions (#2912) — following it would let one action's settle
62
+ * revert another action's live override. Node-level sibling of the store
63
+ * layer's STORE_OPTIMISTIC_OWNERS stamps (#2899). `null` = ambient write.
64
+ */
65
+ _overrideOwner?: Transition | null;
39
66
  _optimisticLane?: OptimisticLane;
40
67
  _pendingSignal?: Signal<boolean>;
41
68
  _latestValueComputed?: Computed<T>;
42
69
  _parentSource?: Signal<any> | Computed<any>;
70
+ /**
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.
78
+ */
79
+ _affectsCount?: number;
43
80
  }
44
81
  export interface FirewallSignal<T> extends RawSignal<T> {
45
82
  _firewall: Computed<any>;
@@ -48,9 +85,10 @@ export interface FirewallSignal<T> extends RawSignal<T> {
48
85
  export type Signal<T> = RawSignal<T> | FirewallSignal<T>;
49
86
  export interface Owner {
50
87
  id?: string;
51
- _transparent?: boolean;
52
- _childrenForbidden?: boolean;
88
+ _config: number;
53
89
  _snapshotScope?: boolean;
90
+ /** Effect-returned cleanup; managed across reruns, invoked at true disposal */
91
+ _cleanup?: () => void;
54
92
  _disposal: Disposable | Disposable[] | null;
55
93
  _parent: Owner | null;
56
94
  _context: Record<symbol | string, unknown>;
@@ -58,16 +96,17 @@ export interface Owner {
58
96
  _queue: IQueue;
59
97
  _firstChild: Owner | null;
60
98
  _nextSibling: Owner | null;
99
+ _prevSibling: Owner | null;
61
100
  _pendingDisposal: Disposable | Disposable[] | null;
62
101
  _pendingFirstChild: Owner | null;
63
102
  }
64
103
  export interface Computed<T> extends RawSignal<T>, Owner {
65
104
  _deps: Link | null;
66
105
  _depsTail: Link | null;
106
+ /** Recompute-pass counter; bumped when dep revalidation starts. */
107
+ _depGen: number;
67
108
  _flags: number;
68
- _inSnapshotScope?: boolean;
69
109
  _blocked?: boolean;
70
- _pendingSource?: Computed<any>;
71
110
  _pendingSources?: Set<Computed<any>>;
72
111
  _error?: unknown;
73
112
  _statusFlags: number;
@@ -78,6 +117,29 @@ export interface Computed<T> extends RawSignal<T>, Owner {
78
117
  _inFlight: PromiseLike<T> | AsyncIterable<T> | null;
79
118
  _child: FirewallSignal<any> | null;
80
119
  _notifyStatus?: (status?: number, error?: any) => void;
120
+ /**
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.
127
+ */
128
+ _reask: boolean;
129
+ /**
130
+ * True while a `loadingValue` node's first real answer hasn't landed: the
131
+ * node was born committed (commit #0 = the loading value) and `handleAsync`
132
+ * serves that committed value instead of throwing NotReadyError, so first
133
+ * flights never suspend readers, trip boundaries, or hold transitions.
134
+ * The window is verdict-quiet: `isPending` stays false, because commit #0
135
+ * answers the question by declaration (first-load affordances belong to
136
+ * the value channel). Cleared by the first value landing on any path (sync
137
+ * return, sync-resolved promise, first iterator yield, async settle); a
138
+ * real error leaves it set — errors answer reads but don't enter the value
139
+ * lineage, so a retry serves the loading value again. Once cleared, normal
140
+ * pending/refetch semantics apply forever.
141
+ */
142
+ _loading: boolean;
81
143
  }
82
144
  export interface Root extends Owner {
83
145
  _root: true;
@@ -0,0 +1,2 @@
1
+ export declare function latest<T>(fn: () => T): T;
2
+ export declare function isPending(fn: () => any): boolean;
@@ -1,9 +1,10 @@
1
- export { $REFRESH, ContextNotFoundError, NoOwnerError, NotReadyError, action, createContext, createOwner, createRoot, runWithOwner, flush, getNextChildId, peekNextChildId, getContext, setContext, getOwner, isDisposed, getObserver, isEqual, untrack, isPending, latest, isRefreshing, refresh, SUPPORTS_PROXY, setSnapshotCapture, markSnapshotScope, releaseSnapshotScope, clearSnapshots, enforceLoadingBoundary, enableExternalSource } from "./core/index.cjs";
1
+ export { $REFRESH, ContextNotFoundError, NoOwnerError, NotReadyError, action, createContext, createOwner, createRoot, runWithOwner, flush, getNextChildId, peekNextChildId, getContext, setContext, getOwner, isDisposed, getObserver, isEqual, untrack, isPending, latest, refresh, SUPPORTS_PROXY, setSnapshotCapture, markSnapshotScope, releaseSnapshotScope, clearSnapshots, enforceLoadingBoundary, enableExternalSource, resetErrorHalt } from "./core/index.cjs";
2
2
  import { type Dev } from "./core/index.cjs";
3
3
  export declare const DEV: Dev | undefined;
4
- export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.cjs";
4
+ export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Refreshable, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.cjs";
5
5
  export { createSignal, createMemo, createEffect, createRenderEffect, createTrackedEffect, createReaction, createOptimistic, resolve, onSettled, onCleanup } from "./signals.cjs";
6
- export type { Accessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.cjs";
6
+ export type { Accessor, SourceAccessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.cjs";
7
+ export { affects } from "./affects.cjs";
7
8
  export { mapArray, repeat, type Maybe } from "./map.cjs";
8
9
  export * from "./store/index.cjs";
9
10
  export { createLoadingBoundary, createErrorBoundary, createRevealOrder, flatten, type RevealOrder } from "./boundaries.cjs";
@@ -1,19 +1,64 @@
1
1
  import { type Accessor } from "./signals.cjs";
2
2
  export type Maybe<T> = T | void | null | undefined | false;
3
3
  /**
4
- * Reactively transforms an array with a callback function - underlying helper for the `<For>` control flow
4
+ * Reactively maps an array, reusing the previously-mapped value for unchanged
5
+ * items.
5
6
  *
6
- * similar to `Array.prototype.map`, but gets the value and index as accessors, transforms only values that changed and returns an accessor and reactively tracks changes to the list.
7
+ * The callback shape follows the keying mode:
8
+ * - default / `keyed: true` receives `(item, index)` where `item` is the raw
9
+ * row value and `index` is an accessor.
10
+ * - `keyed: false` receives `(item, index)` where `item` is an accessor and
11
+ * `index` is a stable number.
12
+ * - `keyed: item => key` receives accessors for both arguments.
13
+ *
14
+ * This is the underlying helper that powers `<For>`. App code should use
15
+ * `<For>` directly; reach for `mapArray` when implementing custom list
16
+ * components.
17
+ *
18
+ * - `options.keyed` — `true` (default for primitives) compares by identity;
19
+ * `false` falls back to index-only mapping; pass a function `(item) => key`
20
+ * for stable identity by extracted key.
21
+ * - `options.fallback` — accessor returning a value to show when the input is
22
+ * empty.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const view = mapArray(
27
+ * items,
28
+ * (item, index) => `${index()}: ${item.label}`,
29
+ * { fallback: () => "no items" }
30
+ * );
31
+ * ```
7
32
  *
8
33
  * @description https://docs.solidjs.com/reference/reactive-utilities/map-array
9
34
  */
10
- export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
11
- keyed?: boolean | ((item: Item) => any);
35
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Item, index: Accessor<number>) => MappedItem, options?: {
36
+ keyed?: true;
37
+ fallback?: Accessor<any>;
38
+ name?: string;
39
+ }): Accessor<MappedItem[]>;
40
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: number) => MappedItem, options: {
41
+ keyed: false;
42
+ fallback?: Accessor<any>;
43
+ name?: string;
44
+ }): Accessor<MappedItem[]>;
45
+ export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options: {
46
+ keyed: (item: Item) => any;
12
47
  fallback?: Accessor<any>;
13
48
  name?: string;
14
49
  }): Accessor<MappedItem[]>;
15
50
  /**
16
- * Reactively repeats a callback function the count provided - underlying helper for the `<Repeat>` control flow
51
+ * Reactively renders a callback `count` times, reusing previously-rendered
52
+ * entries when only the count changes. Underlying helper for `<Repeat>`.
53
+ *
54
+ * - `options.from` — start index (default `0`); useful for offset/windowed
55
+ * rendering.
56
+ * - `options.fallback` — accessor returning a value to show when count is `0`.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * const view = repeat(count, i => `Item ${i}`, { fallback: () => "empty" });
61
+ * ```
17
62
  *
18
63
  * @description https://docs.solidjs.com/reference/reactive-utilities/repeat
19
64
  */