question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error component rendered 2 times when server rendering in production

See original GitHub issue

Expected 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:closed
  • Created 6 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
kochiscommented, Sep 26, 2017

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#L96

So 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.

0reactions
lock[bot]commented, May 10, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found