Skip to content

Commit 1b32ff2

Browse files
ryansolidclaude
andauthored
fix(signals): a frame node re-run outside its hold re-derives the readers of the staging it replaces (#4378) (#4390)
* fix(signals): a frame node re-run outside its hold re-derives the readers of the staging it replaces (#4378) A reader recreated in the flush that clears an upstream error, under Errored > Loading, waits on the async memo's flight, so the frame holds and the error boundary's output stages its content with it. The rejection then re-runs the output outside that transaction's flush: it publishes mainline (#3404), back to the fallback it had committed. That is no change, so nothing re-derived its reader, and the landing applied the reader's held run of the superseded content: an empty hole with nothing in flight. The mainline re-pass now marks its subscribers when it supersedes a staging, so readers of that staging re-derive on the value it publishes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): ledger for #4378 (+16 B minified) Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): ledger for #4378 (+16 B minified), over next @ 40cde2c Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): move the #4378 re-derive into the boundary's redraw so the floors don't pay The insertSubs in recompute's mainline-publish arm cost +16 B minified on every scenario, the frozen floors and hello world included. The case is a boundary's output: a redraw re-derives it outside the hold that staged its content, and it publishes the committed fallback back unchanged. The redraw now marks the output's readers when the output carries a staging, so they re-derive with it. boundaries.ts is tree-shaken from builds without a boundary. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore: describe the #4378 redraw fix in the changeset Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): gate the #4378 re-derive on the held output, not its staging Reading _pendingValue in boundaries.js moved the shared mangled names and every floor with them. CONFIG_HELD on _config, which boundaries.js reads already, marks the same staging. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): ledger for #4378 (boundary scenarios only), over next @ 40cde2c Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * fix(signals): back to recompute's arm for the #4378 re-derive Every frame node up the chain (the boundaries' trees and outputs) drops its staging there, most of them re-run from the heap rather than through redraw, so the generator's E8 case still failed with the redraw version. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * test(web): pin the generator's E8 case for #4378 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * chore(size): ledger for #4378 (+16 B minified), over next @ b68942c Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2 * Re-record #4390's size ledger over next @ 178605c 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 178605c commit 1b32ff2

5 files changed

Lines changed: 229 additions & 6 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 reader created in the flush that clears an upstream error, under `<Errored>` and `<Loading>`, now shows the async memo's error once it rejects, instead of an empty hole. The rejection re-ran the error boundary outside the hold that had staged its content, and the boundary went back to the fallback it had already committed. Because that was no change, the boundary's reader did not re-run, and the hold's landing applied its stale run of the content. A held frame node that re-runs outside its hold now re-derives the readers of the staging it replaces (#4378).

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@ export function recompute(el: Computed<any>, create: boolean = false): void {
424424
// children die below (`disposeChildren`). The landing re-derives a
425425
// fresh held frame for the reveal (`_reruns`).
426426
// Not held any more, whichever frame reader it is: its readers read
427-
// the value this pass publishes.
427+
// the value this pass publishes — those that read the staging it
428+
// supersedes re-derive, even when it publishes the committed value
429+
// back (no change to notify them by): their held runs carry the
430+
// superseded frame, and the landing would apply them (#4378).
431+
if (el._pendingValue !== NOT_PENDING) insertSubs(el);
428432
el._pendingValue = NOT_PENDING;
429433
el._config &= ~CONFIG_HELD;
430434
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* #4378: a reader created in the flush that clears an upstream error, under
3+
* `Errored > Loading > Show keyed`, ends with the async memo's error, as the
4+
* reader that was not recreated does. The new reader waits on `m1`'s flight,
5+
* so the frame holds and the boundary's output stages its content with it.
6+
* The rejection then re-derives the output outside that transaction's flush:
7+
* it publishes mainline (#3404), back to the fallback it had committed — an
8+
* unchanged value, so nothing re-derived its reader, and the landing applied
9+
* the reader's held run of the superseded content: an empty hole.
10+
*/
11+
import { describe, expect, it } from "vitest";
12+
import {
13+
createErrorBoundary,
14+
createLoadingBoundary,
15+
createMemo,
16+
createRenderEffect,
17+
createRoot,
18+
createSignal,
19+
flush,
20+
latest
21+
} from "../src/index.js";
22+
23+
const tick = async () => {
24+
for (let i = 0; i < 5; i++) await Promise.resolve();
25+
await new Promise(r => setTimeout(r, 0));
26+
flush();
27+
};
28+
29+
describe("a reader born in the flush that clears an upstream error (#4378)", () => {
30+
for (const recreate of [false, true])
31+
it(recreate ? "recreated in that flush" : "kept", async () => {
32+
const requests: Array<() => void> = [];
33+
const fetchM1 = (x: number) =>
34+
new Promise<number>((res, rej) =>
35+
requests.push(() => (x % 4 === 0 ? rej(new Error("m1:" + x)) : res(x)))
36+
);
37+
const [s, setS] = createSignal(3);
38+
const [epoch, setEpoch] = createSignal(1);
39+
let slot: unknown = "";
40+
let screen: unknown;
41+
createRoot(() => {
42+
const m0 = createMemo(() => {
43+
const v = 1 + latest(s);
44+
if (v % 4 === 0) throw new Error("m0"); // throws at s = 3
45+
return v;
46+
});
47+
const m1 = createMemo(() => fetchM1(1 + m0())); // at s = 2 asks for 4: rejects
48+
// <Errored fallback="[ERR]"><Loading fallback="[LOAD]">
49+
// <Show when={epoch()} keyed><span>{m1()}</span></Show>
50+
// </Loading></Errored>
51+
const out = createErrorBoundary(
52+
() =>
53+
createLoadingBoundary(
54+
() =>
55+
createMemo(() => {
56+
epoch();
57+
createRenderEffect(m1, v => void (slot = v));
58+
return "span";
59+
}),
60+
() => "[LOAD]"
61+
),
62+
() => "[ERR]"
63+
);
64+
createRenderEffect(
65+
() => {
66+
let v: unknown = out();
67+
while (typeof v === "function") v = v();
68+
return v;
69+
},
70+
v => void (screen = v)
71+
);
72+
});
73+
flush();
74+
await tick();
75+
expect(screen).toBe("[ERR]");
76+
setS(2);
77+
if (recreate) setEpoch(2);
78+
flush();
79+
for (let i = 0; i < 5; i++) {
80+
while (requests.length) requests.shift()!();
81+
await tick();
82+
}
83+
expect([screen, slot]).toEqual(["[ERR]", ""]);
84+
});
85+
});
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* @jsxImportSource @solidjs/web
3+
* @vitest-environment jsdom
4+
*/
5+
// #4378 (async-app generator, pair E8): a reader recreated in the flush that
6+
// clears an upstream error ends with the async memo's error, as the reader
7+
// that was not recreated does — not an empty hole. The signals-side pin is
8+
// `packages/signals/tests/recreated-reader-held-boundary-4378.test.ts`.
9+
import { describe, expect, test } from "vitest";
10+
import { createMemo, createSignal, Errored, flush, latest, Loading, Show } from "solid-js";
11+
import { render } from "../src/index.js";
12+
import { runScenario } from "./async-gen/run.js";
13+
import type { Scenario } from "./async-gen/scenario.js";
14+
15+
const tick = async () => {
16+
for (let i = 0; i < 5; i++) await Promise.resolve();
17+
await new Promise(r => setTimeout(r, 0));
18+
flush();
19+
};
20+
21+
describe("a reader born in the flush that clears an upstream error (#4378)", () => {
22+
for (const recreate of [false, true])
23+
test(recreate ? "recreated in that flush" : "kept", async () => {
24+
const requests: Array<() => void> = [];
25+
const fetchM1 = (x: number) =>
26+
new Promise<number>((res, rej) =>
27+
requests.push(() => (x % 4 === 0 ? rej(new Error("m1:" + x)) : res(x)))
28+
);
29+
const div = document.createElement("div");
30+
let setS!: (v: number) => void, setEpoch!: (v: number) => void;
31+
const dispose = render(() => {
32+
const [s, _setS] = createSignal(3);
33+
setS = _setS;
34+
const m0 = createMemo(() => {
35+
const v = 1 + latest(s);
36+
if (v % 4 === 0) throw new Error("m0");
37+
return v;
38+
});
39+
const m1 = createMemo(() => fetchM1(1 + m0()));
40+
const [epoch, _setEpoch] = createSignal(1);
41+
setEpoch = _setEpoch;
42+
return (
43+
<Errored fallback={() => "[ERR]"}>
44+
<Loading fallback="[LOAD]">
45+
<Show when={epoch()} keyed>
46+
<span>{m1()}</span>
47+
</Show>
48+
</Loading>
49+
</Errored>
50+
);
51+
}, div);
52+
flush();
53+
await tick();
54+
expect(div.innerHTML).toBe("[ERR]");
55+
setS(2);
56+
if (recreate) setEpoch(2);
57+
flush();
58+
for (let i = 0; i < 5; i++) {
59+
while (requests.length) requests.shift()!();
60+
await tick();
61+
}
62+
expect(div.innerHTML).toBe("[ERR]");
63+
dispose();
64+
});
65+
});
66+
67+
// The generator's E8 case at next @ 40cde2cd: the staging the hold built is
68+
// superseded at every frame node up the chain (the inner Errored, the root
69+
// Loading and Errored), each re-run from the heap outside its hold and back
70+
// to its committed fallback.
71+
test("the generator's E8 case: recreated readers under nested boundaries (#4378)", async () => {
72+
const sc: Scenario = {
73+
signals: [2, 3],
74+
memos: [
75+
{ async: false, deps: [{ src: { k: "s", i: 1 }, how: "latest" }], poison: 0 },
76+
{ async: true, deps: [{ src: { k: "m", i: 0 }, how: "plain" }], poison: 0 }
77+
],
78+
tree: {
79+
t: "errored",
80+
child: {
81+
t: "leaf",
82+
text: [],
83+
attrs: [
84+
{ how: "plain", src: { k: "s", i: 1 } },
85+
{ how: "plain", src: { k: "m", i: 1 } }
86+
],
87+
grouped: false
88+
}
89+
},
90+
steps: [
91+
{ t: "settle", pick: 0 },
92+
{ t: "task" },
93+
{ t: "action", s: 1, v: 0 },
94+
{ t: "write", s: 1, v: 1 },
95+
{ t: "flush" },
96+
{ t: "action", s: 1, v: 0 },
97+
{ t: "write", s: 1, v: 2 },
98+
{ t: "settle", pick: 3 }
99+
]
100+
} as Scenario;
101+
const kept = await runScenario(sc);
102+
const recreated = await runScenario(sc, { remount: true });
103+
// Where nothing is in flight (the last step settles the last request).
104+
expect(recreated.screens.at(-1)).toBe("[E]");
105+
expect(recreated.final).toBe(kept.final);
106+
expect(recreated.final).toBe("[E]");
107+
});

0 commit comments

Comments
 (0)