Skip to content

Commit 4170cef

Browse files
committed
fix(signals): a leaf waiting on an unshown lane re-derives at its reveal (#4338)
A render effect that reads a verdict lane's node from the frame while the lane is held and has never shown throws NotReady (the node has no committed value) and holds its frame. That throw names no flight, so only the lane's reveal can re-derive it, but laneRead pushed the reader onto the lane's reruns only on the non-throwing path. The leaf stayed pending, held its transaction, and the lane ends only when that transaction lands: the re-created section never committed. Register the rerun before the throw (a reorder: +0 B minified). Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent 17d4d1b commit 4170cef

4 files changed

Lines changed: 215 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+
A section a change mounts now commits once its async memos land when two boundaries read `isPending()` of the same memo and that memo lands last (#4338). The nested reader's pending held the `isPending` lane, so the sibling boundary's output became a lane node before the lane had shown; its render effect, reading that node from the frame, had no committed value to show and went pending on no flight — and was registered to re-derive at the lane's reveal only when it did not throw. It held the change, the lane ends only when the change lands, and the old content stayed on screen for good. The reader is now registered for the reveal before it waits, so it re-derives there and the change commits whole.

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,13 +609,16 @@ export function laneRead(c: Computed<any> | null, el: Signal<any> | Computed<any
609609
)
610610
return el._pendingValue;
611611
if (l._held || pending) {
612-
if (!guess && !l._shown && status & STATUS_UNINITIALIZED) throw new NotReadyError(null);
613612
// Re-derived at the reveal; once per pass (the pass may also be a stale
614613
// reader of a transaction, REACTIVE_FRAME_READ — both reruns apply).
614+
// Before the throw below: a leaf that waits on a lane that has never
615+
// shown has no flight to settle it — only the reveal re-derives it,
616+
// and its pending holds its frame until then (#4338).
615617
if (!(c._flags & REACTIVE_SCREEN_READ)) {
616618
c._flags |= REACTIVE_FRAME_READ | REACTIVE_SCREEN_READ;
617619
l._reruns.push(c);
618620
}
621+
if (!guess && !l._shown && status & STATUS_UNINITIALIZED) throw new NotReadyError(null);
619622
return display(el);
620623
}
621624
// A verdict reader reads ahead of the seam's verdict: re-derived on the
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/**
2+
* #4338: a render effect that reads a verdict lane's node while that lane is
3+
* held and has never shown waits for the lane's reveal. The node has no
4+
* committed value, so the leaf throws NotReady and its pending holds its
5+
* frame (F-2); that throw names no flight, so nothing but the reveal can
6+
* re-derive it. It was registered for the reveal only when it did not
7+
* throw, so the leaf stayed pending: the hold waited on it, and it waited on
8+
* a lane that ends only when the hold lands.
9+
*
10+
* Shape (the issue's `<Section>`): two `<Errored>` boundaries read
11+
* `isPending(slow)`, one of them nested under `isPending(fast)`. `fast`
12+
* lands first and mounts the nested reader, whose pending on `slow` holds
13+
* the verdict lane; `slow` lands next and the sibling boundary's output
14+
* becomes a lane node before the lane has shown.
15+
*/
16+
import { afterEach, beforeEach, expect, it, vi } from "vitest";
17+
import {
18+
createErrorBoundary,
19+
createMemo,
20+
createRenderEffect,
21+
createRoot,
22+
flush,
23+
isPending,
24+
latest
25+
} from "../src/index.js";
26+
27+
beforeEach(() => vi.useFakeTimers());
28+
afterEach(() => vi.useRealTimers());
29+
30+
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
31+
const latestOr = (read: () => string) => {
32+
try {
33+
return latest(read) ?? "";
34+
} catch {
35+
return "";
36+
}
37+
};
38+
/** `<Show when>` with a static child: the child is built in the value memo. */
39+
function Show(when: () => unknown, children: () => unknown) {
40+
const value = createMemo(when);
41+
const condition = createMemo(value, { equals: (a, b) => !a === !b });
42+
return createMemo(() => (condition() ? children() : undefined));
43+
}
44+
interface El {
45+
tag: string;
46+
text?: string;
47+
}
48+
const el = (tag: string, text?: () => string): El => {
49+
const node: El = { tag };
50+
if (text) createRenderEffect(text, v => void (node.text = v));
51+
return node;
52+
};
53+
const unwrap = (v: unknown): unknown =>
54+
typeof v === "function" ? unwrap(v()) : Array.isArray(v) ? v.map(unwrap) : v;
55+
const html = (v: unknown): string =>
56+
Array.isArray(v)
57+
? v.map(html).join("")
58+
: v == null
59+
? ""
60+
: typeof v === "object"
61+
? `<${(v as El).tag}>${(v as El).text ?? ""}</${(v as El).tag}>`
62+
: String(v);
63+
64+
for (const [label, fastMs, slowMs, errored] of [
65+
["the twice-read memo lands last", 5, 30, true],
66+
["the twice-read memo lands last, no error boundaries", 5, 30, false],
67+
["the twice-read memo lands first", 30, 5, true]
68+
] as const)
69+
it(`#4338: every reader of isPending(slow) shows when both land (${label})`, async () => {
70+
const shown: { a?: unknown; b?: unknown } = {};
71+
const screen = () => html(shown.a) + "|" + html(shown.b);
72+
const dispose = createRoot(d => {
73+
const fast = createMemo(async () => (await sleep(fastMs), "fast"));
74+
const slow = createMemo(async () => (await sleep(slowMs), "slow"));
75+
const boundary = (fn: () => unknown) =>
76+
errored ? createErrorBoundary(fn, () => "err") : fn();
77+
const first = boundary(() =>
78+
Show(
79+
() => !isPending(() => fast()),
80+
() => [
81+
el("p", () => latestOr(() => fast())),
82+
Show(
83+
() => !isPending(() => slow()),
84+
() => el("b", () => latestOr(() => slow()))
85+
)
86+
]
87+
)
88+
);
89+
const second = boundary(() =>
90+
Show(
91+
() => !isPending(() => slow()),
92+
() => el("span")
93+
)
94+
);
95+
// The two holes of the section's `<div>`, one render effect each.
96+
createRenderEffect(
97+
() => unwrap(first),
98+
a => void (shown.a = a)
99+
);
100+
createRenderEffect(
101+
() => unwrap(second),
102+
b => void (shown.b = b)
103+
);
104+
return d;
105+
});
106+
flush();
107+
for (let t = 0; t < 40; t += 5) {
108+
await vi.advanceTimersByTimeAsync(5);
109+
flush();
110+
}
111+
expect(screen()).toBe("<p>fast</p><b>slow</b>|<span></span>");
112+
dispose();
113+
});
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4338: a section the change mounts commits once both of its async memos
6+
// have landed (F-2: the old section stays until then, then the new one shows
7+
// whole) — also when two sibling <Errored> boundaries read isPending() of
8+
// the same memo and that memo lands after the other one.
9+
import { afterEach, beforeEach, expect, test, vi } from "vitest";
10+
import {
11+
Errored,
12+
For,
13+
Loading,
14+
Show,
15+
createMemo,
16+
createSignal,
17+
flush,
18+
isPending,
19+
latest
20+
} from "solid-js";
21+
import { render } from "../src/index.js";
22+
23+
beforeEach(() => vi.useFakeTimers());
24+
afterEach(() => vi.useRealTimers());
25+
26+
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms));
27+
const latestOr = <T,>(read: () => T, fallback: T): T => {
28+
try {
29+
return latest(read) ?? fallback;
30+
} catch {
31+
return fallback;
32+
}
33+
};
34+
const section = (k: string) =>
35+
`<div><p>fast-${k}</p><b>slow-${k}</b><!----><span>side</span><!----></div>`;
36+
37+
for (const [label, fastMs, slowMs, loading] of [
38+
["twice-read memo lands last", 5, 30, true],
39+
["twice-read memo lands last, no <Loading>", 5, 30, false],
40+
["twice-read memo lands first", 30, 5, true]
41+
] as const)
42+
test(`the re-created section commits whole (${label})`, async () => {
43+
function Section(props: { k: string }) {
44+
const fast = createMemo(async () => {
45+
await sleep(fastMs);
46+
return "fast-" + props.k;
47+
});
48+
const slow = createMemo(async () => {
49+
await sleep(slowMs);
50+
return "slow-" + props.k;
51+
});
52+
return (
53+
<div>
54+
<Errored fallback={<i>err1</i>}>
55+
<Show when={!isPending(() => fast())}>
56+
<p>{latestOr(() => fast(), "")}</p>
57+
<Show when={!isPending(() => slow())}>
58+
<b>{latestOr(() => slow(), "")}</b>
59+
</Show>
60+
</Show>
61+
</Errored>
62+
<Errored fallback={<i>err2</i>}>
63+
<Show when={!isPending(() => slow())}>
64+
<span>side</span>
65+
</Show>
66+
</Errored>
67+
</div>
68+
);
69+
}
70+
const [key, setKey] = createSignal("a");
71+
const list = createMemo(() => [key()]);
72+
const container = document.createElement("div");
73+
const rows = () => <For each={list()}>{k => <Section k={k} />}</For>;
74+
const dispose = render(
75+
() => (loading ? <Loading fallback={<i>loading</i>}>{rows()}</Loading> : rows()),
76+
container
77+
);
78+
const before = loading ? "<i>loading</i>" : "";
79+
const frames = async (from: string, to: string) => {
80+
const last = Math.max(fastMs, slowMs);
81+
for (let t = 0; t < last; t += 5) {
82+
expect(container.innerHTML).toBe(from);
83+
await vi.advanceTimersByTimeAsync(5);
84+
flush();
85+
}
86+
expect(container.innerHTML).toBe(to);
87+
};
88+
await frames(before, section("a"));
89+
setKey("b");
90+
flush();
91+
await frames(section("a"), section("b"));
92+
dispose();
93+
});

0 commit comments

Comments
 (0)