Skip to content

Commit fdcff00

Browse files
committed
fix(signals): an earlier latest() read no longer disarms a later never-shown throw (#4275)
A render effect moved into a verdict lane by a `latest(s)` read waited as lane work on a later read of a flight that had never shown, so its mount published with an empty slot. The pass now leaves the lane on that read and its frame holds, as in the reverse read order (S-39, D-28). Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent d786bcf commit fdcff00

3 files changed

Lines changed: 123 additions & 0 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 render effect that reads `latest(s)` before an async value that has never shown now holds its mount the same way the reverse read order does: an earlier `latest()` read no longer turns the later unready read into waiting lane work, so a newly mounted branch (for example under `<Show>`) stays unpublished until the value lands instead of appearing with an empty slot (S-39, D-28) (#4275).

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,17 @@ export function laneRead(c: Computed<any> | null, el: Signal<any> | Computed<any
580580
if (!guess && status & STATUS_PENDING) return NOT_PENDING;
581581
return laneValueOf(el);
582582
}
583+
// D-28: a leaf a verdict read moved into the lane still throws on a flight
584+
// that has never shown — the pass leaves the lane, and its frame holds as
585+
// if the read had come first (S-39, #4275).
586+
if (
587+
(c as any)._type === EFFECT_RENDER &&
588+
passLane?._parent!._verdict === passLane &&
589+
!guess &&
590+
status & STATUS_PENDING &&
591+
el._x!._lane === NOT_PENDING
592+
)
593+
setPassLane(null);
583594
if ((c as any)._type === EFFECT_RENDER && (passLane === null || !sameLane(passLane, l))) {
584595
if (!guess) {
585596
// A flight whose value has never shown: nothing to show — the leaf
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* #4275 (S-39, D-28): a read throws on its own; an earlier read does not
3+
* disarm a later throw. An action holds `s = 1` while `n0(1)` is in flight
4+
* and nothing on screen reads `n0`. A `<Show>` then mounts a reader of
5+
* `latest(s)` and `n0()`. Either read order holds the mount: control stays
6+
* off until `n0(1)` lands, then control and `[1, 1]` together. Before, the
7+
* `latest`-first order put the reader in the lane, `n0()` waited as lane
8+
* work instead of throwing, and the branch published with its slot empty.
9+
*/
10+
import { describe, expect, it } from "vitest";
11+
import {
12+
action,
13+
createMemo,
14+
createRenderEffect,
15+
createRoot,
16+
createSignal,
17+
flush,
18+
latest
19+
} from "../src/index.js";
20+
21+
const tick = async () => {
22+
await new Promise(r => setTimeout(r, 0));
23+
flush();
24+
};
25+
26+
async function run(order: "latest-first" | "n0-first") {
27+
const [s, setS] = createSignal(0);
28+
const [mounted, setMounted] = createSignal(false);
29+
const resolvers = new Map<number, (v: number) => void>();
30+
let control: unknown;
31+
let slot: unknown;
32+
createRoot(() => {
33+
const n0 = createMemo(async () => new Promise<number>(r => resolvers.set(latest(s), r)));
34+
const reader = () =>
35+
order === "latest-first" ? `[${latest(s)}, ${n0()}]` : `[${n0()}, ${latest(s)}]`;
36+
const opts = { transparent: true, sync: true };
37+
// <p>{mounted() ? "on" : "off"}</p>
38+
createRenderEffect(
39+
() => (mounted() ? "on" : "off"),
40+
v => {
41+
control = v;
42+
},
43+
opts
44+
);
45+
// <Show when={mounted()}>{reader}</Show>: the insert's outer binding
46+
// reads the branch and hands a function child to an inner binding.
47+
const when = createMemo(() => mounted(), { sync: true });
48+
const children = createMemo(() => (when() ? reader : undefined), { sync: true });
49+
createRenderEffect(
50+
() => {
51+
const c = children();
52+
if (typeof c !== "function") return c;
53+
createRenderEffect(
54+
c,
55+
v => {
56+
slot = v;
57+
},
58+
opts
59+
);
60+
},
61+
v => {
62+
slot = v;
63+
},
64+
opts
65+
);
66+
});
67+
flush();
68+
await tick();
69+
let release!: () => void;
70+
action(function* () {
71+
setS(1);
72+
yield new Promise<void>(r => (release = r));
73+
})();
74+
flush();
75+
await tick();
76+
const screens: unknown[] = [[control, slot]];
77+
setMounted(true);
78+
flush();
79+
await tick();
80+
screens.push([control, slot]);
81+
resolvers.get(1)?.(1);
82+
await tick();
83+
await tick();
84+
screens.push([control, slot]);
85+
release();
86+
await tick();
87+
await tick();
88+
return screens;
89+
}
90+
91+
describe("#4275: an earlier latest() read does not disarm a later throw", () => {
92+
it("n0-first holds the mount", async () => {
93+
expect(await run("n0-first")).toEqual([
94+
["off", undefined],
95+
["off", undefined],
96+
["on", "[1, 1]"]
97+
]);
98+
});
99+
100+
it("latest-first holds the mount too", async () => {
101+
expect(await run("latest-first")).toEqual([
102+
["off", undefined],
103+
["off", undefined],
104+
["on", "[1, 1]"]
105+
]);
106+
});
107+
});

0 commit comments

Comments
 (0)