Skip to content

Commit 0ad8249

Browse files
committed
Merge remote-tracking branch 'origin/next' into claude/fix-eb-memo-reject
2 parents 12615f1 + ab29345 commit 0ad8249

7 files changed

Lines changed: 252 additions & 36 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 second action's guess into an optimistic slot now shows at once while the first action's `refresh()` of a list the overlay also reads is still in flight, whatever order the overlay reads the two in, and whether it reads the guess directly or through a memo derived from it (#4629).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ What is rendered from a display-ahead read reveals together with it: an async me
216216

217217
A held display-ahead world ("a lane") is a hold seen from the outside. A render effect _off_ it that reads what it is revealing — mounted mid-hold, or re-run by an unrelated sync write — shows the committed value (what is on screen), publishes now, entangles nothing, and re-derives at the release: `Late: 0` at the mount, `Details: 1 | Late: 1 | Value: 1` at the release. `latest()` is not special here: a `createOptimistic` source behaves the same. A reader whose removal is staged in a live hold is still on screen and keeps holding the lane while visible; `latest()` read in such a branch peers through to the proposal. A direct leaf reading a lane's derivation shows the lane's revealed value and re-derives at the reveal (control and content never disagree); a derivation between (a memo, a boundary's tree) carries the future and is born held with its mount (D-2). The same holds for a render effect that reads an optimistic value before its lane is judged: if the lane holds on a derivation's flight, the effect shows the committed value and `latest()` of the guess shows the guess beside it, whether the two reads share one render effect or not — `1 x1 / 5`, then `5 x5 / 5` at the landing (#4284). **Inside the lane, "sees the parent's landings" is about computing, not showing (clarified 2026-10-28):** a lane derivation that reads a value the parent holds joins that hold (D-1) — it computes now, so async downstream of it starts without waiting for the commit, and its result shows at the commit as the hold's work. What lane work _displays_ is the screen plus the lane's own values: its guesses, or what its `latest()` reads asked for. A plain read in lane work of a node the parent holds and the lane does not show ahead is the screen's value, in a verdict lane as in an optimistic one (F-6: "a plain read beside it is a read"); `[s(), L()]` with `L = createMemo(() => latest(s))` shows `v:0 l:1`, as the inline `[s(), latest(s)]` does. A15 #3460's sentence is the computing half.
218218

219-
**Collapses:** [A15](./SPEC-ASYNC-SEMANTICS.md#a15-transition-entanglement-is-graph-driven-lanes-settle-as-one-reveal) lanes corollary (#3460, #3463, #3479, #3662, #3698), #3444, the fuzzer-finding F8 ruling (2026-10-05, #3806), the adopted-staging ruling. **Status:** standing; fuzzer finding F5b ("a stale reader of a held re-guess shows the revealed guess") pinned `it.fails`. Grouping: `tests/lane-render-effect-grouping-4284.test.ts`. Known deviation (#4629, 2026-11-02): a second action's guess into a slot whose earlier action's `refresh()` is in flight waits for that re-ask to land instead of showing now beside the screen's value of the re-asked node (the plain read in lane work above); pinned `it.fails` in `tests/projection-second-guess-4629.test.ts`.
219+
**Collapses:** [A15](./SPEC-ASYNC-SEMANTICS.md#a15-transition-entanglement-is-graph-driven-lanes-settle-as-one-reveal) lanes corollary (#3460, #3463, #3479, #3662, #3698), #3444, the fuzzer-finding F8 ruling (2026-10-05, #3806), the adopted-staging ruling. **Status:** standing; fuzzer finding F5b ("a stale reader of a held re-guess shows the revealed guess") pinned `it.fails`. Grouping: `tests/lane-render-effect-grouping-4284.test.ts`. Fixed 2026-11-02 (#4629, #4633, #4637): a second action's guess into a slot whose earlier action's `refresh()` is in flight shows now, beside the screen's value of the re-asked node (the plain read in lane work above), whatever order the pass reads them in (D-28); `tests/projection-second-guess-4629.test.ts`, `tests/optimistic-second-guess-reask-4629.test.ts`.
220220

221221
### D-27. A verdict reader's mount is a mainline mount
222222

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,8 +1426,25 @@ export function insertSubs(node: Signal<any> | Computed<any>): void {
14261426
* `laneRead` re-derives it on the screen if that lane holds (`entered`). */
14271427
export function laneDirty(node: Signal<any> | Computed<any>, l: Transaction): void {
14281428
for (let s = node._subs; s !== null; s = s._nextSub) {
1429-
const c = s._sub,
1430-
t = c._x?._transaction;
1429+
const c = s._sub;
1430+
let t = c._x?._transaction;
1431+
// A reader the parent holds pending on its re-ask (a correction's
1432+
// re-derivation waiting on a refresh) re-derives from the guess as the
1433+
// lane's work, seated there before its pass: lane work reads the
1434+
// parent's flight as the screen (D-26, D-37), whether it reads the
1435+
// flight before the guess or after (D-28), and whether it reads the
1436+
// guess itself or a derivation of it — this walk runs at every lane
1437+
// node's change. Seated at the guess read, the earlier read threw the
1438+
// pass back into the hold (#4629).
1439+
if (
1440+
t &&
1441+
l._parent &&
1442+
!(c as any)._type &&
1443+
(c._config & (CONFIG_HELD | CONFIG_OVERRIDE)) === CONFIG_HELD &&
1444+
(c._statusFlags & (STATUS_PENDING | STATUS_UNINITIALIZED)) === STATUS_PENDING &&
1445+
resolveTx(t) === resolveTx(l._parent)
1446+
)
1447+
list(c, (t = l));
14311448
if ((c as any)._type === EFFECT_RENDER && node._config & CONFIG_VERDICT)
14321449
((c._config |= CONFIG_VERDICT), (c._flags &= ~REACTIVE_LANE_DIRTY));
14331450
if (t?._lane ? sameLane(t, l) : (c as any)._type) c._flags |= REACTIVE_LANE_DIRTY;
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
/**
2+
* #4629 (the memo half): an async list `issues`, a `createOptimistic` log of
3+
* assignments overlaid on it by a memo. Action 1 is accepted and its
4+
* `refresh(issues)` is in flight when action 2 guesses into the same log.
5+
*
6+
* `issues` is not derived from the guess, so F-6's lane hold does not apply:
7+
* what lane work displays is the screen plus the lane's own values, and a
8+
* plain read in lane work of a node the parent holds is the screen's value
9+
* (D-26, clarified 2026-10-28). Action 1's re-ask is a `refresh()`, which
10+
* re-asks the same question and holds nothing new (D-34, D-31). The two
11+
* guesses share the log slot, so they entangle (D-33): the log reverts only
12+
* when the last of them settles, and a rejected second action reverts only
13+
* its own guess.
14+
*/
15+
import { describe, expect, it } from "vitest";
16+
import {
17+
action,
18+
createMemo,
19+
createOptimistic,
20+
createRenderEffect,
21+
createRoot,
22+
createSignal,
23+
flush,
24+
mapArray,
25+
refresh
26+
} from "../src/index.js";
27+
28+
type Row = { id: number; a: string };
29+
30+
const tick = async () => {
31+
for (let i = 0; i < 4; i++) {
32+
await new Promise(r => setTimeout(r, 0));
33+
flush();
34+
}
35+
};
36+
37+
type Read = "issuesFirst" | "guessFirst" | "viaMemo" | "viaMemoFirst";
38+
39+
function run(read: Read = "issuesFirst") {
40+
const asks: { key: string; res: (v: any) => void; rej: (e: any) => void }[] = [];
41+
const ask = (key: string) => new Promise<any>((res, rej) => asks.push({ key, res, rej }));
42+
const settle = async (key: string, v: any, fail = false) => {
43+
const i = asks.findIndex(a => a.key === key);
44+
const a = asks.splice(i, 1)[0];
45+
fail ? a.rej(v) : a.res(v);
46+
await tick();
47+
};
48+
const server: Row[] = [
49+
{ id: 3, a: "-" },
50+
{ id: 4, a: "dana" }
51+
];
52+
let screen = "";
53+
let assign!: (id: number) => any;
54+
createRoot(() => {
55+
const issues = createMemo<Row[]>(() => ask("issues"));
56+
const [truth] = createSignal<Row[]>(() => []);
57+
const [assigning, guess] = createOptimistic<Row[]>(() => truth());
58+
// The guess read straight, or through a memo derived from it (the held
59+
// pass is then a grandchild of the guessed node).
60+
const byId = createMemo(() => {
61+
const m: Record<number, string> = {};
62+
for (const x of assigning()) m[x.id] = x.a;
63+
return m;
64+
});
65+
const guessed = () => {
66+
if (read === "viaMemo" || read === "viaMemoFirst") return byId();
67+
const m: Record<number, string> = {};
68+
for (const x of assigning()) m[x.id] = x.a;
69+
return m;
70+
};
71+
const overlay = createMemo(() => {
72+
const first = read === "guessFirst" || read === "viaMemoFirst" ? guessed() : undefined;
73+
return issues().map(i => {
74+
const a = (first ?? guessed())[i.id];
75+
return a ? { ...i, a } : i;
76+
});
77+
});
78+
const rows = mapArray(overlay, (r: Row) => () => `[#${r.id} ${r.a}]`);
79+
createRenderEffect(
80+
() =>
81+
rows()
82+
.map(f => f())
83+
.join(""),
84+
v => void (screen = v)
85+
);
86+
assign = action(function* (id: number) {
87+
guess(xs => [...xs, { id, a: "guest" }]);
88+
try {
89+
yield ask(`assign:${id}`);
90+
} catch {
91+
return;
92+
}
93+
refresh(issues);
94+
});
95+
});
96+
return {
97+
get screen() {
98+
return screen;
99+
},
100+
settle,
101+
server,
102+
assign: (id: number) => assign(id),
103+
snap: () => server.map(x => ({ ...x }))
104+
};
105+
}
106+
107+
async function toSecondGuess(read?: Read) {
108+
const t = run(read);
109+
flush();
110+
await tick();
111+
await t.settle("issues", t.snap());
112+
expect(t.screen).toBe("[#3 -][#4 dana]");
113+
t.assign(3);
114+
await tick();
115+
expect(t.screen).toBe("[#3 guest][#4 dana]");
116+
t.server[0].a = "guest";
117+
await t.settle("assign:3", {});
118+
// action 1's refresh(issues) is in flight
119+
expect(t.screen).toBe("[#3 guest][#4 dana]");
120+
t.assign(4);
121+
await tick();
122+
return t;
123+
}
124+
125+
describe("#4629: a second guess into a log beside the first action's re-ask (memo)", () => {
126+
it("the guess shows at once, beside the screen's issues (D-26), and stays", async () => {
127+
const t = await toSecondGuess();
128+
// (4)
129+
expect(t.screen).toBe("[#3 guest][#4 guest]");
130+
await t.settle("issues", t.snap());
131+
// (5) action 1's re-ask lands; action 2's guess still stands
132+
expect(t.screen).toBe("[#3 guest][#4 guest]");
133+
t.server[1].a = "guest";
134+
await t.settle("assign:4", {});
135+
await t.settle("issues", t.snap());
136+
// (6) both actions settled on the truth
137+
expect(t.screen).toBe("[#3 guest][#4 guest]");
138+
});
139+
140+
// D-28: whether a read throws is the read's own — not the order of the
141+
// reads around it. Reading the log before `issues` showed the guess at
142+
// once already.
143+
it("either read order, read straight or through a memo: the guess shows at once", async () => {
144+
for (const read of ["issuesFirst", "guessFirst", "viaMemo", "viaMemoFirst"] as const) {
145+
const t = await toSecondGuess(read);
146+
expect(t.screen, read).toBe("[#3 guest][#4 guest]");
147+
await t.settle("issues", t.snap());
148+
expect(t.screen, read).toBe("[#3 guest][#4 guest]");
149+
}
150+
});
151+
152+
it("through a memo, a rejected second action reverts its row", async () => {
153+
const t = await toSecondGuess("viaMemo");
154+
expect(t.screen).toBe("[#3 guest][#4 guest]");
155+
await t.settle("issues", t.snap());
156+
await t.settle("assign:4", new Error("no"), true);
157+
expect(t.screen).toBe("[#3 guest][#4 dana]");
158+
});
159+
160+
it("a rejected second action reverts its row", async () => {
161+
const t = await toSecondGuess();
162+
expect(t.screen).toBe("[#3 guest][#4 guest]");
163+
await t.settle("issues", t.snap());
164+
expect(t.screen).toBe("[#3 guest][#4 guest]");
165+
await t.settle("assign:4", new Error("no"), true);
166+
expect(t.screen).toBe("[#3 guest][#4 dana]");
167+
});
168+
169+
// D-33: the two guesses share the log slot, so the slot reverts only when
170+
// the last of the two actions settles — action 1 is out until its re-ask
171+
// lands (D-35: a plain load the action asked for is still in flight).
172+
it("a second action rejected before action 1's re-ask lands reverts with it", async () => {
173+
const t = await toSecondGuess();
174+
expect(t.screen).toBe("[#3 guest][#4 guest]");
175+
await t.settle("assign:4", new Error("no"), true);
176+
expect(t.screen).toBe("[#3 guest][#4 guest]");
177+
await t.settle("issues", t.snap());
178+
expect(t.screen).toBe("[#3 guest][#4 dana]");
179+
});
180+
});

‎packages/signals/tests/projection-second-guess-4629.test.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* `issues` is not derived from the guess, so F-6's lane hold does not apply:
99
* a plain read in lane work of a node the parent holds is the screen's value
1010
* (D-26, clarified 2026-10-28), and the lane displays the screen plus its own
11-
* guesses — `[#4 guest]` now, in both shapes. Today both shapes hold the
12-
* guess until action 1's re-ask lands (`[#4 dana]`): a known deviation,
13-
* pinned `it.fails` below.
11+
* guesses — `[#4 guest]` now, in both shapes. (Before #4637 both shapes held
12+
* the guess until action 1's re-ask landed: the overlay's pass threw on its
13+
* first, pending read before it reached the guess, D-28.)
1414
*
1515
* (5) Through the projection the guess never showed before the server's
1616
* answer: the derive's pass that ran as the landing's (the frame's) work and
@@ -137,8 +137,7 @@ describe("#4629: a second guess into a log while the first action's refresh is i
137137
expect([f5, f6]).toEqual(["[#3 guest][#4 guest]", "[#3 guest][#4 guest]"]);
138138
});
139139

140-
// Known deviation (D-26): the guess waits on action 1's re-ask.
141-
it.fails(`${name}: the guess shows at once, beside the screen's issues (D-26)`, async () => {
140+
it(`${name}: the guess shows at once, beside the screen's issues (D-26)`, async () => {
142141
expect(await frames(proj)).toEqual([
143142
"[#3 guest][#4 guest]",
144143
"[#3 guest][#4 guest]",

‎scripts/size/floor-caps.json‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
"minified": 26754
99
},
1010
"app: hydrating (no stores) with Show/For/Loading/Errored/lazy": {
11-
"cap": "18.93 KB",
12-
"minified": 53671
11+
"cap": "18.94 KB",
12+
"minified": 53832
1313
},
1414
"page: base server components (hydrating + dynamic + frames + sf reference)": {
15-
"cap": "33.91 KB",
16-
"minified": 101797
15+
"cap": "33.92 KB",
16+
"minified": 101947
1717
},
1818
"page: live server components (base + live/GET + action + isPending/latest)": {
19-
"cap": "39.77 KB",
20-
"minified": 119743
19+
"cap": "39.82 KB",
20+
"minified": 119983
2121
},
2222
"server: floor (getRequestEvent + isServer)": {
2323
"cap": "1.29 KB",

0 commit comments

Comments
 (0)