-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
What you were expecting:
When using mutationMode="pessimistic"
in Edit or Create components, the onError
handler should be called when the DataProvider throws an HttpError, and error notifications should be displayed to the user.
What happened instead:
The onError
handler is never called, and error notifications are not displayed, even though the DataProvider correctly throws HttpError objects. The form remains in a loading state without any user feedback about the error.
Steps to reproduce:
- Create an Edit component with
mutationMode="pessimistic"
- Add an
onError
handler to the form (TabbedForm, SimpleForm, etc.) - Configure DataProvider to throw HttpError on update/create operations
- Trigger an update/create operation that will fail
- Observe that
onError
is never called and no error notification appears
Related code:
// Edit component
<Edit<Resource> mutationMode="pessimistic">
<TabbedForm onError={(error) => {
console.log('This never gets called'); // This never executes
notify(error.message, { type: 'error' });
}}>
{/* form fields */}
</TabbedForm>
</Edit>
// DataProvider update method
const update = async (resource, params) => {
try {
// API call that returns 400 error
const response = await fetch(/* ... */);
if (!response.ok) {
throw new HttpError('Error message', 400, responseBody);
}
} catch (error) {
// This HttpError is thrown but onError is never called
throw new HttpError(error.message, error.status, error.body);
}
};
Environment:
- React version: ^19.1.0
- React Admin version: ^5.8.1
- Browser: Chrome Version 140.0.7339.128 (Official Build) (64-bit)
Additional context:
Using mutationMode="optimistic"
works correctly and displays error notifications. However, this would make the UI confusing.
This appears to be related to the closed issue #8428 from 2 years ago, which was closed without resolution. The problem affects both Create and Edit components when using pessimistic mutation mode.