Skip to content

Commit cb804cf

Browse files
test(server): cover rejected SSR lazy() reaching Errored + add changeset (solidjs#2780)
Adds the regression test the PR was missing. The original attempt asserted the <Errored> fallback rendered into the server HTML, but in the streamed case (rejected lazy under a Loading boundary) the server only serializes the error at the boundary id and the client renders the fallback via the existing streamed-fragment hydration path. The test asserts the correct server-side behavior: the rejection is captured/serialized and the render completes instead of hanging on NotReadyError or leaking an unhandledRejection. Co-authored-by: Cursor <[email protected]>
1 parent ffae3af commit cb804cf

2 files changed

Lines changed: 36 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+
"solid-js": patch
3+
---
4+
5+
Fix rejected SSR `lazy()` so it reaches `<Errored>` instead of stack-overflowing or leaking an unhandled rejection (#2780). `lazy()` hand-rolls its own promise tracking and previously had no rejection handler, so a failed module load left `p.v` undefined forever (the render memo kept throwing `NotReadyError`, i.e. perpetual "loading") and the orphaned rejection escaped as a process-level `unhandledRejection`. The loader now captures the rejection on the lazy and surfaces it through the render memo, and `ctx.block` swallows its duplicate rejection branch — bringing `lazy()` to parity with async memos, whose rejections already propagate to error boundaries. Once the error reaches the boundary, the existing streamed-fragment hydration path renders the fallback as usual.

‎packages/solid-web/test/server/ssr-stream.spec.tsx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,37 @@ describe("SSR Streaming — Basic Rendering", () => {
266266
expect(html).not.toContain("tracking scope");
267267
});
268268

269+
test("rejected lazy() under Errored serializes the error instead of hanging (#2780)", async () => {
270+
const manifest = { "./Boom.tsx": { file: "assets/boom.js" } };
271+
const LazyBoom = lazy(
272+
() => new Promise<any>((_, rej) => setTimeout(() => rej(new Error("lazy failed")), 10)),
273+
"./Boom.tsx"
274+
) as any;
275+
276+
// Without the rejection capture in lazy(), the failed module load left the
277+
// render memo throwing NotReadyError forever (the stream never completes)
278+
// and leaked a process-level unhandledRejection. The render now completes,
279+
// and — because the boundary's region was already streamed (Loading
280+
// placeholder) — the error reaches `<Errored>` and is serialized at its id
281+
// for the client to render the fallback via the streamed-fragment path.
282+
const html = await renderComplete(
283+
() => (
284+
<Errored fallback={(e: any) => <span>err: {String(e()?.message || e())}</span>}>
285+
<Loading fallback={<span>Pending</span>}>
286+
<LazyBoom />
287+
</Loading>
288+
</Errored>
289+
),
290+
{ manifest }
291+
);
292+
const rKeys = [...html.matchAll(/_\$HY\.r\["([^"]+)"\]/g)].map(m => m[1]);
293+
// Error captured and serialized at the boundary id, the streamed fragment
294+
// settled (rejected), and the shell did not get stuck on the placeholder.
295+
expect(html).toContain("lazy failed");
296+
expect(rKeys).toContain("0");
297+
expect(rKeys).toContain("000_fr");
298+
});
299+
269300
test("async memo — shell contains fallback, final has resolved value", async () => {
270301
function App() {
271302
const data = createMemo(async () => {

0 commit comments

Comments
 (0)