Error Handling for Mutations #5957
Replies: 10 comments 26 replies
-
I commented on your previous post before reading this proposal. I like it. I think it should be opt-in, though. Something like: <Form handleError /> |
Beta Was this translation helpful? Give feedback.
-
@kiliman - let me see if I understand you. Would the api be something like below? <Form handleError={e => /* handle the error */} /> and then the default implementation for And for the use case I described above would be implemented as <Form handleError={e => showErrorDialog()} /> |
Beta Was this translation helpful? Give feedback.
-
we ran into the same issue so many times. |
Beta Was this translation helpful? Give feedback.
-
especial for |
Beta Was this translation helpful? Give feedback.
-
Planned as a possibility anytime soon? |
Beta Was this translation helpful? Give feedback.
-
Linking to remix-run/react-router#10013 as it also addresses the situation |
Beta Was this translation helpful? Give feedback.
-
This would be amazing to have. A failure sending a response in a pop-up chat in the corner of the page shouldn't break the whole page. :) |
Beta Was this translation helpful? Give feedback.
-
I stopped using actions because of that. But now that clientAction landed, we can probably handle network errors there. |
Beta Was this translation helpful? Give feedback.
-
I imagine something like that should work export const clientAction = async ({ serverAction }) => {
try {
return await serverAction()
} catch (error) {
return handleNetworkError(error)
}
} |
Beta Was this translation helpful? Give feedback.
-
Is there any news regarding this? It's a major pain point for us. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Proposal
Allow action errors to be handled without unmounting the route's default component.
Background
In a traditional SPA, a very common error handling pattern for mutations is something like this
"If the mutation throws an error, we show the user a dialog which informs them of the failure. When the dialog is dismissed, the user should be seeing their form again still filled out and ready to retry the submission."
This is very user friendly (and relatively common across the web). In a more traditional React SPA, the code to make this happen might look something like
Accomplishing this same behavior is Remix is currently not possible to my knowledge. Let's say that our user is experiencing network issues when they try to submit a Remix Form. The server will never receive the request and an error will be thrown. There is no opportunity to catch this error in user-land and so Remix renders the ErrorBoundary.
But wait! When we rendered the error boundary, we unmounted the default route component losing all our form data and react state! This is not a good user experience and there are not good workarounds available.
Proposal Details
I propose that the ErrorBoundary should render if there in an error on component render or in the loader for the route, but not if there is an error in the action. The reason for the distinction is that even if the action fails, we can go on rendering the default route component. It still has all it needs to render, so why unmount it?
The UI for an action error should be able to be "added on top of" the existing UI.
Why does this belong in Remix
The Remix docs talk about using progressive enhancement to ensure your UI is resilient to network issues. See https://remix.run/docs/en/1.14.3/tutorials/blog#progressive-enhancement
The Remix docs talk about maintaining form state in case of server error (does not mention network errors). See https://remix.run/docs/en/1.14.3/guides/optimistic-ui#maintain-form-state
I think allowing users to maintain form state while being resilient to network issues is a very natural fit.
Possible APIs
These are just my initial thoughts
Beta Was this translation helpful? Give feedback.
All reactions