Skip to content

Commit 2c2a912

Browse files
committed
test(solid): hydrated error boundary holds the client's own error (#4273)
When the content's run at hydration end throws, the boundary holds that client error: the fallback receives it and reset() clears it. The serialized server error only directs hydration to claim the fallback. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_015hPxMkC3jg3Uivh65gvaf2
1 parent de1dd31 commit 2c2a912

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎.changeset/errored-hydrated-recovery-4273.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"solid-js": patch
33
---
44

5-
An `<Errored>` boundary hydrated in the error state the server rendered now recovers. Before, it showed the server's error and tracked nothing, so it stayed on the fallback until `reset()` was called, even after the failed content's inputs changed. Now the content runs once on the client when hydration ends. If it fails again, the fallback the server rendered stays and the boundary recovers when the content's inputs change. If the error only happened on the server, the client's content replaces the fallback after hydration (#4273).
5+
An `<Errored>` boundary hydrated in the error state the server rendered now recovers. Before, it showed the server's error and tracked nothing, so it stayed on the fallback until `reset()` was called, even after the failed content's inputs changed. Now the content runs once on the client when hydration ends. If it fails again, the fallback stays, now showing the client's own error, and the boundary recovers when the content's inputs change or on `reset()`; the server's error only tells hydration to claim the fallback markup. If the error only happened on the server, the client's content replaces the fallback after hydration (#4273).

‎packages/solid/test/client-hydration.spec.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,47 @@ describe("Error Boundary Hydration", () => {
178178
expect(read()).toBe("item 3");
179179
});
180180

181+
test("createErrorBoundary hydrated from a server error holds the client's own error once hydration ends (#4273)", () => {
182+
startHydration({ t0: new Error("server error") });
183+
184+
let fails = true;
185+
const seen: unknown[] = [];
186+
let read!: () => unknown;
187+
let resetFn!: () => void;
188+
createRoot(
189+
() => {
190+
read = createErrorBoundary(
191+
() => {
192+
if (fails) throw new Error("client error");
193+
return "recovered";
194+
},
195+
(err: any, reset) => {
196+
resetFn = reset;
197+
seen.push(err());
198+
return `fallback: ${err().message}`;
199+
}
200+
);
201+
read();
202+
},
203+
{ id: "t" }
204+
);
205+
flush();
206+
expect(read()).toBe("fallback: server error");
207+
208+
// At hydration end the content's own run throws: the boundary holds the
209+
// client error, and the fallback receives it.
210+
stopHydration();
211+
flush();
212+
expect(read()).toBe("fallback: client error");
213+
expect((seen[seen.length - 1] as Error).message).toBe("client error");
214+
215+
// reset() clears the client error.
216+
fails = false;
217+
resetFn();
218+
flush();
219+
expect(read()).toBe("recovered");
220+
});
221+
181222
test("createErrorBoundary handles non-Error serialized values", () => {
182223
// Server might serialize a string or other value as the error
183224
startHydration({ t0: "string error" });

0 commit comments

Comments
 (0)