@solidjs/signals 2.0.0-beta.9 → 2.0.0-rc.1

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 (106) hide show
  1. package/README.md +14 -10
  2. package/dist/dev.js +6740 -2011
  3. package/dist/node.cjs +7927 -3340
  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 +607 -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 +828 -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 +262 -0
  20. package/dist/prod/core/owner.js +302 -0
  21. package/dist/prod/core/scheduler.js +757 -0
  22. package/dist/prod/core/verdict.js +369 -0
  23. package/dist/prod/index.js +45 -0
  24. package/dist/prod/map.js +319 -0
  25. package/dist/prod/signals.js +394 -0
  26. package/dist/prod/store/index.js +36 -0
  27. package/dist/prod/store/next/optimistic.js +377 -0
  28. package/dist/prod/store/next/projection.js +172 -0
  29. package/dist/prod/store/next/reconcile.js +327 -0
  30. package/dist/prod/store/next/store.js +1232 -0
  31. package/dist/prod/store/next/target.js +20 -0
  32. package/dist/prod/store/store.js +325 -0
  33. package/dist/prod/store/storePath.js +103 -0
  34. package/dist/prod/store/utils.js +201 -0
  35. package/dist/types/affects.d.ts +47 -0
  36. package/dist/types/boundaries.d.ts +60 -13
  37. package/dist/types/core/action.d.ts +35 -6
  38. package/dist/types/core/async.d.ts +16 -1
  39. package/dist/types/core/constants.d.ts +35 -6
  40. package/dist/types/core/context.d.ts +10 -2
  41. package/dist/types/core/core.d.ts +66 -63
  42. package/dist/types/core/dev.d.ts +17 -2
  43. package/dist/types/core/effect.d.ts +1 -2
  44. package/dist/types/core/error.d.ts +33 -0
  45. package/dist/types/core/external.d.ts +0 -11
  46. package/dist/types/core/graph.d.ts +2 -1
  47. package/dist/types/core/heap.d.ts +8 -0
  48. package/dist/types/core/index.d.ts +3 -2
  49. package/dist/types/core/invariants.d.ts +59 -0
  50. package/dist/types/core/lanes.d.ts +2 -0
  51. package/dist/types/core/optimistic.d.ts +6 -0
  52. package/dist/types/core/owner.d.ts +50 -3
  53. package/dist/types/core/scheduler.d.ts +85 -11
  54. package/dist/types/core/types.d.ts +66 -1
  55. package/dist/types/core/verdict.d.ts +2 -0
  56. package/dist/types/index.d.ts +3 -2
  57. package/dist/types/map.d.ts +21 -5
  58. package/dist/types/signals.d.ts +183 -12
  59. package/dist/types/store/index.d.ts +16 -6
  60. package/dist/types/store/next/optimistic.d.ts +20 -0
  61. package/dist/types/store/next/projection.d.ts +24 -0
  62. package/dist/types/store/next/reconcile.d.ts +3 -0
  63. package/dist/types/store/next/store.d.ts +71 -0
  64. package/dist/types/store/next/target.d.ts +99 -0
  65. package/dist/types/store/optimistic.d.ts +3 -3
  66. package/dist/types/store/projection.d.ts +10 -6
  67. package/dist/types/store/reconcile.d.ts +31 -8
  68. package/dist/types/store/store.d.ts +91 -71
  69. package/dist/types/store/utils.d.ts +0 -40
  70. package/dist/types-cjs/affects.d.cts +47 -0
  71. package/dist/types-cjs/boundaries.d.cts +60 -13
  72. package/dist/types-cjs/core/action.d.cts +35 -6
  73. package/dist/types-cjs/core/async.d.cts +16 -1
  74. package/dist/types-cjs/core/constants.d.cts +35 -6
  75. package/dist/types-cjs/core/context.d.cts +10 -2
  76. package/dist/types-cjs/core/core.d.cts +66 -63
  77. package/dist/types-cjs/core/dev.d.cts +17 -2
  78. package/dist/types-cjs/core/effect.d.cts +1 -2
  79. package/dist/types-cjs/core/error.d.cts +33 -0
  80. package/dist/types-cjs/core/external.d.cts +0 -11
  81. package/dist/types-cjs/core/graph.d.cts +2 -1
  82. package/dist/types-cjs/core/heap.d.cts +8 -0
  83. package/dist/types-cjs/core/index.d.cts +3 -2
  84. package/dist/types-cjs/core/invariants.d.cts +59 -0
  85. package/dist/types-cjs/core/lanes.d.cts +2 -0
  86. package/dist/types-cjs/core/optimistic.d.cts +6 -0
  87. package/dist/types-cjs/core/owner.d.cts +50 -3
  88. package/dist/types-cjs/core/scheduler.d.cts +85 -11
  89. package/dist/types-cjs/core/types.d.cts +66 -1
  90. package/dist/types-cjs/core/verdict.d.cts +2 -0
  91. package/dist/types-cjs/index.d.cts +3 -2
  92. package/dist/types-cjs/map.d.cts +21 -5
  93. package/dist/types-cjs/signals.d.cts +183 -12
  94. package/dist/types-cjs/store/index.d.cts +16 -6
  95. package/dist/types-cjs/store/next/optimistic.d.cts +20 -0
  96. package/dist/types-cjs/store/next/projection.d.cts +24 -0
  97. package/dist/types-cjs/store/next/reconcile.d.cts +3 -0
  98. package/dist/types-cjs/store/next/store.d.cts +71 -0
  99. package/dist/types-cjs/store/next/target.d.cts +99 -0
  100. package/dist/types-cjs/store/optimistic.d.cts +3 -3
  101. package/dist/types-cjs/store/projection.d.cts +10 -6
  102. package/dist/types-cjs/store/reconcile.d.cts +31 -8
  103. package/dist/types-cjs/store/store.d.cts +91 -71
  104. package/dist/types-cjs/store/utils.d.cts +0 -40
  105. package/package.json +12 -9
  106. package/dist/prod.js +0 -3627
@@ -0,0 +1,59 @@
1
+ import type { OptimisticLane } from "./lanes.js";
2
+ import type { Computed, Signal } from "./types.js";
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,7 +2,27 @@ import type { Computed, Disposable, Owner, Root } from "./types.js";
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;
7
27
  /**
8
28
  * Returns the currently-tracking observer (the computation that subscribes to
@@ -10,6 +30,15 @@ export declare function peekNextChildId(owner: Owner): string;
10
30
  * Used by reactive primitives that need to know whether they're inside a
11
31
  * tracking scope. App code rarely needs this — see `getOwner()` for the
12
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
+ * ```
13
42
  */
14
43
  export declare function getObserver(): Owner | null;
15
44
  /**
@@ -36,12 +65,30 @@ export declare function getOwner(): Owner | null;
36
65
  * checks. `cleanup()` is the unchecked primitive used by internals.
37
66
  */
38
67
  export declare function cleanup(fn: Disposable): Disposable;
39
- /** Returns `true` if the owner has been disposed (or marked zombie pending disposal). */
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
+ */
40
84
  export declare function isDisposed(node: Owner): boolean;
41
85
  /**
42
86
  * Creates a fresh owner attached as a child of the current owner (or as a
43
- * detached root if there is none). Mostly used by framework internals to
44
- * group cleanups; app code should prefer `createRoot()` or `runWithOwner()`.
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
45
92
  */
46
93
  export declare function createOwner(options?: {
47
94
  id?: string;
@@ -1,5 +1,5 @@
1
1
  import { type Heap } from "./heap.js";
2
- import { activeLanes, assignOrMergeLane, findLane } from "./lanes.js";
2
+ import { activeLanes, assignOrMergeLane, findLane, type OptimisticLane } from "./lanes.js";
3
3
  import type { Computed, Signal } from "./types.js";
4
4
  export { activeLanes, assignOrMergeLane, findLane };
5
5
  export { getOrCreateLane, hasActiveOverride, mergeLanes, resolveLane } from "./lanes.js";
@@ -9,12 +9,19 @@ export declare let clock: number;
9
9
  export declare let activeTransition: Transition | null;
10
10
  export declare let projectionWriteActive: boolean;
11
11
  export declare let _hitUnhandledAsync: boolean;
12
- export declare function registerTransientStoreNode(node: Signal<any>): void;
13
12
  export declare function resetUnhandledAsync(): void;
13
+ /**
14
+ * Toggles the dev-mode "must be inside a `<Loading>` boundary" enforcement
15
+ * window. Only `render()` calls this — wrapping the initial mount so that a
16
+ * top-level uncaught async read surfaces the diagnostic. Not part of the
17
+ * user-facing API.
18
+ *
19
+ * @internal
20
+ */
14
21
  export declare function enforceLoadingBoundary(enabled: boolean): void;
15
- export declare function shouldReadStashedOptimisticValue(node: Signal<any>): boolean;
16
22
  export declare function setProjectionWriteActive(value: boolean): void;
17
23
  export declare function setTrackedQueueCallback(value: boolean): void;
24
+ export declare function setEffectCallback(value: boolean): void;
18
25
  export type QueueCallback = (type: number) => void;
19
26
  type QueueStub = {
20
27
  _queues: [QueueCallback[], QueueCallback[]];
@@ -26,6 +33,7 @@ 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;
@@ -33,6 +41,14 @@ export interface Transition {
33
41
  _gatedSubs: Set<Computed<any>>;
34
42
  }
35
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;
36
52
  export interface IQueue {
37
53
  enqueue(type: number, fn: QueueCallback): void;
38
54
  run(type: number): boolean | void;
@@ -48,6 +64,7 @@ export declare class Queue implements IQueue {
48
64
  _parent: IQueue | null;
49
65
  _queues: [QueueCallback[], QueueCallback[]];
50
66
  _children: IQueue[];
67
+ _ranAt: number;
51
68
  created: number;
52
69
  addChild(child: IQueue): void;
53
70
  removeChild(child: IQueue): void;
@@ -59,28 +76,74 @@ export declare class Queue implements IQueue {
59
76
  }
60
77
  export declare class GlobalQueue extends Queue {
61
78
  _running: boolean;
62
- _pendingNodes: Signal<any>[];
63
- _optimisticNodes: OptimisticNode[];
64
- _optimisticStores: Set<any>;
79
+ _batch: Transition;
65
80
  static _update: (el: Computed<unknown>) => void;
66
81
  static _dispose: (el: Computed<unknown>, self: boolean, zombie: boolean) => void;
67
- 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 | false) | null;
109
+ static _laneAsyncPending: ((el: Computed<any>) => void) | null;
110
+ static _laneAsyncSettled: ((el: Computed<any>) => void) | null;
111
+ static _trackOptimisticStore: ((store: any) => void) | null;
68
112
  flush(): void;
69
113
  notify(node: Computed<any>, mask: number, flags: number, error?: any): boolean;
70
114
  initTransition(transition?: Transition | null): void;
71
115
  }
116
+ export declare function queuePendingNode(node: Signal<any>): void;
117
+ export declare function armReaskClear(): void;
72
118
  export declare function insertSubs(node: Signal<any> | Computed<any>, optimistic?: boolean): void;
119
+ export declare let storeCommitHook: (() => void) | null;
120
+ export declare function setStoreCommitHook(fn: () => void): void;
73
121
  export declare function finalizePureQueue(completingTransition?: Transition | null, incomplete?: boolean): void;
74
- export declare function trackOptimisticStore(store: any): void;
122
+ /**
123
+ * Count of live `affects()` registrations across the system (including
124
+ * store-scope inherited marks). Gates the read-path mark check in `read()` so
125
+ * graphs that never use the feature pay one integer compare.
126
+ */
127
+ export declare let activeAffectsMarks: number;
128
+ /**
129
+ * Counter mutation seam for the mark engine in affects.ts: an imported `let`
130
+ * binding is read-only, and the read-path gate above must stay a plain module
131
+ * variable so `read()` pays one integer compare, not a function call.
132
+ *
133
+ * @internal
134
+ */
135
+ export declare function shiftAffectsMarks(delta: 1 | -1): void;
75
136
  export declare const globalQueue: GlobalQueue;
76
137
  /**
77
- * Synchronously processes the pending reactive queue: runs every scheduled
78
- * memo/effect/computation that has dirty inputs, until the graph is settled.
138
+ * Synchronously processes the pending reactive queue, or runs `fn` in a synchronous
139
+ * flush scope before draining the queue.
79
140
  *
80
141
  * Reactive updates are normally batched onto the microtask queue, so multiple
81
142
  * writes in a row collapse into a single update pass. Call `flush()` when you
82
143
  * need to *observe* the result of those writes synchronously — most commonly
83
- * in tests, but also at the boundary of imperative integration code.
144
+ * in tests, but also at the boundary of imperative integration code. Pass a
145
+ * callback when the writes themselves should bypass microtask scheduling and
146
+ * drain synchronously when the callback returns.
84
147
  *
85
148
  * @example
86
149
  * ```ts
@@ -90,9 +153,20 @@ export declare const globalQueue: GlobalQueue;
90
153
  * setCount(5);
91
154
  * flush();
92
155
  * expect(doubled()).toBe(10);
156
+ *
157
+ * flush(() => setCount(6));
158
+ * expect(doubled()).toBe(12);
159
+ *
160
+ * // Nested flushes drain at each level:
161
+ * flush(() => {
162
+ * setCount(7);
163
+ * flush(() => setCount(8)); // inner drain — effects fire here
164
+ * // outer continues with up-to-date state
165
+ * });
93
166
  * ```
94
167
  */
95
168
  export declare function flush(): void;
169
+ export declare function flush<T>(fn: () => T): T;
96
170
  export declare function currentTransition(transition: Transition): Transition;
97
171
  export declare function setActiveTransition(transition: Transition | null): void;
98
172
  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;
@@ -35,10 +54,29 @@ export interface RawSignal<T> {
35
54
  _transition: Transition | null;
36
55
  _pendingValue: T | typeof NOT_PENDING;
37
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;
38
66
  _optimisticLane?: OptimisticLane;
39
67
  _pendingSignal?: Signal<boolean>;
40
68
  _latestValueComputed?: Computed<T>;
41
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;
42
80
  }
43
81
  export interface FirewallSignal<T> extends RawSignal<T> {
44
82
  _firewall: Computed<any>;
@@ -49,6 +87,8 @@ export interface Owner {
49
87
  id?: string;
50
88
  _config: number;
51
89
  _snapshotScope?: boolean;
90
+ /** Effect-returned cleanup; managed across reruns, invoked at true disposal */
91
+ _cleanup?: () => void;
52
92
  _disposal: Disposable | Disposable[] | null;
53
93
  _parent: Owner | null;
54
94
  _context: Record<symbol | string, unknown>;
@@ -56,15 +96,17 @@ export interface Owner {
56
96
  _queue: IQueue;
57
97
  _firstChild: Owner | null;
58
98
  _nextSibling: Owner | null;
99
+ _prevSibling: Owner | null;
59
100
  _pendingDisposal: Disposable | Disposable[] | null;
60
101
  _pendingFirstChild: Owner | null;
61
102
  }
62
103
  export interface Computed<T> extends RawSignal<T>, Owner {
63
104
  _deps: Link | null;
64
105
  _depsTail: Link | null;
106
+ /** Recompute-pass counter; bumped when dep revalidation starts. */
107
+ _depGen: number;
65
108
  _flags: number;
66
109
  _blocked?: boolean;
67
- _pendingSource?: Computed<any>;
68
110
  _pendingSources?: Set<Computed<any>>;
69
111
  _error?: unknown;
70
112
  _statusFlags: number;
@@ -75,6 +117,29 @@ export interface Computed<T> extends RawSignal<T>, Owner {
75
117
  _inFlight: PromiseLike<T> | AsyncIterable<T> | null;
76
118
  _child: FirewallSignal<any> | null;
77
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;
78
143
  }
79
144
  export interface Root extends Owner {
80
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.js";
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.js";
2
2
  import { type Dev } from "./core/index.js";
3
3
  export declare const DEV: Dev | undefined;
4
4
  export type { Owner, Context, ContextRecord, IQueue, ExternalSourceFactory, ExternalSource, ExternalSourceConfig, Refreshable, Dev, DevHooks, DiagnosticCapture, DiagnosticCode, DiagnosticEvent, DiagnosticKind, Diagnostics, DiagnosticSeverity } from "./core/index.js";
5
5
  export { createSignal, createMemo, createEffect, createRenderEffect, createTrackedEffect, createReaction, createOptimistic, resolve, onSettled, onCleanup } from "./signals.js";
6
- export type { Accessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.js";
6
+ export type { Accessor, SourceAccessor, Setter, Signal, ComputeFunction, EffectFunction, EffectBundle, EffectOptions, SignalOptions, MemoOptions, NoInfer } from "./signals.js";
7
+ export { affects } from "./affects.js";
7
8
  export { mapArray, repeat, type Maybe } from "./map.js";
8
9
  export * from "./store/index.js";
9
10
  export { createLoadingBoundary, createErrorBoundary, createRevealOrder, flatten, type RevealOrder } from "./boundaries.js";
@@ -2,8 +2,14 @@ import { type Accessor } from "./signals.js";
2
2
  export type Maybe<T> = T | void | null | undefined | false;
3
3
  /**
4
4
  * Reactively maps an array, reusing the previously-mapped value for unchanged
5
- * items. The callback receives `(value, index)` as accessors so individual
6
- * items and indexes can be subscribed to without re-running the mapper.
5
+ * items.
6
+ *
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.
7
13
  *
8
14
  * This is the underlying helper that powers `<For>`. App code should use
9
15
  * `<For>` directly; reach for `mapArray` when implementing custom list
@@ -19,15 +25,25 @@ export type Maybe<T> = T | void | null | undefined | false;
19
25
  * ```ts
20
26
  * const view = mapArray(
21
27
  * items,
22
- * (item, index) => `${index()}: ${item().label}`,
28
+ * (item, index) => `${index()}: ${item.label}`,
23
29
  * { fallback: () => "no items" }
24
30
  * );
25
31
  * ```
26
32
  *
27
33
  * @description https://docs.solidjs.com/reference/reactive-utilities/map-array
28
34
  */
29
- export declare function mapArray<Item, MappedItem>(list: Accessor<Maybe<readonly Item[]>>, map: (value: Accessor<Item>, index: Accessor<number>) => MappedItem, options?: {
30
- 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;
31
47
  fallback?: Accessor<any>;
32
48
  name?: string;
33
49
  }): Accessor<MappedItem[]>;