- 
                Notifications
    You must be signed in to change notification settings 
- Fork 29.7k
Description
Bug report
Describe the bug
Error.getInitialProps is not called when an exception is thrown at the top level of a page while it is being loaded. This is problematic because getInitialProps would have provided access to the Error object. I want the Error so that I can log it and potentially display it to the user in render().
To Reproduce
I've created a minimal reproduction here: https://github.com/WestonThayer/bug-nextjs-error-getinitialprops
Expected behavior
The Error that was thrown should be made available to _error.js. I would expect to receive it via getInitialProps, but I supposed having it as a prop passed in to render would work too.
Additional context
I think this was introduced by #4764, specifically the lines that use the props from the server. I can see how that makes sense if the Error was thrown on the server side and _error.js's getInitialProps ran on the server, but it doesn't account for code that works fine on the server, but throws on the client.
As a workaround, the exception is passed as a prop to App, so I'm simply passing it on:
class MyApp extends App {
  render() {
    const { Component, pageProps, err } = this.props;
    return <Component {...pageProps} err={err} />;
  }
}