Skip to content

Commit 17ec571

Browse files
ryansolidclaude
andauthored
fix(signals): a derived store over latest() never serves its seed after it first resolves (#4355) (#4369)
A derived store whose derive reads an async memo through `latest()` resolved, but a memo reading it saw the seed for one pass: a render effect behind that memo committed `undefined`, then the value. A render effect reading the store directly saw only the value. Cause: the derive reads `latest()`, so it is a verdict reader, and a memo that reads it through the store's status pull becomes one too (F-6, #4050). In the landing flush the derive's first write is a staging and the derive is still uninitialized. Core serves a verdict reader the screen for a staged signal (A10, `stagedScreen`), and a store leaf's screen is the committed backing, which is the seed. The seed is never observable (A25, D-30). A memo born staged has the same guard in core `serve`, but store leaves take the signal fast path, which has no status to check. Fix: the store's `nodeValue` serves the leaf's unheld staging while the family's derive has never committed (STATUS_UNINITIALIZED), as it already does for a handler read. Store engine only: +19 B minified on the four store scenarios, every floor unchanged. Tests: packages/signals/tests/derived-store-latest-seed-4355.test.ts (memo, second derived store and direct readers, latest and plain derives) and packages/web/test/derived-store-latest-seed-4355.spec.tsx (a hole through a memo and a direct hole). Size ledger lines added; RULES-INDEX regenerated. Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 Co-authored-by: Claude <[email protected]>
1 parent 5f60713 commit 17ec571

6 files changed

Lines changed: 141 additions & 6 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@solidjs/signals": patch
3+
"solid-js": patch
4+
---
5+
6+
A derived store whose derive reads an async memo through `latest()` no longer shows its seed for one pass after it first resolves: a memo (or a second derived store) reading it now sees what the derive wrote, so a render effect downstream commits only the real value, the same as one reading the store directly (#4355).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ Status legend: **live** stated and standing · **ruled** carries an explicit rul
6969
| A22 | amended | `docs/SPEC-ASYNC-SEMANTICS.md:229` | store.ts×1 | createProjection.draft-lifetime-3585.test.ts×1 spec-async-semantics.test.ts×1 visibility-oracle-store.states.ts×1 | [ruled, amended in place 2026-07-08] Pending is per-node; store-wide only for the firewall's own work — **Pending is per-node: store-wide verdicts exist only as the firewall's own in-flight work (A9) … |
7070
| A23 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:239` | — | spec-async-semantics.test.ts×1 | [ruled 2026-07-08] The `isPending` probe is reads-only — **The `isPending` probe is reads-only — the thunk's return value is never inspected.** `isPending(() => store)` reads nothing and reports `fals… |
7171
| A24 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:157` | affects-marks.ts×1 affects.ts×1 constants.ts×1 lanes.ts×2 types.ts×1 verdict.ts×3 affects.ts×1 optimistic.ts×1 | body-end-supersession-visibility.test.ts×1 create-deferred-3710.test.ts×2 optimistic-undefined-override.test.ts×1 reveal-gating-contract.test.ts×1 spec-async-semantics.test.ts×3 kanban-a17-fixture.test.ts×1 signal-store-twins-qd.test.ts×1 visibility-oracle-store.states.ts×4 visibility-oracle.states.ts×5 visibility-oracle.test.ts×1 | [ruled 2026-07-13] Question-scoped pending: pending iff a value change is in flight or an `affects()` mark is live — (**ruled 2026-07-13** — supersedes A20/A21; the converged model from the #2844/#272… |
72-
| A25 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:309` | projection.ts×2 | derived-presence-async-3726.test.ts×2 seedless-derived-store.test.ts×1 uninitialized-visibility.test.ts×3 visibility-oracle-store.states.ts×7 visibility-oracle-store.test.ts×1 | [ruled 2026-07-16] A derived store's seed is a draft, never an observable value — (**ruled 2026-07-16**, #2897) **A derived store's seed is a draft, never an observable value.** The seed exists for th… |
72+
| A25 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:309` | projection.ts×2 store.ts×1 | derived-presence-async-3726.test.ts×2 seedless-derived-store.test.ts×1 uninitialized-visibility.test.ts×3 visibility-oracle-store.states.ts×7 visibility-oracle-store.test.ts×1 | [ruled 2026-07-16] A derived store's seed is a draft, never an observable value — (**ruled 2026-07-16**, #2897) **A derived store's seed is a draft, never an observable value.** The seed exists for th… |
7373
| A26 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:111` | — | action-await-contract.test.ts×2 fuzz-findings-l2.test.ts×1 posture-store-parity.test.ts×2 visibility-oracle-store.states.ts×2 visibility-oracle.states.ts×1 visibility-oracle.test.ts×1 | [ruled 2026-07-17] An ambient transaction window is one flush; parking is flush-driven — (**ruled 2026-07-17**, #2913; **enforcement hardened 2026-08-31**, #3141 — parking is flush-driven, and a trans… |
7474
| A27 | ruled | `docs/SPEC-ASYNC-SEMANTICS.md:301` | — | loading-value.test.ts×2 visibility-oracle.states.ts×18 visibility-oracle.test.ts×1 | [ruled 2026-08-10] The commit-#0 loading window is loading-class and verdict-quiet — (**ruled 2026-08-10**) **The commit-#0 loading window is loading-class and verdict-quiet.** A node born committed v… |
7575
| A28 | ruled, mechanism landed | `docs/SPEC-ASYNC-SEMANTICS.md:95` | constants.ts×1 core.ts×12 lanes.ts×2 scheduler.ts×3 types.ts×1 verdict.ts×2 store.ts×5 | continuation-sibling-reader-4146.test.ts×1 createOptimistic.test.ts×5 fuzz-findings-l2.test.ts×6 held-derivation-not-a-proposal-3612.test.ts×1 issue-3800-repro.test.ts×1 latest-held-till-flush.test.ts×1 posture-store-parity.test.ts×5 question-scoped-pending.test.ts×3 snapshot-derived-store-rows.test.ts×1 createOptimisticStore.test.ts×10 optimistic-draft-visibility-3665.test.ts×5 optimistic-list-mutation-matrix.harness.ts×1 optimistic-list-mutation-matrix.test.ts×2 shallow.test.ts×1 woken-transaction-adopts-staged-bump.test.ts×1 treeshake.test.ts×2 verdict-contract.test.ts×1 visibility-oracle-store.states.ts×8 visibility-oracle.states.ts×8 | [ruled, mechanism landed 2026-09-15] A write becomes visible at flush — to every channel — (**ruled 2026-09-08**; supersedes the #2922 mid-tick pull) **A write becomes visible at flush — to every chan… |

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ import {
4444
REACTIVE_RECOMPUTING_DEPS,
4545
REACTIVE_STAGED_READ,
4646
STATUS_ERROR,
47-
STATUS_PENDING
47+
STATUS_PENDING,
48+
STATUS_UNINITIALIZED
4849
} from "../core/constants.js";
4950
import {
5051
captureWriteSnapshot,
@@ -1741,14 +1742,18 @@ function changedBetween(
17411742

17421743
/** Value of a key with a leaf: core's — `read()` links a tracked reader and,
17431744
* tracked or not, applies the hold and A28 rules a signal's read does. A
1744-
* projection's unheld staging is ahead for a handler (`familyAhead`). */
1745+
* projection's unheld staging is ahead for a handler (`familyAhead`), and is
1746+
* the only value while its derive has never committed: the committed side
1747+
* is the seed, never observable (A25) — a reader core serves the screen (a
1748+
* verdict reader, #4355) is served the staging, as for a memo born staged
1749+
* (core `serve`). */
17451750
function nodeValue(node: Signal<any>, backing: any, target: StoreTarget): any {
17461751
let v = readNode(node);
17471752
if (
17481753
node._pendingValue !== NOT_PENDING &&
17491754
!(node._config & CONFIG_HELD) &&
1750-
context === null &&
1751-
target.fam !== null
1755+
target.fam !== null &&
1756+
(context === null || target.fam.node?._statusFlags! & STATUS_UNINITIALIZED)
17521757
)
17531758
v = node._pendingValue;
17541759
return v === (FORCE as any) ? backing : v;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
createMemo,
4+
createRenderEffect,
5+
createRoot,
6+
createStore,
7+
flush,
8+
latest
9+
} from "../src/index.js";
10+
11+
// #4355 (D-30, D-22, D-3): a derived store whose derive reads an async memo
12+
// through `latest()` resolves; its first downstream reader must see what the
13+
// derive wrote, never the seed. A render effect commits only the real value.
14+
describe("#4355 derived store over latest() of an async memo", () => {
15+
const settle = async () => {
16+
for (let i = 0; i < 4; i++) {
17+
await new Promise(r => setTimeout(r, 0));
18+
flush();
19+
}
20+
};
21+
22+
async function run(form: "latest" | "plain", reader: "memo" | "store" | "direct") {
23+
let resolve!: (v: { name: string }) => void;
24+
const seen: unknown[] = [];
25+
let dispose!: () => void;
26+
createRoot(d => {
27+
dispose = d;
28+
const record = createMemo(() => new Promise<{ name: string }>(r => (resolve = r)));
29+
const [state] = createStore<any>((draft: any) => {
30+
draft.value = {
31+
name: form === "latest" ? latest(() => record().name) : record().name
32+
};
33+
}, {});
34+
if (reader === "memo") {
35+
const view = createMemo(() => state.value?.name);
36+
createRenderEffect(view, v => {
37+
seen.push(v);
38+
});
39+
} else if (reader === "store") {
40+
// The report's display store: a second derived store copying the first.
41+
const [display] = createStore<any>((draft: any) => {
42+
draft.value = state.value;
43+
}, {});
44+
createRenderEffect(
45+
() => display.value?.name,
46+
v => {
47+
seen.push(v);
48+
}
49+
);
50+
} else {
51+
createRenderEffect(
52+
() => state.value?.name,
53+
v => {
54+
seen.push(v);
55+
}
56+
);
57+
}
58+
});
59+
flush();
60+
expect(seen).toEqual([]);
61+
resolve({ name: "Hartford" });
62+
await settle();
63+
dispose();
64+
return seen;
65+
}
66+
67+
for (const form of ["latest", "plain"] as const)
68+
for (const reader of ["memo", "store", "direct"] as const)
69+
it(`${form} derive, ${reader} reader: the effect commits only the value`, async () => {
70+
expect(await run(form, reader)).toEqual(["Hartford"]);
71+
});
72+
});
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4355 — a derived store whose derive reads an async memo through
6+
// `latest()`: once it resolves, a memo over the store sees what the derive
7+
// wrote, never the seed, so a hole fed through that memo shows the same
8+
// thing as a hole reading the store directly (D-30, D-3: JSX grouping does
9+
// not change the result). The signals-side pins are
10+
// `packages/signals/tests/derived-store-latest-seed-4355.test.ts`.
11+
import { describe, expect, test } from "vitest";
12+
import { createMemo, createStore, latest, Loading } from "solid-js";
13+
import { render } from "../src/index.js";
14+
15+
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
16+
17+
describe("derived store over latest() of an async memo (#4355)", () => {
18+
for (const through of ["memo", "direct"] as const)
19+
test(`a hole reading the store ${through === "memo" ? "through a memo" : "directly"} never sees the seed`, async () => {
20+
const div = document.createElement("div");
21+
const seen: string[] = [];
22+
const dispose = render(() => {
23+
const record = createMemo(async () => {
24+
await sleep(10);
25+
return { name: "Hartford" };
26+
});
27+
const [state] = createStore<{ value?: { name: string } }>(d => {
28+
d.value = { name: latest(() => record().name) };
29+
}, {});
30+
// `state.value.name.trim()` throws on the seed: the report's form
31+
// component.
32+
const name =
33+
through === "memo"
34+
? createMemo(() => state.value!.name.trim())
35+
: () => state.value!.name.trim();
36+
return (
37+
<Loading fallback={<p>Loading…</p>}>
38+
<p>{(seen.push(name()), name())}</p>
39+
</Loading>
40+
);
41+
}, div);
42+
expect(div.innerHTML).toBe("<p>Loading…</p>");
43+
await sleep(40);
44+
expect(div.innerHTML).toBe("<p>Hartford</p>");
45+
expect(seen.every(v => v === "Hartford")).toBe(true);
46+
dispose();
47+
});
48+
});

0 commit comments

Comments
 (0)