Replies: 2 comments 1 reply
-
In another discussion I proposed |
Beta Was this translation helpful? Give feedback.
0 replies
-
I think that this use case would be covered by middleware: if you add a client middleware for handling network errors and recommended error handling in your action/loaders (via try/catch), you would be able to do everything you need in user-land |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This proposal aims to Improve the way actions/fetchers/revalidations errors are handled
Background
React Router currently uses Error Boundaries as a unified way to handle errors that occur in routes, regardless of whether the errors occur in loaders, actions, or the component.
I totally get that, having a single way to do a certain thing makes life easier in many cases.
However, in terms of user experience, using error fallbacks only really makes sense when there is nothing that can be displayed in its place, for example when the error occurs when accessing a new page. In the case of a submission error, on the other hand, replacing the form component with an error fallback seems exaggerated...
Workarounds
The recommended approach has always been to return errors as data and access them directly in the component. To capture any type of error, we could wrap our action code in a try/catch.:
To also handle network errors with server actions in framework mode, we could use
clientAction
:These approaches generally work, but I have observed at least two limitations:
clientAction
to every route: In addition to increasing the js bundle slightly, this requires more effort from the developer to remember to add this so that this type of error is properly handled.useRevalidator
because that would require addingclientLoader
to every route putting try/catch in each of them, and in the navigation flow that would create branching for success/error loader data inside the componentProposal
Add the following properties to hold the uncaught error without unmounting the route component:
state
will be 'idle' (same as when there's data).Alternative API
What if there was an event listener to optionally prevent the error boundary?
Kind of similar to what we would do with clientAction, but a possible advantage could be being able to create a reusable Form component with this logic built-in.
Open Questions
unknown
(aligns with the error type in useRouteError()) or alwaysError
(simpler to use)?Related Discussions
remix-run/remix#7688
remix-run/remix#5957
remix-run/remix#4242
Beta Was this translation helpful? Give feedback.
All reactions