fix(server): handle rejection in lazy() so it reaches Errored (closes #2780)#2781
Open
tsushanth wants to merge 1 commit into
Open
fix(server): handle rejection in lazy() so it reaches Errored (closes #2780)#2781tsushanth wants to merge 1 commit into
tsushanth wants to merge 1 commit into
Conversation
…olidjs#2780) `load()` registered a single `p.then(mod => p.v = mod.default)`. When the lazy import rejects, there's no second argument, so the rejection falls through as a process-level `unhandledRejection` and `p.v` stays `undefined` forever — the memo body keeps throwing `NotReadyError` and SSR treats the module as still loading instead of converting the rejection into a regular error that `<Errored>` can catch. Add a rejection branch that stores the error on `p.error`, then surface it from the memo via `if (p.error) throw p.error` ahead of the `!p.v` NotReadyError check. Mirror the change on the `ctx.block(p.then(...))` call site so it doesn't propagate its own unhandled rejection alongside the one captured for the render path.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2780.
lazy()server impl (packages/solid/src/server/component.ts:79+) registersp.then(mod => p.v = mod.default)with no rejection branch. When the lazy import rejects:p.vstaysundefined, so the memo body keeps throwingNotReadyErrorand SSR thinks the module is still loading.unhandledRejection.RangeError: Maximum call stack size exceededin the serialized output (per reporter) — but the real bug, as the reporter points out, is that the rejection never reaches<Errored>.Fix:
.thenargument onload()'sp.then(...)and store the error onp.error.if (p.error) throw p.errorahead of theNotReadyErrorcheck, so the throw lands in the surrounding<Errored>instead of looping the loading state.ctx.block(p.then(...))callsite so it doesn't propagate its own unhandled rejection alongside the one we capture for the render path.The diagnosis in the issue body (
p.then(mod => p.v = mod.default)with no rejection handler) maps 1:1 to the patch — same place, same shape.Test plan
Tried adding a regression test under
SSR Streaming — Error Handlinginpackages/solid-web/test/server/ssr-stream.spec.tsx:It produced only the SSR hydration script tags rather than the
<Errored>fallback — I suspect the streaming machinery doesn't re-pull the memo body afterctx.blocksettles in the rejection case, or the lazy-with-manifest test path needs a different harness (the existinglazy() with no manifest throwstests preload viaawait LazyHome.preload!()before rendering, so they never exercise the rejection-on-render path). Rather than ship a flaky/false-negative test, I dropped it from the diff and left the source fix self-contained — it's a small mechanical change you can sanity-check directly. Happy to follow up with a working test once a maintainer points at the right harness shape, or once #2779 surfaces a similar Promise-on-render path that I can borrow.Written by an agent (Claude Code, claude-opus-4-7).