Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

@hi-ogawa hi-ogawa commented Nov 11, 2025

Description

Part of #795. Similar idea as wakujs/waku#1752

TODO

  • http status
  • no js server action error
  • test
  • update other examples

@hi-ogawa hi-ogawa changed the title chore(rsc): example - fallback to CSR on SSR error chore(rsc/example): fallback to CSR on SSR error Nov 11, 2025
@hi-ogawa hi-ogawa force-pushed the 11-11-chore_rsc_update_example_to_fallback_to_csr_on_ssr_error branch from 7fe3922 to efbaa6d Compare November 11, 2025 09:51
@hi-ogawa hi-ogawa force-pushed the 11-11-chore_rsc_update_example_to_fallback_to_csr_on_ssr_error branch from 331ac90 to ef269bd Compare November 11, 2025 10:03
@hi-ogawa hi-ogawa marked this pull request as ready for review November 12, 2025 02:58
hi-ogawa and others added 2 commits November 12, 2025 12:10
…llback to CSR on SSR error

Apply the same SSR error handling pattern from the basic example to the remaining examples that use SSR (starter, starter-cf-single, and ssg). When SSR fails, these examples now return a 500 status with a minimal HTML shell and trigger pure CSR on the browser, which replays the error and shows the error boundary.

Also adds missing GlobalErrorBoundary to starter-cf-single and ssg examples.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
For the SSG example, when rendering fails during static site generation (options.ssg=true), the build should fail rather than generating a fallback CSR shell. The try-catch error handling is now only applied for regular SSR at request time.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@hi-ogawa hi-ogawa requested a review from Copilot November 12, 2025 03:24
Copilot finished reviewing on behalf of hi-ogawa November 12, 2025 03:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a fallback mechanism to gracefully handle SSR errors by falling back to Client-Side Rendering (CSR) when Server-Side Rendering fails. The changes ensure that when SSR encounters an error, the server returns a minimal HTML shell with a 500 status code, allowing the client to replay the error and trigger error boundaries for proper error handling.

  • Wraps SSR rendering in try-catch blocks to catch and handle errors
  • Returns an object with both stream and status code from renderHTML functions
  • Adds proper error handling for form-based server actions with explicit 500 responses
  • Implements CSR fallback using __NO_HYDRATE flag and createRoot instead of hydrateRoot

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
packages/plugin-rsc/examples/starter/src/framework/entry.ssr.tsx Adds try-catch wrapper for SSR rendering and returns status code along with stream
packages/plugin-rsc/examples/starter/src/framework/entry.rsc.tsx Updates to handle new SSR result format and adds error handling for server actions with proper status codes
packages/plugin-rsc/examples/starter/src/framework/entry.browser.tsx Implements CSR fallback logic by checking for __NO_HYDRATE flag and using createRoot when SSR failed
packages/plugin-rsc/examples/starter-cf-single/src/framework/error-boundary.tsx Adds new global error boundary component for catching and displaying errors
packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.ssr.tsx Same SSR error handling as starter example
packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.rsc.tsx Same RSC handling as starter example
packages/plugin-rsc/examples/starter-cf-single/src/framework/entry.browser.tsx Adds error boundary wrapper and CSR fallback logic
packages/plugin-rsc/examples/ssg/src/framework/error-boundary.tsx Adds new global error boundary component for SSG example
packages/plugin-rsc/examples/ssg/src/framework/entry.ssr.tsx Adds SSR error handling with special case for SSG builds to let errors throw
packages/plugin-rsc/examples/ssg/src/framework/entry.rsc.tsx Updates to handle new SSR result format
packages/plugin-rsc/examples/ssg/src/framework/entry.browser.tsx Adds error boundary wrapper and CSR fallback logic
packages/plugin-rsc/examples/basic/src/routes/server-error/server.tsx Adds new test component for triggering server errors
packages/plugin-rsc/examples/basic/src/routes/root.tsx Integrates the new test server error component
packages/plugin-rsc/examples/basic/src/framework/error-boundary.tsx Updates error page styling to match Next.js conventions
packages/plugin-rsc/examples/basic/src/framework/entry.ssr.tsx Same SSR error handling as starter example
packages/plugin-rsc/examples/basic/src/framework/entry.rsc.tsx Same RSC handling as starter example with server action error handling
packages/plugin-rsc/examples/basic/src/framework/entry.browser.tsx Implements CSR fallback logic
packages/plugin-rsc/e2e/basic.test.ts Adds tests for server component error handling and updates error message assertions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hi-ogawa hi-ogawa merged commit 120c145 into main Nov 12, 2025
19 of 20 checks passed
@hi-ogawa hi-ogawa deleted the 11-11-chore_rsc_update_example_to_fallback_to_csr_on_ssr_error branch November 12, 2025 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants