Skip to content

Commit 8295a47

Browse files
committed
fix(signals): clear a derived store's stale inputs-published mark at its setter landing (#4269)
A store derive's first flight commits beneath its flight at the mount seam (CONFIG_INPUTS_PUBLISHED), but its landing commits through the setter, never through commitPendingNode, so the mark stood. On the next re-ask a verdict reader under a revealed boundary was refused the committed screen (observeFlight) and suspended, so `isPending(() => state.a)` read false beside the stale value. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent d786bcf commit 8295a47

3 files changed

Lines changed: 102 additions & 2 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 derived store's per-key `isPending` now reads `true` while the derive re-asks under a `Loading` boundary that has shown content, when the verdict is read in the same computation as the value (`${state.a} ${isPending(() => state.a)}`). The derive's first flight left a commit-beneath-a-flight mark that its setter landing never cleared, so the next re-ask suspended the verdict reader to the boundary (which kept the stale screen with `isPending` false) instead of serving it the committed value with `isPending` true, as an async memo does. (#4269)

‎packages/signals/src/core/async.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
CONFIG_GUESS,
55
CONFIG_OVERRIDE,
66
CONFIG_HELD,
7+
CONFIG_INPUTS_PUBLISHED,
78
CONFIG_STAGED,
89
CONFIG_STAGED_ERROR,
910
CONFIG_SYNC,
@@ -550,8 +551,14 @@ export function handleAsync<T>(
550551
return;
551552
}
552553
// A store derive's landing commits through its setter: unheld, the
553-
// shown error leaves now; held, at the derive's commit.
554-
if (!(el._config & CONFIG_HELD)) el._x!._shownError = undefined;
554+
// shown error leaves now, and so does a commit-beneath-a-flight's
555+
// CONFIG_INPUTS_PUBLISHED (its first flight's, #4269) — left standing,
556+
// a verdict reader of the next flight would suspend instead of being
557+
// served the screen; held, both at the derive's commit.
558+
if (!(el._config & CONFIG_HELD)) {
559+
el._x!._shownError = undefined;
560+
el._config &= ~CONFIG_INPUTS_PUBLISHED;
561+
}
555562
if (wasUninitialized) landStatus(el, true);
556563
// Attribution hook: this path landed through the setter (derived
557564
// stores, projections), which does not go through setSignal, so the
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import { describe, expect, it } from "vitest";
2+
import {
3+
createLoadingBoundary,
4+
createMemo,
5+
createRenderEffect,
6+
createRoot,
7+
createSignal,
8+
createStore,
9+
flush,
10+
isPending,
11+
untrack
12+
} from "../src/index.js";
13+
14+
// #4269 (D-30, S-37 row 2): a derived store's leaves report the derive's
15+
// new-question refetch like any async memo — also when the verdict is read in
16+
// the same computation as the value, under a boundary that has shown content.
17+
describe("#4269 derived store per-key isPending under a revealed boundary", () => {
18+
const tick = async () => {
19+
await new Promise(r => setTimeout(r, 0));
20+
flush();
21+
await new Promise(r => setTimeout(r, 0));
22+
flush();
23+
};
24+
25+
async function run(kind: "store" | "memo", where: "boundary" | "none") {
26+
const flights = new Map<string, { p: Promise<any>; resolve: (v: any) => void }>();
27+
const fetchKey = (key: string) => {
28+
if (!flights.has(key)) {
29+
let resolve!: (v: any) => void;
30+
const p = new Promise(r => (resolve = r));
31+
flights.set(key, { p, resolve });
32+
}
33+
return flights.get(key)!.p;
34+
};
35+
const land = async (key: string, v: any) => {
36+
flights.get(key)!.resolve(v);
37+
await tick();
38+
};
39+
let screen = "";
40+
const [id, setId] = createSignal(1);
41+
let dispose!: () => void;
42+
createRoot(d => {
43+
dispose = d;
44+
let a: () => any;
45+
if (kind === "store") {
46+
const [state] = createStore<any>(async (draft: any) => {
47+
const v = await fetchKey("s:" + id());
48+
Object.assign(draft, v);
49+
}, {});
50+
a = () => state.a;
51+
} else {
52+
const m = createMemo(() => fetchKey("s:" + id()));
53+
a = () => (m() as any).a;
54+
}
55+
const view = () => `${a()} ${isPending(a) ? "pending" : "-"}`;
56+
const out =
57+
where === "boundary" ? untrack(() => createLoadingBoundary(view, () => "loading")) : view;
58+
createRenderEffect(
59+
() => out(),
60+
v => {
61+
screen = v as string;
62+
}
63+
);
64+
});
65+
flush();
66+
await tick();
67+
await land("s:1", { a: 1, b: 1 });
68+
expect(screen).toBe("1 -");
69+
setId(2);
70+
flush();
71+
await tick();
72+
const pending = screen;
73+
await land("s:2", { a: 2, b: 2 });
74+
const landed = screen;
75+
dispose();
76+
return [pending, landed];
77+
}
78+
79+
it("store under a boundary reports pending on the re-ask", async () => {
80+
expect(await run("store", "boundary")).toEqual(["1 pending", "2 -"]);
81+
});
82+
it("memo under a boundary (control)", async () => {
83+
expect(await run("memo", "boundary")).toEqual(["1 pending", "2 -"]);
84+
});
85+
it("store without a boundary (control)", async () => {
86+
expect(await run("store", "none")).toEqual(["1 pending", "2 -"]);
87+
});
88+
});

0 commit comments

Comments
 (0)