Skip to content

Conversation

@hi-ogawa
Copy link
Contributor

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

Description

Part of #795

I just found the idea of returning server function result as promise on Next.js. This naturally propagates server function error as rejection, which can trigger error boundary on browser. https://github.com/hi-ogawa/reproductions/tree/main/next-error


Hmm, this isn't entirely better since it now returns http status 200 on such action response. Next.js actually keeps 500 somehow. For example, for production server logging / monitoring, indicating server response error code is probably essential.

Okay, so we still need to await to reflect the status code https://github.com/vercel/next.js/blob/28a14da5010ad3147a06abbabc99a119d009f733/packages/next/src/server/app-render/action-handler.ts#L1124-L1125


TODO:

  • e2e in basic
    • full error on dev
    • status
  • update all examples
  • add root error boundary
  • compare with Waku

@hi-ogawa hi-ogawa requested a review from Copilot November 11, 2025 06:18
Copilot finished reviewing on behalf of hi-ogawa November 11, 2025 06:19
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 error handling for server functions using React error boundaries, allowing server-side errors to naturally propagate to the client and trigger error boundaries. This is based on the Next.js pattern where server function results are returned as promises, enabling rejections to be caught by error boundaries.

Key changes:

  • Server action return values are now returned as promises without awaiting, allowing rejections to propagate to the client
  • Added an ErrorBoundary component to catch and display server function errors
  • Wrapped the App component with ErrorBoundary in the root

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
packages/plugin-rsc/examples/starter/src/framework/entry.rsc.tsx Modified to return server action results as promises without awaiting, enabling error propagation to client-side error boundaries
packages/plugin-rsc/examples/starter/src/client.tsx Added ErrorBoundary class component to catch and display errors with a reset button
packages/plugin-rsc/examples/starter/src/root.tsx Wrapped the App component with ErrorBoundary to enable error catching

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

@hi-ogawa hi-ogawa force-pushed the 11-11-chore_rsc_server_function_error_handling_example branch from 1711122 to c4b90f5 Compare November 11, 2025 07:45
@hi-ogawa hi-ogawa marked this pull request as ready for review November 11, 2025 08:13
@hi-ogawa hi-ogawa merged commit 67427fc into main Nov 11, 2025
21 checks passed
@hi-ogawa hi-ogawa deleted the 11-11-chore_rsc_server_function_error_handling_example branch November 11, 2025 09:49
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