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

Endless loop when _error render throws on client side #6973

Closed
dorian-marchal opened this issue Apr 9, 2019 · 21 comments · Fixed by #26567
Closed

Endless loop when _error render throws on client side #6973

dorian-marchal opened this issue Apr 9, 2019 · 21 comments · Fixed by #26567
Assignees
Labels
good first issue Easy to fix issues, good for newcomers
Milestone

Comments

@dorian-marchal
Copy link

dorian-marchal commented Apr 9, 2019

Bug report

Describe the bug

When using a custom _error page, Next can enter an infinite loop if _error render throws on client side (with a production build).

To Reproduce

Repro here : https://github.com/dorian-marchal/next-repro/tree/repro-6973

In a terminal:

$ git clone -b repro-6973 https://github.com/dorian-marchal/next-repro
Cloning into 'next-repro'...

$ cd next-repro/

$ node -v
v10.14.1

$ npm install

$ npm ls next
[email protected] /tmp/next-repro
└── [email protected]

$ npm run build && npm run start
...
> Ready on http://localhost:3000

In your browser:

  • Go to http://localhost:3000/
  • Open your browser devtools
  • Click on "Client side nav"
  • See the app entering an endless loop (stopped after 20 iterations).

Expected behavior

On client side, if _error throws, I expect an "Internal Error" page (this is what happens when _error throw during server side rendering).

I suppose that Next could force a page reload in this case.

System information

  • OS: Ubuntu 18.04
  • Version of Next.js: 8.0.4

Additional context

In our project, this error happens when _error getInitialProps fails to retrieve some dependencies (Error.render tries to access an undefined property).

@dorian-marchal
Copy link
Author

dorian-marchal commented Apr 11, 2019

Possible workaround, using an error boundary: https://github.com/dorian-marchal/next-repro/blob/workaround-6973/pages/_error.js

class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { hasError: false };
  }

  static getDerivedStateFromError() {
    return { hasError: true };
  }

  render() {
    if (this.state.hasError) {
      return "Internal Error.";
    }

    return this.props.children;
  }
}

const ErrorTemplate = () => {
  // ReferenceError: foo is not defined.
  foo;
  return "OK";
};

class Error extends React.Component {
  render() {
    return (
      <ErrorBoundary>
        {/* If ErrorTemplate throws, the boundary will catch it. */}
        <ErrorTemplate {...this.props} />
      </ErrorBoundary>
    );
  }
}

@armenr
Copy link

armenr commented May 24, 2019

^ We are running into this same error on our side. The workaround provided doesn't appear to be working for us, when we implement it verbatim.

@MarcusBondezan
Copy link

MarcusBondezan commented Aug 16, 2019

Same error here. None of the solutions above did the trick for me =/

@timneutkens timneutkens added this to the 9.0.x milestone Aug 16, 2019
@dan-fein
Copy link
Contributor

This is a really worrisome bug. Happens to me on every single error.

@timneutkens
Copy link
Member

Well it's not super worrisome, you're customizing the error page and introducing another error (runtime error) into it, which is more like a pretty big edge case. We'll fix it though (or you're welcome to open a PR).

@Timer Timer modified the milestones: 9.0.x, 9.0.5, 9.0.6 Aug 20, 2019
@Timer Timer modified the milestones: 9.0.6, 9.0.7 Sep 12, 2019
@Timer Timer modified the milestones: 9.0.7, 9.0.8, 9.0.9 Sep 28, 2019
@Timer Timer modified the milestones: 9.0.9, 9.1.1, 9.1.2 Oct 7, 2019
@Timer Timer modified the milestones: 9.1.2, 9.1.3 Oct 23, 2019
@Timer Timer modified the milestones: 9.1.3, 9.1.4 Nov 8, 2019
@Timer Timer modified the milestones: 9.1.4, 9.1.5 Nov 19, 2019
@Timer Timer modified the milestones: 9.1.5, 9.1.6 Dec 10, 2019
@Timer Timer removed this from the 9.4.x milestone Jun 6, 2020
@timneutkens timneutkens added this to the backlog milestone Jun 6, 2020
@Oikio
Copy link

Oikio commented Jun 15, 2020

v9.4.2, still happens.

@Timer Timer added the good first issue Easy to fix issues, good for newcomers label Jun 17, 2020
@grefrit
Copy link

grefrit commented Sep 30, 2020

9.5.3 not fixed

@MyCupOfTeaOo
Copy link

v10.0.1, still happens.

@wjd3
Copy link

wjd3 commented Feb 6, 2021

Happens in 10.0.5 in production (deployed to Vercel) when calling .includes() on a variable that's missing server-side data.

I actually don't have a custom /_error page, but this was the only existing issue that resembles what I'm experiencing. It matches in every way except for the use of custom /_error.

@lucashfreitas

This comment has been minimized.

@CharlestonREM
Copy link

Happens in 10.0.5 in production (deployed to Vercel) when calling .includes() on a variable that's missing server-side data.

I actually don't have a custom /_error page, but this was the only existing issue that resembles what I'm experiencing. It matches in every way except for the use of custom /_error.

@dayvista , i think i'm running into this issue in my nextjs app. could you post one of your examples of calling .includes() on a variable that's missing server-side data?

@wjd3
Copy link

wjd3 commented Apr 16, 2021

@CharlestonREM unfortunately that was many iterations ago in a private repo at my last job. I recall that I solved the issue by structuring the code like:

serverSideData?.includes('some string')

instead of:

serverSideData.includes('some string')

That way, if the server side data == null, then the function evaluates to false instead of throwing an error.

@wjd3
Copy link

wjd3 commented Apr 16, 2021

@CharlestonREM you could also use a server side data caching library like SWR and check if isLoading === false before calling .includes()

@tarasov-gk
Copy link

in Next 10.0.1 is still happens.

@Abhishek-Sati
Copy link

next version: 12.0.2
node version: 17.0.1
On client-side rendering when routing happens, and the page has some error then _error page goes into an infinite loop.

@huozhi
Copy link
Member

huozhi commented Nov 2, 2021

@Abhishek-Sati can you open a new issue with a reproduction? We can investigate it, thanks!

@kvet
Copy link

kvet commented Jan 11, 2022

Got similar issue with the swcMinify: true configuration in [email protected] and [email protected]

@WinnersProx
Copy link

WinnersProx commented Jan 13, 2022

Got similar issue with the swcMinify: true configuration in [email protected] and [email protected]

Getting the exact same error too

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Feb 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet