-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
Comments
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>
);
}
} |
^ 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. |
Same error here. None of the solutions above did the trick for me =/ |
This is a really worrisome bug. Happens to me on every single error. |
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). |
v9.4.2, still happens. |
9.5.3 not fixed |
v10.0.1, still happens. |
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. |
This comment has been minimized.
This comment has been minimized.
@dayvista , i think i'm running into this issue in my nextjs app. could you post one of your examples of calling |
@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 |
@CharlestonREM you could also use a server side data caching library like SWR and check if |
in Next 10.0.1 is still happens. |
next version: 12.0.2 |
@Abhishek-Sati can you open a new issue with a reproduction? We can investigate it, thanks! |
Got similar issue with the |
Getting the exact same error too |
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. |
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:
In your browser:
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
Additional context
In our project, this error happens when _error
getInitialProps
fails to retrieve some dependencies (Error.render
tries to access an undefined property).The text was updated successfully, but these errors were encountered: