-
-
Notifications
You must be signed in to change notification settings - Fork 196
chore(rsc/example): fallback to CSR on SSR error #973
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hi-ogawa
merged 10 commits into
main
from
11-11-chore_rsc_update_example_to_fallback_to_csr_on_ssr_error
Nov 12, 2025
+417
−75
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
efbaa6d
chore(rsc): update example to fallback to CSR on SSR error
hi-ogawa 0e0dd89
cleanup
hi-ogawa ef269bd
test: serve error (wip)
hi-ogawa 6a1ef8c
tweak
hi-ogawa b97626e
add noscript
hi-ogawa 274f640
handle ssr error status 500
hi-ogawa f781b53
test: add e2e
hi-ogawa 693a8de
chore(rsc): update starter, starter-cf-single, and ssg examples to fa…
hi-ogawa 46b460a
fix(rsc/ssg): fail build on SSR error during static generation
hi-ogawa 3b35902
fix(rsc): fix typo in error-boundary comment (handel -> handle)
hi-ogawa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
10 changes: 10 additions & 0 deletions
10
packages/plugin-rsc/examples/basic/src/routes/server-error/server.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export async function TestServerError(props: { url: URL }) { | ||
| if (props.url.searchParams.has('test-server-error')) { | ||
| throw new Error('test-server-error!') | ||
| } | ||
| return ( | ||
| <div> | ||
| <a href="?test-server-error">test-server-error</a> | ||
| </div> | ||
| ) | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,7 +10,7 @@ export async function renderHtml( | |||||||
| options?: { | ||||||||
| ssg?: boolean | ||||||||
| }, | ||||||||
| ) { | ||||||||
| ): Promise<{ stream: ReadableStream<Uint8Array>; status?: number }> { | ||||||||
| const [rscStream1, rscStream2] = rscStream.tee() | ||||||||
|
|
||||||||
| let payload: Promise<RscPayload> | ||||||||
|
|
@@ -23,18 +23,38 @@ export async function renderHtml( | |||||||
| await import.meta.viteRsc.loadBootstrapScriptContent('index') | ||||||||
|
|
||||||||
| let htmlStream: ReadableStream<Uint8Array> | ||||||||
| let status: number | undefined | ||||||||
| if (options?.ssg) { | ||||||||
| // for static site generation, let errors throw to fail the build | ||||||||
| const prerenderResult = await prerender(<SsrRoot />, { | ||||||||
| bootstrapScriptContent, | ||||||||
| }) | ||||||||
| htmlStream = prerenderResult.prelude | ||||||||
| } else { | ||||||||
| htmlStream = await renderToReadableStream(<SsrRoot />, { | ||||||||
| bootstrapScriptContent, | ||||||||
| }) | ||||||||
| // for regular SSR, catch errors and fallback to CSR | ||||||||
| try { | ||||||||
| htmlStream = await renderToReadableStream(<SsrRoot />, { | ||||||||
| bootstrapScriptContent, | ||||||||
| }) | ||||||||
| } catch (e) { | ||||||||
| // fallback to render an empty shell and run pure CSR on browser, | ||||||||
| // which can replay server component error and trigger error boundary. | ||||||||
|
||||||||
| // which can replay server component error and trigger error boundary. | |
| // which can replay server component error and trigger error boundary. | |
| console.error('SSR failed, falling back to CSR:', e) |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.