-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
Implementing global error handling #1181
Comments
EDIT: nevermind, this does not seem to work, it's still always caught here with no way to disable: router/packages/react-router/src/Matches.tsx Lines 92 to 106 in 249e41e
createRouter({
...
defaultErrorComponent: (({ error }) => {
throw error;
}) satisfies ErrorRouteComponent,
}); It would indeed be nice to be able to disable error handling, in case the router is used in an environment that expects to handle errors completely on its own, eg. Storybook with Chromatic. |
is this still relevant? |
Here's the same StackBlitz as @kimsagro1 with the latest TanStack Router packages. Now:
This part of the original issue is still unsolved:
This part is now working:
An alternative approach can be seen in this StackBlitz. I removed the error boundary and defaultErrorComponent, and am instead using an errorComponent in the root route. The errorComponent renders the same thing as the root route (so the navbar is duplicated). This ensures that the same UI is shown regardless of where the error originates. @schiller-manuel I think this can be closed. |
Closing this since this should no longer be an issue with the user being able to set an https://stackblitz.com/edit/github-mx6tcy?file=src%2Froutes%2Fabout.tsx |
Describe the bug
I am trying to implement a global error page and am having difficulties.
I have a sample here where you can try uncommenting the throw statements to see various scenarios
https://stackblitz.com/edit/github-rodaot?file=src%2Fmain.tsx
Attempt 1 - ErrorBoundary
I first tried adding an ErrorBoundary to the root of my component tree, but it seem's like tanstack router has it's own in-built Something went wrong error component so my error boundary was never triggered.
Attempt 2 - defaultErrorComponent
I next tried adding a defaultErrorComponent however the issue with this is that if the error is raised in the index component then the defaultErrorComponent is wrapped in the root layout. If the error is raised in the root component then the defaultErrorComponent is not wrapped in root layout. I'm trying to achieve an error page that looks the same in all scenarios.
Issue 1
It doesn't appear possible to achieve an error component that looks the same regardless of where the error is thrown and handles all scenarios?
Issue 2
I also noticed that the error being thrown in the about loader doesn't seem to trigger the error component.
Your Example Website or App
https://stackblitz.com/edit/github-rodaot?file=src%2Fmain.tsx
Steps to Reproduce the Bug or Issue
// throw 'error from index';
to see the messagedefaultErrorComponent: Something went wrong
but wrapped in the root layout// throw 'error from root';
to see the messagedefaultErrorComponent: Something went wrong
but not wrapped in the root layout// throw 'error from about loader';
to see the the error component is not shownExpected behavior
As a user I expected a way to show a fallback error component (much like when you specify a
notFoundComponent
on theroot
route) that displays the same regardless of where the error is thrown. Or perhaps a way to opt out completely and use my own error boundaryScreenshots or Videos
No response
Platform
NA
Additional context
No response
The text was updated successfully, but these errors were encountered: