Skip to content

Commit 736bb5c

Browse files
committed
fix(signals): outer error boundary recovers after an inner fallback's rethrow (#4270)
An outer boundary catching an error rethrown from an inner fallback waits on that fallback's computed. The inner content recovering disposes it in the render phase, after the seam that would have dropped it ran, so the outer kept its fallback until a later flush. Schedule another round when an errored fallback is disposed so the seam drops it and redraws. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent d786bcf commit 736bb5c

3 files changed

Lines changed: 71 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+
An error boundary that caught an error rethrown from an inner boundary's fallback now recovers when the inner content does: switching the inner boundary back to its content disposes the fallback that threw, and the outer boundary now drops that error and shows its content again in the same flush, instead of keeping its fallback until some later error re-rendered it (#4270).

‎packages/signals/src/boundaries.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ function createBoundary<T>(
702702
if (fb !== null)
703703
globalQueue.enqueue(EFFECT_RENDER, () => {
704704
if (!b._fallback && b._fb === fb) {
705+
// A fallback that threw (a rethrow the boundary does not
706+
// handle) is what an enclosing boundary waits on: it died, and
707+
// the seam of another round drops it there (#4270).
708+
if (fb._statusFlags & STATUS_ERROR) schedule();
705709
dispose(fb);
706710
b._fb = null;
707711
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// #4270: an error rethrown from an inner boundary's fallback is caught by the
2+
// outer boundary, whose source is the inner fallback's computed. The inner
3+
// content recovering disposes that computed; the outer must recover with it.
4+
import {
5+
createErrorBoundary,
6+
createMemo,
7+
createRenderEffect,
8+
createRoot,
9+
createSignal,
10+
flush,
11+
untrack
12+
} from "../src/index.js";
13+
14+
class NotFound extends Error {}
15+
class Other extends Error {}
16+
17+
it.each([false, true])(
18+
"an outer boundary recovers when the inner fallback that rethrew is replaced by content (nested: %s)",
19+
nested => {
20+
const [which, setWhich] = createSignal(0);
21+
let screen = "";
22+
createRoot(() => {
23+
const m = createMemo(() => {
24+
const w = which();
25+
if (w === 1) throw new NotFound("nf");
26+
if (w === 2) throw new Other("other");
27+
return "ok" + w;
28+
});
29+
const makeInner = () =>
30+
createErrorBoundary(
31+
() => m(),
32+
err => {
33+
const e = err();
34+
if (!(e instanceof NotFound)) throw e;
35+
return "inner:" + e.message;
36+
}
37+
);
38+
const inner = nested ? null : untrack(makeInner);
39+
const outer = untrack(() =>
40+
createErrorBoundary(
41+
nested ? makeInner : () => inner!(),
42+
err => "outer:" + (err() as Error).message
43+
)
44+
);
45+
createRenderEffect(
46+
() => outer(),
47+
v => {
48+
screen = v;
49+
}
50+
);
51+
});
52+
const seen: string[] = [];
53+
flush();
54+
seen.push(screen);
55+
for (const w of [1, 0, 2, 0, 1, 0]) {
56+
setWhich(w);
57+
flush();
58+
seen.push(screen);
59+
}
60+
expect(seen).toEqual(["ok0", "inner:nf", "ok0", "outer:other", "ok0", "inner:nf", "ok0"]);
61+
}
62+
);

0 commit comments

Comments
 (0)