Error component rendered 2 times when server rendering in production
See original GitHub issueExpected Behavior
1 error component is rendered
Current Behavior
2 error components are rendered below eachother. 1 through SSR and 1 through client side rendering.
Steps to Reproduce (for bugs)
import Link from 'next/link'
export default class extends React.Component {
static async getInitialProps() {
// Just throw an error in getInitialProps
throw new Error('test');
}
render() {
return (
<div>
<h1>Hello world</h1>
</div>
)
}
}
Context
Issue can be seen here: https://create-next-example-app-olyuogqcxe.now.sh/ (deployment with the above code). Scroll down cause the component itself is screen filling 😅
@harshmaur surfaced this.
Your Environment
Tech | Version |
---|---|
next | 2.x+ (so beta too) |
mode | production |
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Why is my React component is rendering twice?
It's not a bug. Indeed the very reason they do the extra render is to "catch bugs" in development. (The extra render won't...
Read more >React Components rendered twice — any way to fix this?
Many developer have implemented a similar functional component and have seen this behavior. Some have even opened a bug report in the official...
Read more >Error component rendered 2 times when server ... - GitHub
2 error components are rendered below eachother. 1 through SSR and 1 through client side rendering. Steps to Reproduce (for bugs). import Link ......
Read more >My React components render twice and drive me crazy
The double-rendering behaviour is definitely not reproducible in production as we see despite the fact that we had exactly the same setup by ......
Read more >Solved Why React Component (useEffect) is rendering twice??
Why is useEffect running twice ? This is due to StrictMode most likely in your root tree. What is strict mode?StrictMode...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I believe this was introduced in https://github.com/zeit/next.js/pull/1800
And the problem code is here: https://github.com/zeit/next.js/blob/v3-beta/server/render.js#L114
If there is an error on the server, it’s sent to the client through the
err
prop, which is what the client is using to determine whether it should render the error page: https://github.com/zeit/next.js/blob/master/client/index.js#L96So it seems like any uncaught exception will render both server & client error pages. I’m not sure what the correct behavior for this should be, but one solution I could think of would be to add
.ignore
to the error object created server-side.This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.