Skip to content

Commit 07fa8be

Browse files
committed
fix(signals): latest() tears ahead of an optimistic lane however reads are grouped (#4284)
A render effect that read a guess and latest(guess) together entered the guess's lane before the seam judged it; when the lane held on a downstream async derivation, the effect's run parked with the lane and froze the latest() beside it (`1 x1 / 1`), while split effects showed `1 x1 / 5`. A verdict reader entering a lane the seam has not judged now reads ahead of it like a staging read: if the seam holds the lane, the pass re-derives next round from the frame's seat, a stale reader of the lane (committed value and committed derivation, `latest()` shows the guess). A verdict lane's seat no longer links a render effect into a guess lane, and a never-shown lane's pending member reads as its committed value for a stale reader. An unblocked lane pays no extra pass. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 1d6c40f commit 07fa8be

5 files changed

Lines changed: 215 additions & 7 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+
`latest()` of an optimistic value now shows the guess beside the held screen however reads are grouped into render effects (#4284). When a guess's lane is held on a downstream async derivation, a render effect that reads the guess and `latest(guess)` together no longer parks with the lane and freezes the `latest()` read: like split effects, it shows `1 x1 / 5` (the committed value and its derivation beside the guess) and `5 x5 / 5` when the derivation lands. The lane still holds the guess until its derivation lands; an unblocked lane costs no extra pass.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ What is rendered from a display-ahead read reveals together with it: an async me
212212

213213
**From:** F-6, F-1, F-3. **Scenarios:** S-30.
214214

215-
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).
215+
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).
216216

217-
**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`.
217+
**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`.
218218

219219
### D-27. A verdict reader's mount is a mainline mount
220220

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ These are the only words the fundamentals use. Internal names (transaction, stag
8080

8181
## F-6. Display-ahead readers show now and never hold the change they read ahead of; their own async holds them, in their own lane
8282

83-
**Immutable.** `latest(x)`, `isPending(x)` and an optimistic value are the screen's way of showing a held change ahead of its reveal: they display the in-flight value, or the verdict about it, now, beside the held screen, and they are never a reason for the change to wait. But a display-ahead read is a world of its own — a _lane_ — and F-1 and F-2 apply inside it exactly as they do outside: **async derived from a display-ahead read opens a hold of its own, in that lane.** An async memo over `latest(x)`, a refetch an optimistic value feeds, a derivation of either that is rendered — while it is in flight, the display-ahead readers and everything rendered from them wait together, showing what the screen showed, and reveal together when it lands: never a `latest()` view beside a half-computed derivation of itself. That lane hold is separate from the parent hold on both sides — the parent does not wait for it, and it does not wait for the parent; it reveals at its own landing. `latest()` escapes the hold, not its own lane. A display-ahead read in `on` arms the boundary from a frame that has already landed, so the fallback shows now, beside the held frame; every read of the held value stays held (D-17).
83+
**Immutable.** `latest(x)`, `isPending(x)` and an optimistic value are the screen's way of showing a held change ahead of its reveal: they display the in-flight value, or the verdict about it, now, beside the held screen, and they are never a reason for the change to wait. But a display-ahead read is a world of its own — a _lane_ — and F-1 and F-2 apply inside it exactly as they do outside: **async derived from a display-ahead read opens a hold of its own, in that lane.** An async memo over `latest(x)`, a refetch an optimistic value feeds, a derivation of either that is rendered — while it is in flight, the display-ahead readers (but `latest()` of an optimistic value, below) and everything rendered from them wait together, showing what the screen showed, and reveal together when it lands: never a `latest()` view beside a half-computed derivation of itself. That lane hold is separate from the parent hold on both sides — the parent does not wait for it, and it does not wait for the parent; it reveals at its own landing. `latest()` escapes the hold, not its own lane — and an optimistic value's lane is not `latest()`'s own: `latest()` of an optimistic value whose lane is held shows the guess now, beside the readers that wait, whether or not they share its render effect (#4284). A display-ahead read in `on` arms the boundary from a frame that has already landed, so the fallback shows now, beside the held frame; every read of the held value stays held (D-17).
8484

8585
**What it does not say.** It does not say display-ahead readers never wait — they wait for their _own_ async, in their own lane; what they never wait for is the hold they are reading ahead of. It does not say `latest()` shows a write before the flush that carries it (F-10). It does not say a display-ahead reader can _reveal_ a held change for the rest of the screen — a mount it opens is a mainline mount and reads the screen (D-27). It does not say an optimistic value is pending (F-9: verdict-inert). It does not say a render effect escapes by also asking for a verdict: a probe alone holds nothing, but a plain read beside it is a read (F-2) — `[isPending(x), x()]` in one render effect holds like `x()` alone, and the two stay atomic (D-23, #3442).
8686

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,11 @@ function dissolveLane(l: Transaction, into: Transaction | null, except?: Signal<
550550
* has shown, or one the seam has not judged yet (its run waits on the
551551
* verdict: released if the lane shows, held if it blocks) — and sees the
552552
* lane's latest. NOT_PENDING falls through: lane work's read of a pending
553-
* member throws like any. */
553+
* member throws like any. A verdict reader entering a lane the seam has
554+
* not judged reads ahead of it like a staging read: if the seam holds the
555+
* lane, the pass re-derives on the screen (`entered`, #4284) — `latest()`
556+
* beside the lane's nodes tears ahead of the hold however the reads are
557+
* grouped into effects. */
554558
export function laneRead(c: Computed<any> | null, el: Signal<any> | Computed<any>): unknown {
555559
const guess = el._config & CONFIG_GUESS;
556560
const l = txOf(el);
@@ -586,10 +590,13 @@ export function laneRead(c: Computed<any> | null, el: Signal<any> | Computed<any
586590
const never = pending && el._x!._lane === NOT_PENDING;
587591
// D-28: a leaf a verdict read moved into the lane still throws on such
588592
// a flight — the pass leaves the lane, and its frame holds as if the
589-
// read had come first (S-39, #4275).
590-
if (never && passLane?._parent!._verdict === passLane) setPassLane(null);
593+
// read had come first (S-39, #4275). Nor does a verdict lane's seat carry
594+
// the leaf into another lane (no link): it reads that lane as from the
595+
// frame's seat (#4284).
596+
if ((never || passLane !== l) && passLane?._parent!._verdict === passLane) setPassLane(null);
591597
if (passLane === null || !sameLane(passLane, l)) {
592-
if (never) return NOT_PENDING;
598+
// (A lane that has never shown: the screen is the committed value.)
599+
if (never && l._shown) return NOT_PENDING;
593600
if (
594601
!guess &&
595602
el._pendingValue !== NOT_PENDING &&
@@ -608,6 +615,9 @@ export function laneRead(c: Computed<any> | null, el: Signal<any> | Computed<any
608615
}
609616
return display(el);
610617
}
618+
// A verdict reader reads ahead of the seam's verdict: re-derived on the
619+
// screen if the lane holds (#4284).
620+
if (c._config & CONFIG_VERDICT && l._parent!._verdict !== l) entered.push(c);
611621
}
612622
}
613623
enterLane(l, c);
@@ -855,7 +865,17 @@ const laneSeams = (leaks: Computed<any>[] | null): void => {
855865
}
856866
for (let k = Math.min(judged, lanes.length) - 1; k >= 0; k--)
857867
laneSeam(lanes[k], leaked.indexOf(lanes[k]) !== -1);
868+
// A verdict reader that entered a lane this seam held: its run waits with
869+
// the lane, and the verdict beside it would freeze — it re-derives next
870+
// round from the frame's seat, a stale reader of the lane (#4284).
871+
for (let r; (r = entered.pop()); )
872+
if (r._x!._transaction?._held) {
873+
r._flags &= ~REACTIVE_LANE_DIRTY;
874+
enqueueSub(r);
875+
}
858876
};
877+
/** Render effects that read a verdict and entered a lane before its seam (#4284). */
878+
const entered: Computed<any>[] = [];
859879
installLaneHooks(
860880
laneRead,
861881
laneStage,
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
/**
2+
* #4284 — `latest()` tears ahead of the screen, and the frame does not depend
3+
* on how reads are grouped into render effects.
4+
*
5+
* An action writes `x` (a plain signal, or an optimistic guess) and yields a
6+
* promise. A render effect shows `${x()} ${derived()} / ${latest(x)}`, either
7+
* as one effect or split into `${x()} ${derived()} /` and `${latest(x)}`.
8+
*
9+
* - held write: `1 / 5` either way;
10+
* - guess, no downstream async: `5 / 5` either way;
11+
* - guess with a downstream async memo (`derived`, the lane held on it):
12+
* `1 x1 / 5` either way — the render effect reads the guess as the screen
13+
* (committed) beside `latest(guess)` — and `5 x5 / 5` at the lane's
14+
* landing. The guess does not reveal before `derived(5)` lands.
15+
*
16+
* Before, the combined effect entered the lane on its `x()` read and parked
17+
* with it, freezing the `latest(x)` beside it at `1 x1 / 1`.
18+
*/
19+
import { describe, expect, it } from "vitest";
20+
import {
21+
action,
22+
createMemo,
23+
createOptimistic,
24+
createRenderEffect,
25+
createRoot,
26+
createSignal,
27+
flush,
28+
latest
29+
} from "../src/index.js";
30+
31+
type Kind = "held" | "opt" | "lane";
32+
type Mode = "one" | "split";
33+
type Order = "plain-first" | "latest-first";
34+
35+
async function tick() {
36+
for (let i = 0; i < 3; i++) {
37+
await new Promise(r => setTimeout(r, 0));
38+
flush();
39+
}
40+
}
41+
42+
function setup(kind: Kind, mode: Mode, order: Order = "plain-first") {
43+
let resolveDerived: (() => void) | undefined;
44+
let resolveAction!: () => void;
45+
let attempt!: () => Promise<void>;
46+
let screen = "";
47+
let a = "";
48+
let b = "";
49+
const dispose = createRoot(d => {
50+
let x: () => number;
51+
let set: (v: number) => void;
52+
if (kind === "held") [x, set] = createSignal(1);
53+
else {
54+
const [base] = createSignal(1);
55+
[x, set] = createOptimistic(() => base());
56+
}
57+
const derived =
58+
kind === "lane"
59+
? createMemo(() =>
60+
x() === 1 ? "x1" : new Promise<string>(r => (resolveDerived = () => r("x" + x())))
61+
)
62+
: () => "-";
63+
attempt = action(function* () {
64+
set(5);
65+
yield new Promise<void>(r => (resolveAction = r));
66+
});
67+
if (mode === "one")
68+
createRenderEffect(
69+
() => {
70+
if (order === "latest-first") {
71+
const l = latest(x);
72+
return `${x()} ${derived()} / ${l}`;
73+
}
74+
return `${x()} ${derived()} / ${latest(x)}`;
75+
},
76+
v => void (screen = v)
77+
);
78+
else {
79+
createRenderEffect(
80+
() => `${x()} ${derived()} /`,
81+
v => void (screen = `${(a = v)} ${b}`)
82+
);
83+
createRenderEffect(
84+
() => latest(x),
85+
v => void (screen = `${a} ${(b = String(v))}`)
86+
);
87+
}
88+
return d;
89+
});
90+
return {
91+
dispose,
92+
attempt,
93+
screen: () => screen,
94+
resolveDerived: () => resolveDerived!(),
95+
resolveAction: () => resolveAction()
96+
};
97+
}
98+
99+
describe("#4284 latest() tears ahead of the hold however reads are grouped", () => {
100+
for (const mode of ["one", "split"] as const) {
101+
it(`held write (${mode}): the screen beside latest — 1 - / 5`, async () => {
102+
const t = setup("held", mode);
103+
flush();
104+
await tick();
105+
expect(t.screen()).toBe("1 - / 1");
106+
void t.attempt();
107+
flush();
108+
await tick();
109+
expect(t.screen()).toBe("1 - / 5");
110+
t.resolveAction();
111+
await tick();
112+
expect(t.screen()).toBe("5 - / 5");
113+
t.dispose();
114+
});
115+
116+
it(`guess, no downstream async (${mode}): the lane shows — 5 - / 5`, async () => {
117+
const t = setup("opt", mode);
118+
flush();
119+
await tick();
120+
void t.attempt();
121+
flush();
122+
await tick();
123+
expect(t.screen()).toBe("5 - / 5");
124+
t.dispose();
125+
});
126+
127+
it(`guess with a downstream async memo (${mode}): 1 x1 / 5, then 5 x5 / 5 at the landing`, async () => {
128+
const t = setup("lane", mode);
129+
flush();
130+
await tick();
131+
expect(t.screen()).toBe("1 x1 / 1");
132+
void t.attempt();
133+
flush();
134+
await tick();
135+
// The lane holds on derived(5): the guess does not reveal; latest tears.
136+
expect(t.screen()).toBe("1 x1 / 5");
137+
t.resolveDerived();
138+
await tick();
139+
expect(t.screen()).toBe("5 x5 / 5");
140+
t.dispose();
141+
});
142+
}
143+
144+
it("guess with a downstream async memo, latest() read first in the one effect: 1 x1 / 5, then 5 x5 / 5", async () => {
145+
const t = setup("lane", "one", "latest-first");
146+
flush();
147+
await tick();
148+
void t.attempt();
149+
flush();
150+
await tick();
151+
expect(t.screen()).toBe("1 x1 / 5");
152+
t.resolveDerived();
153+
await tick();
154+
expect(t.screen()).toBe("5 x5 / 5");
155+
t.dispose();
156+
});
157+
158+
it("guess, no downstream async, one effect: one pass for the guess (no stale re-run)", async () => {
159+
let passes = 0;
160+
let attempt!: () => Promise<void>;
161+
const seen: string[] = [];
162+
const dispose = createRoot(d => {
163+
const [base] = createSignal(1);
164+
const [x, set] = createOptimistic(() => base());
165+
attempt = action(function* () {
166+
set(5);
167+
yield new Promise<void>(() => {});
168+
});
169+
createRenderEffect(
170+
() => (passes++, `${x()} / ${latest(x)}`),
171+
v => void seen.push(v)
172+
);
173+
return d;
174+
});
175+
flush();
176+
void attempt();
177+
flush();
178+
await tick();
179+
expect(seen).toEqual(["1 / 1", "5 / 5"]);
180+
expect(passes).toBe(2);
181+
dispose();
182+
});
183+
});

0 commit comments

Comments
 (0)