close
The Wayback Machine - https://web.archive.org/web/20201101054205/https://github.com/vercel/next.js/issues/7578
Skip to content
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

Entire app remounts on error #7578

Open
exogen opened this issue Jun 14, 2019 · 1 comment
Open

Entire app remounts on error #7578

exogen opened this issue Jun 14, 2019 · 1 comment

Comments

@exogen
Copy link
Contributor

@exogen exogen commented Jun 14, 2019

Bug report

Describe the bug

I'm not sure if this is intentional or not, but it seems undesirable at least. This is in production mode.

When an error occurs during rendering, triggering Next.js’ error boundary, the entire <App> component remounts. This is counter to what I think the developer’s expectation is, which is that <App> is only mounted once and remains mounted for the entire duration.

I can't think of a good reason this would be intentional. It seems more likely that the tree above <App> changes in some incidental way, such that React can no longer update the existing element instances but remounts them instead. For example:

<SomeContainer>                 <OtherContainer>
  <App>                           <App>
    <Page />   -- on error -->      <Page />
  </App>                          </App>
</SomeContainer>                </OtherContainer>

or:

                              <ErrorContainer>
<App>                           <App>  
  <Page />   -- on error -->      <Page />
</App>                          </App>
                              </ErrorContainer>

The downside is that code people expected to mount only once (potentially expensive initialization, recreating things that don't need to be recreated, etc.) can happen multiple times.

To Reproduce

This repo demonstrates the issue: https://github.com/exogen/next-error-remount

Clicking the button will logs what is being unmounted.

Expected behavior

Transition to the error state should be just like transitioning pages: the <Page> should unmount and the <Error> should mount, but the <App> should remain mounted.

System information

  • Version of Next.js: 8.0.4, 8.1.0, canary
@mmmeff
Copy link

@mmmeff mmmeff commented Feb 27, 2020

I'm getting the same scenario in Next 9 at the moment while using a custom _app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.