Skip to content

Commit 8a8e950

Browse files
ryansolidclaude
andauthored
fix(signals): a guess re-based over a parked question's answer waits for that question (#4559) (#4564)
* fix(signals): a guess re-based over a parked question's answer waits for that question (#4559) When a question's answer re-bases a keyed guess written while the question was in flight (#4525), the lane's rows are that answer's. If the question's transaction is still parked on another async read, the lane revealed those rows beside the old question (`open: [#2]`). The lane seam now holds such a lane while the transaction it was re-based over is live and blocked, so the new question and its answer land together (F-1, D-34 ¶3). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * perf(signals): inline the parked-question check in laneSeam (-8 B on optimistic rows) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 --------- Co-authored-by: Claude <[email protected]>
1 parent d1d6d51 commit 8a8e950

3 files changed

Lines changed: 144 additions & 1 deletion

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+
fix(signals): a guess re-based over a question's answer stays off the screen while that question's transaction is parked on another read, so the old question never shows beside the new answer's rows (#4559)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ import {
9494
queuePendingNode,
9595
releaseQueues,
9696
reruns,
97+
liveTx,
9798
resolveTx,
9899
sameLane,
99100
schedule,
@@ -843,7 +844,9 @@ function laneCorrections(): boolean {
843844
function laneSeam(l: Transaction, leaked: boolean): void {
844845
// Blocked — or one of its passes read a write the frame holds this seam:
845846
// its runs wait, the pass re-derives on the screen next round.
846-
if (leaked || blocked(l)) {
847+
// Re-based over a question still parked on another read (#4525): its rows
848+
// are that answer's, shown only with the question (F-1, D-34 ¶3, #4559).
849+
if (leaked || blocked(l) || (l.over && blocked(liveTx(l.over) || l))) {
847850
l._held = true;
848851
return;
849852
}
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
import { expect, test } from "vitest";
2+
import {
3+
action,
4+
createMemo,
5+
createOptimisticStore,
6+
createRenderEffect,
7+
createRoot,
8+
createSignal,
9+
flush,
10+
refresh
11+
} from "../src/index.js";
12+
13+
const tick = async () => {
14+
for (let i = 0; i < 4; i++) {
15+
await new Promise(r => setTimeout(r, 0));
16+
flush();
17+
}
18+
};
19+
20+
// #4559: #4536's setup plus a second async read of the question that answers
21+
// after the list does. The question's transaction stays parked on that read,
22+
// so the frame must not show the old question beside the new answer's rows
23+
// (F-1, D-34 ¶3).
24+
for (const order of ["question first", "list first"] as const)
25+
for (const mode of ["inline", "memo", "split"] as const)
26+
test(`a guess re-based while the question's transaction is parked keeps the frame whole (${order}, ${mode})`, async () => {
27+
type Issue = { id: number };
28+
const asks: { key: string; resolve: (value: any) => void }[] = [];
29+
const ask = (key: string) => new Promise<any>(resolve => asks.push({ key, resolve }));
30+
const settle = async (key: string, value: any) => {
31+
const i = asks.findIndex(a => a.key === key);
32+
expect(i).toBeGreaterThanOrEqual(0);
33+
asks.splice(i, 1)[0].resolve(value);
34+
await tick();
35+
};
36+
const frames: string[] = [];
37+
const last = () => frames.filter(f => !f.startsWith("other")).at(-1);
38+
let setFilter!: (value: string) => void;
39+
let closeOne!: (id: number) => unknown;
40+
let dispose!: () => void;
41+
createRoot(d => {
42+
dispose = d;
43+
const [filter, setFilterValue] = createSignal("open");
44+
setFilter = setFilterValue;
45+
const [issues, set] = createOptimisticStore<Issue[]>(() => ask(`issues:${filter()}`), [], {
46+
key: "id"
47+
});
48+
const other = createMemo(async () => {
49+
const f = filter();
50+
await ask(`other:${f}`);
51+
return f.length;
52+
});
53+
closeOne = action(function* (id: number) {
54+
set(list => {
55+
const i = list.findIndex(row => row.id === id);
56+
if (i >= 0) list.splice(i, 1);
57+
});
58+
yield ask(`close:${id}`);
59+
refresh(issues);
60+
});
61+
const screen = () => {
62+
let question: string;
63+
let rows: string;
64+
if (order === "question first") {
65+
question = filter();
66+
rows = issues.map(row => `[#${row.id}]`).join("");
67+
} else {
68+
rows = issues.map(row => `[#${row.id}]`).join("");
69+
question = filter();
70+
}
71+
return `${question}: ${rows}`;
72+
};
73+
if (mode === "split") {
74+
// One binding per read, as a template's holes are: the screen is
75+
// what both show after each flush.
76+
let question = "",
77+
rows = "";
78+
const show = () => frames.push(`${question}: ${rows}`);
79+
const bindQuestion = () =>
80+
createRenderEffect(filter, v => {
81+
question = v;
82+
queueMicrotask(show);
83+
});
84+
const bindRows = () =>
85+
createRenderEffect(
86+
() => issues.map(row => `[#${row.id}]`).join(""),
87+
v => {
88+
rows = v;
89+
queueMicrotask(show);
90+
}
91+
);
92+
if (order === "question first") {
93+
bindQuestion();
94+
bindRows();
95+
} else {
96+
bindRows();
97+
bindQuestion();
98+
}
99+
} else
100+
createRenderEffect(
101+
mode === "memo" ? createMemo(screen) : screen,
102+
value => void frames.push(value)
103+
);
104+
createRenderEffect(other, value => void frames.push(`other ${value}`));
105+
});
106+
try {
107+
await tick();
108+
await settle("other:open", {});
109+
await settle("issues:open", [{ id: 1 }, { id: 3 }, { id: 4 }]);
110+
expect(last()).toBe("open: [#1][#3][#4]");
111+
setFilter("closed");
112+
await tick();
113+
closeOne(1);
114+
await tick();
115+
expect(["open: [#3][#4]", "open: [#1][#3][#4]"]).toContain(last());
116+
await settle("issues:closed", [{ id: 1 }, { id: 2 }]);
117+
// The transaction is still parked on `other`: the question and its
118+
// answer have not landed, so the old frame (guess or not) stands.
119+
expect(["open: [#3][#4]", "open: [#1][#3][#4]"]).toContain(last());
120+
await settle("other:closed", {});
121+
expect(last()).toBe("closed: [#2]");
122+
await settle("close:1", {});
123+
await settle("issues:closed", [{ id: 2 }]);
124+
expect(last()).toBe("closed: [#2]");
125+
expect(
126+
frames.filter(
127+
frame =>
128+
(frame.startsWith("closed") && /#3|#4/.test(frame)) ||
129+
(frame.startsWith("open") && /#2/.test(frame))
130+
)
131+
).toEqual([]);
132+
} finally {
133+
dispose();
134+
}
135+
});

0 commit comments

Comments
 (0)