Skip to content

Commit 4d17c17

Browse files
committed
Merge remote-tracking branch 'origin/next' into claude/project-thread-x1ore2-4355
# Conflicts: # scripts/size/scenarios.js
2 parents 5f2176f + 5f60713 commit 4d17c17

7 files changed

Lines changed: 144 additions & 26 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@solidjs/signals": patch
3+
---
4+
5+
A keyed `createProjection` whose function returned another store's proxy and then a plain array (for example a memo that returns `issues` or `issues.filter(…)`) keeps updating. Switching away from the proxy compared the new array against the proxy itself, which already showed the source store's new rows, so the projection's readers never heard the change and the frame stalled. The switch now tells every leaf and the container, and each node's own equality check decides whether its readers re-run (#4361).

‎packages/signals/docs/INTERNALS-STORE-STATE.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,11 @@ raw object. Mechanics:
443443
channel backing swap; subscribers re-read, re-subscribe to the new backing,
444444
and the old chain drops via dependency rebuild. The displaced backing's
445445
`storeLookup` registration is superseded at swap (proj R10 — proxy keeps
446-
its backing; the *raw→proxy* entry moves).
446+
its backing; the *raw→proxy* entry moves). The swap's diff base is the
447+
live inner proxy, which already reads the inner store's next frame — a
448+
landing in the same flush would diff as unchanged — so a severing writes
449+
every node of the target and its container, each node's equality judging
450+
it against what it was last told (#4361).
447451
- **Snapshot through a chain** unwraps backing pointers to the base raw.
448452
Snapshot identity rule (resolves proj R22 + recon-snap R24/R25 jointly):
449453
**source identity for unowned subtrees; cached copy for owned subtrees**

‎packages/signals/docs/RULES-INDEX.md‎

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,19 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
124124

125125
| id | status | defined | cited in src | cited in tests | statement (at definition) |
126126
|---|---|---|---|---|---|
127-
| RUL-1 | resolved | `docs/INTERNALS-STORE-STATE.md:543` | store.ts×2 | next-smoke.test.ts×1 | - **RUL-1 — RESOLVED (2026-08-16, verified per "mirror signals if verified" — |
128-
| RUL-2 | ruled | `docs/INTERNALS-STORE-STATE.md:552` | — | createOptimisticStore.test.ts×1 | - **RUL-2 — RULED (Ryan, 2026-08-17): no landing matrix. Two orthogonal |
129-
| RUL-3 | resolved | `docs/INTERNALS-STORE-STATE.md:651` | optimistic.ts×1 | — | - **RUL-3 — RESOLVED (verified 2026-08-16).** Ownership already lives |
130-
| RUL-4 | resolved | `docs/INTERNALS-STORE-STATE.md:658` | — | optimistic-signal-refetch-hold.test.ts×1 | - **RUL-4 — RESOLVED (2026-08-17, signal parity — verified empirically).** |
131-
| RUL-5 | live | `docs/INTERNALS-STORE-STATE.md:671` | — | adoption-lane-rollback.test.ts×1 | - **RUL-5 — SPEC'D (2026-08-17): §6b.** Lane backing + lane-view/committed- |
132-
| RUL-6 | live | `docs/INTERNALS-STORE-STATE.md:675` | — | — | - **RUL-6 — reclassified: SPEC WORK, not a ruling.** Live chaining (#2941 — |
133-
| RUL-7 | live | `docs/INTERNALS-STORE-STATE.md:684` | — | — | - **RUL-7 — SPEC'D (2026-08-17): §6c.** One status field on the root target, |
134-
| RUL-8 | live | `docs/INTERNALS-STORE-STATE.md:687` | — | adoption-lane-rollback.test.ts×1 | - **RUL-8 — SPEC'D (2026-08-17): §6 rewrite, resolves O2.** Per-transaction |
135-
| RUL-9 | resolved | `docs/INTERNALS-STORE-STATE.md:690` | — | — | - **RUL-9 — RESOLVED (2026-08-17, parity by construction).** Every piece of |
136-
| RUL-10 | live | `docs/INTERNALS-STORE-STATE.md:695` | — | — | - **RUL-10 — The equality trio.** One precise rule needed spanning: no-op |
137-
| RUL-11 | live | `docs/INTERNALS-STORE-STATE.md:701` | — | — | - **RUL-11 — SPEC'D (2026-08-17): §6d.** Sticky descendants flag ported from |
138-
| RUL-12 | live | `docs/INTERNALS-STORE-STATE.md:703` | store.ts×1 types.ts×1 | createProjection.async.test.ts×1 shared-child-multiparent.test.ts×1 | - **RUL-12 — Smaller rulings, each with a proposed default** (proceeding on |
139-
| RUL-13 | resolved | `docs/INTERNALS-STORE-STATE.md:749` | — | — | - **RUL-13 — RESOLVED (verified 2026-08-16)**: `optimistic-lane-transaction- |
127+
| RUL-1 | resolved | `docs/INTERNALS-STORE-STATE.md:547` | store.ts×2 | next-smoke.test.ts×1 | - **RUL-1 — RESOLVED (2026-08-16, verified per "mirror signals if verified" — |
128+
| RUL-2 | ruled | `docs/INTERNALS-STORE-STATE.md:556` | — | createOptimisticStore.test.ts×1 | - **RUL-2 — RULED (Ryan, 2026-08-17): no landing matrix. Two orthogonal |
129+
| RUL-3 | resolved | `docs/INTERNALS-STORE-STATE.md:655` | optimistic.ts×1 | — | - **RUL-3 — RESOLVED (verified 2026-08-16).** Ownership already lives |
130+
| RUL-4 | resolved | `docs/INTERNALS-STORE-STATE.md:662` | — | optimistic-signal-refetch-hold.test.ts×1 | - **RUL-4 — RESOLVED (2026-08-17, signal parity — verified empirically).** |
131+
| RUL-5 | live | `docs/INTERNALS-STORE-STATE.md:675` | — | adoption-lane-rollback.test.ts×1 | - **RUL-5 — SPEC'D (2026-08-17): §6b.** Lane backing + lane-view/committed- |
132+
| RUL-6 | live | `docs/INTERNALS-STORE-STATE.md:679` | — | — | - **RUL-6 — reclassified: SPEC WORK, not a ruling.** Live chaining (#2941 — |
133+
| RUL-7 | live | `docs/INTERNALS-STORE-STATE.md:688` | — | — | - **RUL-7 — SPEC'D (2026-08-17): §6c.** One status field on the root target, |
134+
| RUL-8 | live | `docs/INTERNALS-STORE-STATE.md:691` | — | adoption-lane-rollback.test.ts×1 | - **RUL-8 — SPEC'D (2026-08-17): §6 rewrite, resolves O2.** Per-transaction |
135+
| RUL-9 | resolved | `docs/INTERNALS-STORE-STATE.md:694` | — | — | - **RUL-9 — RESOLVED (2026-08-17, parity by construction).** Every piece of |
136+
| RUL-10 | live | `docs/INTERNALS-STORE-STATE.md:699` | — | — | - **RUL-10 — The equality trio.** One precise rule needed spanning: no-op |
137+
| RUL-11 | live | `docs/INTERNALS-STORE-STATE.md:705` | — | — | - **RUL-11 — SPEC'D (2026-08-17): §6d.** Sticky descendants flag ported from |
138+
| RUL-12 | live | `docs/INTERNALS-STORE-STATE.md:707` | store.ts×1 types.ts×1 | createProjection.async.test.ts×1 shared-child-multiparent.test.ts×1 | - **RUL-12 — Smaller rulings, each with a proposed default** (proceeding on |
139+
| RUL-13 | resolved | `docs/INTERNALS-STORE-STATE.md:753` | — | — | - **RUL-13 — RESOLVED (verified 2026-08-16)**: `optimistic-lane-transaction- |
140140
## R — core-store (`CS-R<n>`)
141141

142142
| id | status | defined | cited in src | cited in tests | statement (at definition) |
@@ -390,10 +390,10 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
390390
| §6c | live | `docs/INTERNALS-STORE-STATE.md:356` | — | createProjection.async.test.ts×1 flight-owned-transaction.test.ts×1 | Store-wide status gating (RUL-7) |
391391
| §6d | live | `docs/INTERNALS-STORE-STATE.md:369` | reconcile.ts×2 target.ts×2 | — | Diff reachability (RUL-11) |
392392
| §7 | live | `docs/INTERNALS-STORE-STATE.md:381` | optimistic.ts×1 projection.ts×1 | — | Projections & optimism layering |
393-
| §7b | live | `docs/INTERNALS-STORE-STATE.md:391` | scheduler.ts×1 affects.ts×1 optimistic.ts×2 projection.ts×1 reconcile.ts×1 store.ts×8 target.ts×4 | optimistic-chained-revert-3672-memo.test.ts×1 optimistic-removed-prop-3883.test.ts×1 | Chained backing (cross-store) — spec |
394-
| §8 | live | `docs/INTERNALS-STORE-STATE.md:462` | — | l2-contract.test.ts×1 reconcile-resend-identity.test.ts×1 | Assumptions / open questions |
395-
| §8b | live | `docs/INTERNALS-STORE-STATE.md:518` | — | — | Suite-mined rules (2026-08-16) — index & rulings needed |
396-
| §9 | live | `docs/INTERNALS-STORE-STATE.md:754` | — | — | Decision log |
393+
| §7b | live | `docs/INTERNALS-STORE-STATE.md:391` | scheduler.ts×1 affects.ts×1 optimistic.ts×2 projection.ts×1 reconcile.ts×2 store.ts×9 target.ts×4 | projection-proxy-then-array-4361.test.ts×1 optimistic-chained-revert-3672-memo.test.ts×1 optimistic-removed-prop-3883.test.ts×1 | Chained backing (cross-store) — spec |
394+
| §8 | live | `docs/INTERNALS-STORE-STATE.md:466` | — | l2-contract.test.ts×1 reconcile-resend-identity.test.ts×1 | Assumptions / open questions |
395+
| §8b | live | `docs/INTERNALS-STORE-STATE.md:522` | — | — | Suite-mined rules (2026-08-16) — index & rulings needed |
396+
| §9 | live | `docs/INTERNALS-STORE-STATE.md:758` | — | — | Decision log |
397397
| §11 | live | `docs/NODE-SHAPE.md:29` | — | — | Stage 3 opener: the core tax map (2026-08-21) |
398398
| §11b | live | `docs/NODE-SHAPE.md:53` | constants.ts×1 | rules-index.test.ts×1 treeshake.test.ts×1 | Presence bits — hot-path monomorphism |
399399
| §11c | live | `docs/NODE-SHAPE.md:72` | — | — | Stage-3 increment log |

‎packages/signals/src/store/reconcile.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ function applyAdopt(t: StoreTarget, incoming: any, keyFn: KeyFn | null, proj = f
107107
if (shallow) markRawIngest(incoming);
108108
// The deep witness is bumped once per adoption (none to bump: done).
109109
let bumped = t.dk === null;
110-
if (Array.isArray(prevView) !== nextArr) {
110+
// A live chained base (a store proxy, §7b) reads the inner store's
111+
// current frame, not what the nodes were last told — nothing to diff
112+
// against: the fold writes every node (#4361).
113+
if (Array.isArray(prevView) !== nextArr || old[$TARGET]) {
111114
notifyFold(t, old, incoming);
112115
return;
113116
}

‎packages/signals/src/store/store.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,10 @@ export function notifyKeyDiff(
13571357
} else {
13581358
const ov = old[key as any];
13591359
const nv = neu[key as any];
1360-
if (!isEqual(ov, nv) && !targetsEqual(ov, nv))
1360+
// A live chained `old` (a store proxy, §7b) already reads the inner
1361+
// store's next frame, not what the node was last told: written, the
1362+
// node's own equality judging it (#4361).
1363+
if (old[$TARGET] || (!isEqual(ov, nv) && !targetsEqual(ov, nv)))
13611364
setSignal(node, typeof nv === "function" ? () => nv : (nv as any));
13621365
}
13631366
}
@@ -1393,7 +1396,8 @@ export function notifyKeyValue(
13931396
* unrelated `a.value` stayed stale until the action settled). A real
13941397
* change still writes, and on a held node still proposes. A live chained
13951398
* `old` (a store proxy, §7b) reflects the inner store, not what the node
1396-
* was last told — written unconditionally, as before.
1399+
* was last told — written unconditionally, as before; its container too
1400+
* (#4361).
13971401
*
13981402
* The container is told of an arrangement change when it has structural
13991403
* subscribers OR carries an arrangement guess (S4): for a guessed
@@ -1409,17 +1413,18 @@ export function notifyFoldTail(
14091413
neu: Record<PropertyKey, any>
14101414
): void {
14111415
const has = t.h;
1416+
const live: StoreTarget | undefined = (old as any)[$TARGET];
14121417
if (has !== null) {
1413-
const live: StoreTarget | undefined = (old as any)[$TARGET];
14141418
for (const key of Reflect.ownKeys(has))
14151419
if (live || key in old !== key in neu) setSignal(has[key as any], key in neu);
14161420
}
14171421
const k = t.k;
14181422
if (k !== null && (k._subs !== null || k._config & CONFIG_OVERRIDE)) {
14191423
const changed =
1420-
Array.isArray(neu) && Array.isArray(old)
1424+
live ||
1425+
(Array.isArray(neu) && Array.isArray(old)
14211426
? arrayStructureChanged(old as any[], neu as any[])
1422-
: membershipChanged(old, neu);
1427+
: membershipChanged(old, neu));
14231428
if (changed) notifyContainer(k, neu);
14241429
}
14251430
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/**
2+
* #4361: a keyed `createProjection(() => memo(), [], { key })` whose fn
3+
* returns an async store's proxy, then a plain array, then the proxy again
4+
* must keep updating — the frames reach `#1(-) #3(ann)`. The root was
5+
* chained to the proxy (§7b), so the diff base of the switch back read the
6+
* inner store's next frame, not what the projection's nodes were last told:
7+
* no leaf (nor the container) heard the change, and the held frame waited
8+
* on a reader that never re-ran.
9+
*/
10+
import { describe, expect, it } from "vitest";
11+
import {
12+
createMemo,
13+
createOptimisticStore,
14+
createProjection,
15+
createRenderEffect,
16+
createRoot,
17+
createSignal,
18+
createStore,
19+
flush
20+
} from "../src/index.js";
21+
22+
const tick = async () => {
23+
for (let i = 0; i < 4; i++) {
24+
await new Promise(r => setTimeout(r, 0));
25+
flush();
26+
}
27+
};
28+
29+
const readers = {
30+
// Leaves: `length` and each index.
31+
leaves: (p: any) => p.map((i: any) => `#${i.id}(${i.a})`).join(" "),
32+
// Structure: the container node.
33+
keys: (p: any) => Object.keys(p).join(",")
34+
};
35+
const expected = {
36+
leaves: ["#1(-) #3(-)", "#2(eve)", "#1(-) #3(ann)"],
37+
keys: ["0,1", "0", "0,1"]
38+
};
39+
40+
describe("#4361 projection returning a store proxy, then an array, then the proxy", () => {
41+
for (const reader of ["leaves", "keys"] as const)
42+
for (const kind of ["optimisticStore", "store"] as const)
43+
for (const memo of [true, false])
44+
it(`${reader} ${kind} memo=${memo}`, async () => {
45+
const asks: { key: string; res: (v: any) => void }[] = [];
46+
const ask = (key: string) => new Promise<any>(res => asks.push({ key, res }));
47+
const land = async (key: string, v: any) => {
48+
const i = asks.findIndex(a => a.key === key);
49+
asks.splice(i, 1)[0].res(v);
50+
await tick();
51+
};
52+
const frames: string[] = [];
53+
let setFilter!: (f: string) => void;
54+
createRoot(() => {
55+
const [filter, sf] = createSignal("open");
56+
setFilter = sf;
57+
const make: any = kind === "store" ? createStore : createOptimisticStore;
58+
const [issues] = make(
59+
async (d: any[]) => {
60+
const r = await ask(`f:${filter()}`);
61+
d.length = 0;
62+
d.push(...r.map((x: any) => ({ ...x })));
63+
},
64+
[],
65+
{ key: "id" }
66+
);
67+
const src = memo
68+
? createMemo(() =>
69+
filter() === "open" ? (issues as any[]).filter(() => true) : issues
70+
)
71+
: () => issues;
72+
const p = createProjection(() => src() as any, [] as any, { key: "id" } as any);
73+
createRenderEffect(
74+
() => readers[reader](p),
75+
v => {
76+
if (frames.at(-1) !== v) frames.push(v);
77+
}
78+
);
79+
});
80+
await land("f:open", [
81+
{ id: 1, a: "-" },
82+
{ id: 3, a: "-" }
83+
]);
84+
setFilter("closed");
85+
flush();
86+
await tick();
87+
await land("f:closed", [{ id: 2, a: "eve" }]);
88+
setFilter("open");
89+
flush();
90+
await tick();
91+
await land("f:open", [
92+
{ id: 1, a: "-" },
93+
{ id: 3, a: "ann" }
94+
]);
95+
expect(frames).toEqual(expected[reader]);
96+
});
97+
});

0 commit comments

Comments
 (0)