-
Notifications
You must be signed in to change notification settings - Fork 27.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_app getInitialProps not called when rendering error page #4574
Comments
Created a pull request: seanconnollydev/next-error-page-props#1
|
@timneutkens I appreciate the PR, but your changes do not fix the issue. I believe the root of this issue is that This may be intentional given this block of code: https://github.com/zeit/next.js/blob/86d01706a67cee5c80796974d04c1e11cdff453a/client/index.js#L173 So is that your expectation? When rendering the error page, we should not expect |
That specific case you're mentioning is an edge case in development where the following events happen:
So for normal pages the following happens:
There is no case where However, after fixing your example (the HOC) it seemed to work fine for me. |
@timneutkens Just to clarify, when you say it worked fine, were you able to see the correct message after running
but if what you say is true, I should see this:
|
I actually checked against the 404 page. |
I can confirm this issue, and I've dug in pretty deeply. I'm going to restate some things here from the initial issue description to help clarify and isolate the problematic code. What's wrongThis 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 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 @goldenshun's original repro illustrates this nicely, though the use of a HOC is unnecessary. Why is it brokenThis regression was introduced two months ago in #4156, where the invocation of I believe the sentiment about " How to fixI'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 |
Here's the fix that has been working for me: jamesreggio@e19ec0d It causes a regression in a test, though. |
I fixed the regression and opened a PR here: #4764. |
Bug report
Describe the bug
When the error page is rendered (either custom _error page or the default), the
_app
getInitialProps
function is not called. As a result any rendering that expects props to be present behaves unexpectedly. This can be especially problematic in scenarios where_app
is wrapped by higher order components (as demonstrated in the Apollo example)To Reproduce
Repo (with steps to reproduce in Readme): https://github.com/goldenshun/next-error-page-props
Live Example: https://next-error-page-props-krqkeinaul.now.sh/
Expected behavior
I expect initial props for the
_app
to be be hydrated when rendering the error page.Screenshots
System information
Additional context
This unexpected behavior caused a bug for us where attempts to render the error page resulted in a subsequent error because the expectation was that the props passed via
getInitialProps
would be present. We have several higher order components wrapping our_app
component, so we needed to add special error checking logic just for the scenario when the error page was being rendered.The text was updated successfully, but these errors were encountered: