Add option to disable the error boundary or bubble "outside of the router" #10166
Replies: 15 comments 19 replies
-
Not thowing the error means that in development my app does not fail and send the stack trace to the terminal. This means that all of the IDE work that has gone into processing stack traces and linking to the correct sites is useless. Am I doing something wrong? Is this really the intended behaviourin development? How does everybody else use react-router while they develop? Just watching the errors printed on the html? |
Beta Was this translation helpful? Give feedback.
-
I second the request. We cannot use it atm, as the routes are intercepting the errors displaying default ErrorBoundary of the RR. We have tried adding a top level error boundary via:
But it does not work, we are still seeing the default handler on routes in modules that are not direct children of the above browser router (they are rendered as While I appreciate the default error handling, there should be a way to disable that and wrap app in our own boundary. At the moment is is more of a hindrance than aid. |
Beta Was this translation helpful? Give feedback.
-
Just re-throw the error.
This seems to work properly |
Beta Was this translation helpful? Give feedback.
-
Upvote. Would like to see this be implemented. |
Beta Was this translation helpful? Give feedback.
-
Support this configuration and hope to implement it soon, It is now implemented through hacks |
Beta Was this translation helpful? Give feedback.
-
This would be helpful! Need it as we use |
Beta Was this translation helpful? Give feedback.
-
Upvote. We have global error handling via a common component library used by multiple apps/teams, and we all now have to implement a custom "hack" individually to handle errors at each route also |
Beta Was this translation helpful? Give feedback.
-
This is also a problem when using Storybook with their test-runner, because stories with errors no longer fail tests. |
Beta Was this translation helpful? Give feedback.
-
Have folks tried the solution proposed above to just re-throw from a root level boundary to get it outside the router? #10166 (comment) const router = createBrowserRouter([
{
path: '/'
Component: Root,
ErrorBoundary: () => {
throw useRouteError();
},
},
]); There is a separate concern of being able to gain access to the |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, this was my work arround to get access to error and info. Hope this help you guys |
Beta Was this translation helpful? Give feedback.
-
We're struggling with this as well, we have an isomorphic web application that renders a serviceable html version of the page On initial load. Unfortunately the ErrorBoundary driven solutions above insist on re-rendering and replacing a usable page with a non-usable one. I would like to simply allow the error to run it's course. This way, the error will get picked up by our logging, hydration will fail, and the initial html will continue to be displayed to the user who will click on to the next page without knowing anything went wrong.
I agree with this take, error handling seems outside the scope of a router and would be extremely easy to implement, but in it's current state it forces itself on all users. |
Beta Was this translation helpful? Give feedback.
-
I think that this (partial) error handling feature doesn't adhere to the separation of concerns principle. |
Beta Was this translation helpful? Give feedback.
-
Part of what makes React Router's built-in error boundaries problematic is that we're forced into the re-throw hack so that we can use the root error boundary, which is typically where we install Sentry or the equivalent (an error reporting service). If I split up my route config across a few files, I need to remember to add my re-throw component as the error boundary for each top-level route. Otherwise React Router's error boundary catches and swallows errors, so they're never reported to Sentry. I think many thousands of apps using React Router are set up this way—i.e., with only an error boundary at the root. |
Beta Was this translation helpful? Give feedback.
-
I'm working on a legacy application. It's old and bad react code, I'm working on modernizing it. There are literally hundreds of exceptions thrown all over the place. They're "normal". Despite these exceptions, the app works reasonably well; sorta. However, I migrated from the legacy router to the browser router and now the app won't even render? We can't upgrade from an earlier version of react router to a newer one because suddenly react-router decided it wanted to decide when the app should or shouldn't render? This makes no sense. Yes of course we intend to clean up the errors, but most of the errors are very inconsequential and would be nice to clean up like it would be nice to clean up the attic at home, not because fatal errors are occurring all over the place! |
Beta Was this translation helpful? Give feedback.
-
It is not the responsibility of the router to catch errors. I can see how this would be useful to people, so it's a nice addition, but it should be an opt-in feature. As other folks have said, if you upgrade your router, you should not expect to have it impact your app's global error handling code. Also, you might not even know! And how will you find out, if you're not getting error reports sent?!
So, if you have a highly upvoted issue and none of your users know the workaround available to them, don't you think that is evidence of a poor or unintuitive design? I'm glad there's a simple workaround, but this decision making is disappointing. |
Beta Was this translation helpful? Give feedback.
-
Whilst the
errorElement
might be a nice addition, it's quite inconvenient when having customErrorBoundaries
in place or using one from another package like the AppInsightsErrorBoundary.An app-wide
ErrorBoundary
can't be used anymore because react-router will always catch it beforehand.So when having components outside of the router it basically requires two implementations (the "default one" and one using
useRouteError
)Crude suggestion
<RouterProvider router={router} disableErrorBoundary={true} />
Current workaround
Move the
<RouterProvider>
as high as possible and wrap the top-most route with the custom ErrorBoundary.Beta Was this translation helpful? Give feedback.
All reactions