-
-
Notifications
You must be signed in to change notification settings - Fork 197
chore(rsc): server function error handling example #971
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
chore(rsc): server function error handling example #971
Conversation
There was a problem hiding this 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.
1711122 to
c4b90f5
Compare
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: