rsnext/test/integration
James Reggio 4cc691c0b8 Fix #4574: getInitialProps is not called on _error page for client-side errors (#4764)
## What's wrong

This problem is specific to errors that happen on the client _after_ the initial mounting of the component. (The router has special logic to handle exceptions thrown in `getInitialProps` during a client-side navigation, and I've confirmed this logic is correct.)

Specifically, if the page is mounted, and you raise an exception on the page, the exception will cause  the error page to be mounted without ever invoking `getInitialProps` on the new App/Error page pairing.

This has been illustrated with multiple repros in #4574.

## Why is it broken

This regression was introduced two months ago in #4156, where the invocation of `getInitialProps` was removed from the app's top-level error handler. Specifically, [this line](https://github.com/zeit/next.js/pull/4156/files#diff-895656aeaccff5d7c0f56a113ede9662L147) was removed and [replaced by a comment](https://github.com/zeit/next.js/pull/4156/files#diff-895656aeaccff5d7c0f56a113ede9662R167) that says that "`App` will handle the calling of `getInitialProps`".

I believe the sentiment about "`App` will handle calling `getInitialProps`" is mistaken. In fact, it really doesn't make sense on its face, since it would require an instance lifecycle method of `App` (which is mounted immediately after the comment) to invoke the `static getInitialProps` method on the error page.

## How I fixed it

I've fixed this in a fork by restoring Lines 146 – 148 that were removed in #4156. I think this is the right fix, but Next.js's handling of `getInitialProps` could certainly be improved. (The code in [this conditional](86d01706a6/client/index.js (L173)) speaks to the unnecessary complexity around this.)
2018-07-11 23:58:42 +02:00
..
app-aspath Fix Typescript HMR (#4689) 2018-06-28 20:07:41 +02:00
app-document Use nonce attribute for all scripts and preloads if provided (#4539) 2018-06-28 20:16:30 +02:00
babel Fix Typescript HMR (#4689) 2018-06-28 20:07:41 +02:00
basic Make sure hashchanges get triggered (#4676) 2018-06-28 20:56:18 +02:00
config Fix Typescript HMR (#4689) 2018-06-28 20:07:41 +02:00
custom-server Upgrade standard.js (#4064) 2018-03-27 20:11:03 +02:00
dist-dir Clean up references to this.dir and this.dist everywhere (#4535) 2018-06-04 15:45:39 +02:00
ondemand Merge branch 'master' into fix/canary 2018-01-13 06:33:19 +01:00
page-extensions Fix Typescript HMR (#4689) 2018-06-28 20:07:41 +02:00
production Fix #4574: getInitialProps is not called on _error page for client-side errors (#4764) 2018-07-11 23:58:42 +02:00
static Support events emitter for router (#4726) 2018-07-05 14:41:18 +02:00
with-router Support events emitter for router (#4726) 2018-07-05 14:41:18 +02:00