@solidjs/signals 2.0.0-rc.3 → 2.0.0-rc.4

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 (48) hide show
  1. package/dist/dev.js +1334 -94
  2. package/dist/node.cjs +2589 -1367
  3. package/dist/prod/affects.js +13 -12
  4. package/dist/prod/boundaries.js +39 -34
  5. package/dist/prod/core/action.js +3 -3
  6. package/dist/prod/core/async.js +48 -46
  7. package/dist/prod/core/core.js +99 -67
  8. package/dist/prod/core/effect.js +25 -28
  9. package/dist/prod/core/external.js +2 -2
  10. package/dist/prod/core/graph.js +85 -49
  11. package/dist/prod/core/heap.js +10 -10
  12. package/dist/prod/core/lanes.js +19 -19
  13. package/dist/prod/core/optimistic.js +36 -33
  14. package/dist/prod/core/owner.js +13 -13
  15. package/dist/prod/core/scheduler.js +131 -85
  16. package/dist/prod/core/verdict.js +29 -15
  17. package/dist/prod/index.js +4 -0
  18. package/dist/prod/map.js +101 -101
  19. package/dist/prod/signals.js +1 -1
  20. package/dist/prod/store/index.js +2 -0
  21. package/dist/prod/store/next/optimistic.js +65 -11
  22. package/dist/prod/store/next/patch-hooks.js +13 -0
  23. package/dist/prod/store/next/patch.js +614 -0
  24. package/dist/prod/store/next/reconcile.js +307 -120
  25. package/dist/prod/store/next/store.js +321 -92
  26. package/dist/prod/store/next/target.js +13 -4
  27. package/dist/prod/store/store.js +5 -5
  28. package/dist/types/core/core.d.ts +15 -1
  29. package/dist/types/core/dev.d.ts +8 -0
  30. package/dist/types/core/graph.d.ts +22 -0
  31. package/dist/types/core/scheduler.d.ts +12 -0
  32. package/dist/types/store/index.d.ts +2 -0
  33. package/dist/types/store/next/patch-hooks.d.ts +41 -0
  34. package/dist/types/store/next/patch.d.ts +91 -0
  35. package/dist/types/store/next/reconcile.d.ts +14 -0
  36. package/dist/types/store/next/store.d.ts +30 -2
  37. package/dist/types/store/next/target.d.ts +58 -8
  38. package/dist/types-cjs/core/core.d.cts +15 -1
  39. package/dist/types-cjs/core/dev.d.cts +8 -0
  40. package/dist/types-cjs/core/graph.d.cts +22 -0
  41. package/dist/types-cjs/core/scheduler.d.cts +12 -0
  42. package/dist/types-cjs/store/index.d.cts +2 -0
  43. package/dist/types-cjs/store/next/patch-hooks.d.cts +41 -0
  44. package/dist/types-cjs/store/next/patch.d.cts +91 -0
  45. package/dist/types-cjs/store/next/reconcile.d.cts +14 -0
  46. package/dist/types-cjs/store/next/store.d.cts +30 -2
  47. package/dist/types-cjs/store/next/target.d.cts +58 -8
  48. package/package.json +2 -2
@@ -0,0 +1,91 @@
1
+ import type { Owner } from "../../core/types.cjs";
2
+ import { type StoreNextTarget } from "./target.cjs";
3
+ export type PatchFn = (next: any, prev: any, force?: boolean) => void;
4
+ interface PatchEntry {
5
+ fn: PatchFn;
6
+ owner: Owner | null;
7
+ }
8
+ /**
9
+ * Emit a record's visibility transition. Callers gate on `hasPatches()` and
10
+ * `t.d` cheaply; this function re-checks and walks ancestors (§4b).
11
+ */
12
+ export declare function emitPatch(t: StoreNextTarget, next: any, prev: any): void;
13
+ /** Emission for sites that already stand at the record with both sides in
14
+ * hand and have already handled ancestors (the adoption walk descends —
15
+ * parents were visited first), so no bubbling walk. */
16
+ export declare function emitPatchLocal(t: StoreNextTarget, next: any, prev: any): void;
17
+ export declare function emitPatchOptimistic(t: StoreNextTarget, next: any, prev: any): void;
18
+ /** Row-ops emission at OPTIMISTIC (lane) timing: user drafts on an
19
+ * optimistic family must show structure IN FLIGHT — bypassing the
20
+ * transition stash exactly like emitPatchOptimistic. Two forms:
21
+ * - `ops` given (write site): `nextRows` is the draft's intended visible
22
+ * list, ops the identity diff against the pre-write optimistic view.
23
+ * - `ops === null` (revert site): RESYNC — the consumer rebuilds retention
24
+ * by row identity against the live post-revert view, resolved from the
25
+ * target at drain time (overrides are gone by then, so `pb ?? v` IS the
26
+ * committed truth). */
27
+ export declare function emitRowOpsOptimistic(t: StoreNextTarget, nextRows: any[] | null, ops: RowOps | null): void;
28
+ /** Test-only accounting probe: the live registration count must return to
29
+ * baseline across register/unbind/demote cycles. @internal */
30
+ export declare function patchCountForTests(): number;
31
+ export declare function hasPatches(): boolean;
32
+ export declare function registerPatch(record: any, fn: PatchFn): () => void;
33
+ /** Dual-driver bind probe (compiler runtime contract): when `record` is a
34
+ * patchable store record, returns its CURRENT raw backing (the driver's
35
+ * initial force-apply reads it directly — no proxy traffic, no tracking);
36
+ * returns undefined otherwise (driver falls back to the effect path).
37
+ * Not patchable: non-records, non-proxies, accessor-bearing records
38
+ * (patches read raw — getters need tracked evaluation), broken chains. */
39
+ export declare function patchableRaw(record: any): Record<PropertyKey, any> | undefined;
40
+ /** Accessor demotion (design §5): a record that acquires an accessor after
41
+ * registration stops being patchable — reads must go through tracked
42
+ * evaluation. Clears patches and repairs the global count; callers re-drive
43
+ * the pulled bodies (demoteToEffects). */
44
+ export declare function demotePatches(t: StoreNextTarget): PatchEntry[] | null;
45
+ /** The demotion re-drive (re-audit blocker 3): each pulled body becomes the
46
+ * SAME dual-driver effect fallback the web runtime would have chosen had the
47
+ * record carried the accessor at bind — a tracked compute pass (next === prev
48
+ * short-circuits every compare into a pure read THROUGH THE PROXY, so getter
49
+ * dependencies track) plus an untracked force-apply at effect timing.
50
+ *
51
+ * Creation is DEFERRED to the effect phase: the trap that discovers the
52
+ * accessor runs mid-draft, and an effect's initial pass must not read
53
+ * through the proxy inside the write window. The record's own transition
54
+ * for that draft is covered by the new effect's initial force-apply.
55
+ *
56
+ * Known edge (documented): a demoted LIST-ROW body re-drives under its
57
+ * registering owner (the list owner), so per-row severing on removal is
58
+ * lost for demoted rows — the effect lives until the LIST disposes. Rows
59
+ * only demote when user code defines an accessor on a row record at
60
+ * runtime. */
61
+ export declare function demoteToEffects(t: StoreNextTarget): void;
62
+ /** Structural ops for one keyed-array transition. `prefix` rows key-matched
63
+ * in place; for each later index i (absolute), `sources[i - prefix]` is the
64
+ * OLD index its row retained from, or -1 for a new row. `removed` holds the
65
+ * dropped old row values (unbind/teardown handles). Aligned value ticks emit
66
+ * NOTHING — ops exist only when structure changed. */
67
+ export interface RowOps {
68
+ prefix: number;
69
+ sources: number[];
70
+ removed: any[];
71
+ }
72
+ /** `ops === null` is the RESYNC form (optimistic revert): the consumer
73
+ * rebuilds retention by row identity against `next` (the live view). */
74
+ export type RowOpsFn = (next: any[], ops: RowOps | null) => void;
75
+ /** Register a structural-ops consumer on a keyed store array (the list
76
+ * container's channel — what `For` consumes through the seam). */
77
+ export declare function registerRowOps(array: any, fn: RowOpsFn): () => void;
78
+ /** Slot patches (shallow arrays) ride the same apply queue: the walk emits
79
+ * per aligned value-replaced slot; application happens at effect phase under
80
+ * the registration owner's lifetime. */
81
+ export declare function emitSlotPatch(t: StoreNextTarget, index: number, next: any, prev: any): void;
82
+ /** Slot patch for shallow arrays: the reconcile walk emits (index, next,
83
+ * prev) for KEY-ALIGNED value-replaced slots (structure rides row ops), and
84
+ * the emission queues through the patch apply queue — effect-phase timing,
85
+ * transition stamping, disposed-owner drop — like every other channel. */
86
+ export declare function registerSlotPatchNext(arr: any, fn: (index: number, next: any, prev: any) => void): () => void;
87
+ /** Row-ops ride the SAME apply queue/timing as record patches: transition-
88
+ * stamped, applied at effect phase, in emission order (structure before the
89
+ * new rows' own patches can exist; retained rows' value patches commute). */
90
+ export declare function emitRowOps(t: StoreNextTarget, next: any[], ops: RowOps): void;
91
+ export {};
@@ -1,3 +1,17 @@
1
+ import type { RowOps } from "./patch.cjs";
2
+ import { type StoreNextTarget } from "./target.cjs";
1
3
  type KeyFn = (item: any) => any;
2
4
  export declare function reconcileNextState(value: any, state: any, key: string | KeyFn | null | undefined, replace?: boolean): void;
5
+ /** Key equality for EVERY key comparison in this module (re-audit 2, P1-5):
6
+ * SameValueZero, matching the Map-based matchers (buildRowOps, the adoption
7
+ * window) — NaN keys are equal to themselves, so aligned NaN rows stay
8
+ * aligned in the prefix walk instead of forever misaligning. Adoption and
9
+ * row ops MUST agree on key equality or retained DOM rows go stale. */
10
+ export declare function sameKey(a: any, b: any): boolean;
11
+ export declare function emitSetterRowOps(t: StoreNextTarget, prevRows: any[], nextRows: any[]): void;
12
+ /** Identity-keyed structural diff, returned rather than emitted: shared by
13
+ * the setter channel (regular queue) and the OPTIMISTIC write channel (lane
14
+ * queue) — same retention semantics, different dispatch timing. Returns
15
+ * null when the lists are identity-aligned (no structure changed). */
16
+ export declare function buildIdentityRowOps(prevRows: any[], nextRows: any[]): RowOps | null;
3
17
  export {};
@@ -1,5 +1,7 @@
1
1
  import type { Signal } from "../../core/types.cjs";
2
- import { type StoreNextFamily, type StoreNextTarget } from "./target.cjs";
2
+ import { type StoreNextFamily, type StoreNextTarget, type PatchChannel } from "./target.cjs";
3
+ /** Lazily allocate the patch-channel extension (one literal shape). */
4
+ export declare function pcOf(t: StoreNextTarget): PatchChannel;
3
5
  export declare function wrapNext<T extends Record<PropertyKey, any>>(value: T, parent?: StoreNextTarget | null, parentKey?: PropertyKey | null, fam?: StoreNextFamily | null): T;
4
6
  /** Unwrap our own proxies to their current backing; leave everything else. */
5
7
  export declare function unwrapValue(v: any): any;
@@ -9,6 +11,10 @@ export declare function getKeySetNode(target: StoreNextTarget): Signal<number>;
9
11
  /** Deep-witness bump: any value/shape change on a record with a live deep()
10
12
  * subscriber notifies it. One null check when unused. */
11
13
  export declare function bumpDeep(t: StoreNextTarget): void;
14
+ /** Scanned plainness for patch admission (patchableRaw): runs the one-time
15
+ * accessor scan if it hasn't happened yet — the sticky `a` flag alone is not
16
+ * trustworthy before a scan (it starts false and is discovered lazily). */
17
+ export declare function targetIsPlain(target: StoreNextTarget): boolean;
12
18
  /** Downgrade a prototype-overlay pending backing to the clone path: builds
13
19
  * the real container (committed + overlay writes − deletes) that fold will
14
20
  * SWAP in as the committed backing, exactly as if the draft had started on
@@ -63,8 +69,30 @@ export type SetStoreNextFunction<T> = (fn: (draft: T) => T | void) => void;
63
69
  * projection recomputes legitimately write from inside their computed. */
64
70
  export declare function storeSetterNext<T>(proxy: T, fn: (draft: T) => T | void, guard?: boolean): void;
65
71
  export declare function createStoreNext<T extends Record<PropertyKey, any>>(init: T, shallow?: boolean): [T, SetStoreNextFunction<T>];
72
+ /** True when `proxy` is a SHALLOW store (children served verbatim, slots
73
+ * replaced by reference — #2932). The list driver uses this to choose the
74
+ * slot-patch channel (collected row bodies) over per-record registration. */
75
+ export declare function storeIsShallow(proxy: any): boolean;
76
+ /** True when `proxy` belongs to a projection/optimistic FAMILY. The list
77
+ * driver must DECLINE family arrays (external audit finding): family
78
+ * structural changes never emit row/slot ops (the setter channel is
79
+ * fam-gated; optimistic writes ride node overrides), and the proxy identity
80
+ * is stable so the each-watch cannot catch the change either — an engaged
81
+ * list would freeze on optimistic/projection structural updates. Record-
82
+ * level family patches are unaffected (they have their own emission). */
83
+ export declare function storeHasFamily(proxy: any): boolean;
84
+ /** True when `proxy` belongs to an OPTIMISTIC family specifically. The list
85
+ * driver declines these (audit finding, narrowed): optimistic user writes
86
+ * ride node-level overrides — they never enter the reconcile walk, so no
87
+ * row/slot ops are emitted and an engaged list would freeze on optimistic
88
+ * structural changes. PROJECTION (non-optimistic) families are drivable:
89
+ * their recomputes go through the reconcile walk, whose emissions are
90
+ * transition-stamped in the apply queue like any other (equivalence-matrix
91
+ * gated). Re-admitting optimistic families requires a lane-timed structural
92
+ * emission mirroring emitPatchOptimistic, plus revert resync. */
93
+ export declare function storeHasOptimisticFamily(proxy: any): boolean;
66
94
  /** Tracking deep snapshot (`deep()` for next targets): subscribes to the
67
- * key-set and every property node at every reachable level, then returns the
95
+ * key-set and deep-witness node at every reachable level, then returns the
68
96
  * plain view. Shared references and cycles handled via the visited set. */
69
97
  export declare function deepNext<T>(value: T): T;
70
98
  /**
@@ -12,7 +12,7 @@
12
12
  * entry per read-through object; zero layer slots; nodes, has-nodes, and the
13
13
  * key-set node are lazy, materialized only by subscription.
14
14
  */
15
- import type { Computed, Signal } from "../../core/types.cjs";
15
+ import type { Computed, Owner, Signal } from "../../core/types.cjs";
16
16
  /** Projection family (§7b): children wrap into the family's own map (writes
17
17
  * land in the projection, never the source family), and every node created
18
18
  * under the family carries the projection computed as its firewall. */
@@ -32,6 +32,40 @@ export interface StoreNextFamily {
32
32
  node: Computed<any> | null;
33
33
  shallow?: boolean;
34
34
  }
35
+ /** Write-side patch-channel state (stage 2), grouped off the target's named
36
+ * fields — see the shape rule on `StoreNextTarget.pc`. One literal shape,
37
+ * allocated by `pcOf` on first use. */
38
+ export interface PatchChannel {
39
+ /** Slot-patch hooks for shallow arrays — the reconcile walk emits
40
+ * (i, next, prev) for key-aligned value-replaced slots through the patch
41
+ * apply queue (records are raw, no per-record targets exist).
42
+ * MULTI-CONSUMER (external audit): one array can drive several lists. */
43
+ sp: {
44
+ fn: (index: number, next: any, prev: any) => void;
45
+ owner: Owner | null;
46
+ }[] | null;
47
+ /** Patch-channel consumers (next/patch.ts): per-record compiled patch
48
+ * entries, multi-consumer. null when unpatched (the common case). */
49
+ p: object[] | null;
50
+ /** Same-batch coalescing stamp (re-audit 2/3): the container array this
51
+ * channel last pushed a non-forced SELF entry into, plus that entry. A
52
+ * later same-batch emission UPDATES the queued entry's `next` in place
53
+ * (latest state wins — adoption REPLACES the captured object, so dropping
54
+ * the later emission would apply stale state) while `prev` stays the
55
+ * batch's earliest. The drain clears both stamps so a quiet record
56
+ * retains nothing from its last batch. */
57
+ qa: unknown;
58
+ qe: unknown;
59
+ /** Row-ops consumers (next/patch.ts, PR-B): structural list ops —
60
+ * (nextRows, { prefix, sources, removed }) at apply timing. */
61
+ ro: object[] | null;
62
+ /** Keys written through the traps since the last fold commit. Bounds the
63
+ * setter notify/hold-check to O(written) instead of O(subscribed nodes) —
64
+ * a record with thousands of per-key subscriptions (selection maps) would
65
+ * otherwise pay a full node scan on every write. null = no trap writes
66
+ * this batch (bulk paths fall back to the full scan). */
67
+ wk: Set<PropertyKey> | null;
68
+ }
35
69
  export interface StoreNextTarget {
36
70
  /** Committed backing: source object (shared) or owned clone. */
37
71
  v: Record<PropertyKey, any>;
@@ -47,6 +81,15 @@ export interface StoreNextTarget {
47
81
  h: Record<PropertyKey, Signal<boolean>> | null;
48
82
  /** Lazy key-set node: membership/iteration/$TRACK subscriptions (§6). */
49
83
  k: Signal<number> | null;
84
+ /** Patch-channel extension (lazily allocated on first use): groups the
85
+ * write-side stage-2 fields so they never widen the TARGET's own named
86
+ * field count. LOAD-BEARING SHAPE RULE: array proxy targets carry their
87
+ * fields as named properties on a real array, and V8 normalizes an array
88
+ * to dictionary properties as the named count grows (empirically at
89
+ * counts ≡ 0 mod 3 from 18 up on V8 13.x) — every trap field read then
90
+ * becomes a hash lookup (~15% uibench, tree suites worst). New
91
+ * patch-channel state MUST go inside this object, not on the target. */
92
+ pc: PatchChannel | null;
50
93
  /** Lazy deep-witness node: `deep()` subscribes ONE node per record instead
51
94
  * of one per path; write paths bump it only when it exists. Separate from
52
95
  * `k` so $TRACK/mapArray never rerun on leaf value changes (R9). */
@@ -79,17 +122,21 @@ export interface StoreNextTarget {
79
122
  /** Keys deleted in the overlay window (a prototype overlay cannot shadow
80
123
  * a delete); null when none. */
81
124
  del: Set<PropertyKey> | null;
82
- /** Keys written through the traps since the last fold commit. Bounds the
83
- * setter notify/hold-check to O(written) instead of O(subscribed nodes) —
84
- * a record with thousands of per-key subscriptions (selection maps) would
85
- * otherwise pay a full node scan on every write. null = no trap writes
86
- * this batch (bulk paths fall back to the full scan); WK_ALL sentinel =
87
- * bound unusable this batch (array length write implies index deletes). */
88
- wk: Set<PropertyKey> | null;
89
125
  /** Projection family, null for plain stores (§7b). */
90
126
  fam: StoreNextFamily | null;
91
127
  /** Shallow store root (values served raw). */
92
128
  s: boolean;
129
+ /** Held committed view (#3074/#3075): the pre-hold committed backing,
130
+ * served to committed-visibility readers while `ht` is live. Adoption is
131
+ * eager by contract, but a projection recompute deriving from uncommitted
132
+ * inputs (a transition-held source, or a latest()-pull ahead of the flush)
133
+ * swaps the backing SPECULATIVELY — the old view must stay servable until
134
+ * the hold resolves. */
135
+ hv: Record<PropertyKey, any> | null;
136
+ /** The holder for `hv`: a live transition (cleared lazily when it is done)
137
+ * or the PLAIN_HOLD sentinel (a latest()-pull staging — cleared by the
138
+ * fold commit). null = no hold. */
139
+ ht: any;
93
140
  }
94
141
  /**
95
142
  * Ownership (first cut, decision 2026-08-16d): one WeakSet of store-owned
@@ -115,3 +162,6 @@ export interface OptStoreHooks {
115
162
  }
116
163
  export declare let optHooks: OptStoreHooks | null;
117
164
  export declare function setOptHooks(h: OptStoreHooks): void;
165
+ /** Sticky descendants flag walk (§6d): reconcile's keyed pruning descends
166
+ * only where subscriptions exist at/below. Nodes AND patches count. */
167
+ export declare function markDescendants(target: StoreNextTarget): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "2.0.0-rc.3",
3
+ "version": "2.0.0-rc.4",
4
4
  "description": "Solid's reactive primitives: signals, memos, effects, stores, and async-aware computations.",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
@@ -66,4 +66,4 @@
66
66
  "vite": "^7.0.0",
67
67
  "vitest": "^4.1.6"
68
68
  }
69
- }
69
+ }