React-admin: Unhandled rejection (HttpError) on Edit, optimistic rendering - undoable true

Created on 18 Dec 2020  路  3Comments  路  Source: marmelab/react-admin

What you were expecting:
Optimistically return to index page, show error notification 'not found' once server responds with 404

What happened instead:
Optimistically returns to index page with 'undo' option as expected. But once server responds with 404, I get unhandled rejection.

Other information:
If I use undoable: false on my Edit component, the index view is not optimistically rendered and react admin correctly handles the HttpError with a 'not found' notification.

I'm using fetchUtils.fetchJson and returning a promise from update method on dataProvider. Per docs, I'm under the impression that react admin should handle http errors, and the fact that it does when undoable: false is evidence that I have it set up correctly.

Is the unhandled rejection that I'm seeing with the optimistic rendering the expected behavior for react admin?

Environment

  • React-admin version: 3.11.0
  • React version: 17.0.1
  • Browser: chrome (latest)
bug

Most helpful comment

Right, it can be triggered in the simple example sandbox by editing a post, setting 'f00bar' as the title, saving, and waiting until the notification disappears.

It seems to be caused by the following line: https://github.com/marmelab/react-admin/blob/4847dc6b47a72253cc9f657e0d172dcc7c75bb0c/packages/ra-core/src/dataProvider/useDataProvider.ts#L409

It was introduced in #4291, where I used the same code for optimistic and non-optimistic calls. If it make sense to re-throw the error in non-optimistic mode (so that the dataProvider promise rejects), it doesn't make sense in optimistic mode, as the dataProvider promise already resolved. So the error musn't be rethrown in optimistic mode.

All 3 comments

I don't understand your test case. Can you please provide a CodeSandbox reproducing the error, and add a step-by-step way to reproduce the error?

The test case is simply that using the out-of-the-box edit action (with undoable: true) will throw an uncaught http error after it optimistically redirects back to list view when server responds to the put/patch with an error. I can do a sandbox at some point.

Right, it can be triggered in the simple example sandbox by editing a post, setting 'f00bar' as the title, saving, and waiting until the notification disappears.

It seems to be caused by the following line: https://github.com/marmelab/react-admin/blob/4847dc6b47a72253cc9f657e0d172dcc7c75bb0c/packages/ra-core/src/dataProvider/useDataProvider.ts#L409

It was introduced in #4291, where I used the same code for optimistic and non-optimistic calls. If it make sense to re-throw the error in non-optimistic mode (so that the dataProvider promise rejects), it doesn't make sense in optimistic mode, as the dataProvider promise already resolved. So the error musn't be rethrown in optimistic mode.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kikill95 picture kikill95  路  3Comments

fzaninotto picture fzaninotto  路  3Comments

alukito picture alukito  路  3Comments

aserrallerios picture aserrallerios  路  3Comments

yangjiamu picture yangjiamu  路  3Comments