Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move middlewares to dataProvider hooks #9855

Merged
merged 9 commits into from
May 22, 2024
Merged

Conversation

djhi
Copy link
Collaborator

@djhi djhi commented May 17, 2024

Problem

With react-query v5, we cannot rely on the side effects callbacks anymore to execute middlewares. Indeed, we had to move the default side effects of the main mutation (update for instance) at the hook call so that they are called even when the component that triggered the mutation has been unmounted (optimistic and undoable with redirections for instance). Because of that, middlewares don't have access to the default side effects anymore.

Solution

Apply the middlewares in the function we pass to react-query mutation (for instance, on dataProvider.update).
We loose the ability to alter side effects. However, the whole mutation (base one with its middlewares applied) can now be cancelled with undoable.

@djhi djhi added the WIP Work In Progress label May 17, 2024
@djhi djhi added RFR Ready For Review and removed WIP Work In Progress labels May 17, 2024
@fzaninotto
Copy link
Member

You should update the docs, too (cf https://marmelab.com/react-admin/useRegisterMutationMiddleware.html)

@adguernier adguernier self-requested a review May 21, 2024 07:38
Copy link
Member

@fzaninotto fzaninotto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document that change in the upgrade guide, too

packages/ra-core/src/controller/edit/useEditController.ts Outdated Show resolved Hide resolved
packages/ra-core/src/dataProvider/useUpdate.ts Outdated Show resolved Hide resolved
packages/ra-core/src/dataProvider/useUpdate.ts Outdated Show resolved Hide resolved
packages/ra-core/src/dataProvider/useUpdate.ts Outdated Show resolved Hide resolved
packages/ra-core/src/dataProvider/useUpdate.spec.tsx Outdated Show resolved Hide resolved
packages/ra-core/src/dataProvider/useUpdate.spec.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@slax57 slax57 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than that LGTM, well done!

@fzaninotto fzaninotto merged commit 81d5624 into next May 22, 2024
14 checks passed
@fzaninotto fzaninotto deleted the refactor-middlewares branch May 22, 2024 12:45
@fzaninotto fzaninotto added this to the 5.0.0 milestone May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants