DX flaw: An error occurred in the Server Components render #66999
Replies: 4 comments 2 replies
-
Beta Was this translation helpful? Give feedback.
-
It's even confusing in the Next.js tutorials: "Seeing these errors are helpful while developing as you can catch any potential problems early." They are not helpful because now devs don't realise the error message they think they're throwing won't displayed in production. But will only work for them while developing. |
Beta Was this translation helpful? Give feedback.
-
Potential solution: |
Beta Was this translation helpful? Give feedback.
-
Hi, is there a solution for this that works with react-query |
Beta Was this translation helpful? Give feedback.
-
There's a major flaw in how errors for server actions are handled. They work differently in dev and in prod.
In dev: throwing an error in a server action exposes the error that occurred.
In prod: the message isn't exposed to the client. Instead you see: "An error occurred in the Server Components render"
The Next.js team's reasoning for this design choice is to make it easier for devs to see errors when working on their app.
The problem is that it actually makes it harder, because you only notice errors come up when running in production, and not immediately in development.
This has happened to my users. This has happened to me as a user on other sites too. Even well funded dev teams are making this mistake.
The fix:
Make prod and dev consistent. Or at the very least, add a message to the start of the error message that is exposed to the client that this will only show in dev. eg. "This only shows in Next.js development. You should not use this field in production. Error: ..."
Beta Was this translation helpful? Give feedback.
All reactions