refine icon indicating copy to clipboard operation
refine copied to clipboard

[BUG] undoable mutation is called many times

Open collinpreston opened this issue 3 years ago • 2 comments

Describe the bug When updating multiple records at the same time whose mutationMode is undoable, the doMutation() method is called multiple times leading to duplicate API calls for the dataProvider.

To Reproduce Steps to reproduce the behavior:

  1. Go to a list page where multiple records are shown. useUpdate or useUpdateMany works best for this. Ensure the mutation function for the records defines mutationMode: "undoable"
  2. Edit one of the records.
  3. While the toast message from step 2 is still shown, update different record.
  4. While the toast message from step 2 is still shown, update the same record from step 2 again

Expected behavior Viewing the network calls made from the browser, you will see that many more API calls to the dataProvider endpoint were executed. You would expect that with 3 updates made, only 3 API calls would have been performed.

Screenshots I've modified the refine-advanced-table-example with the following changes in order to better represent this issue:

  1. The "Delete selected items" button is not disabled while waiting for the success of the undoable mutation.
  2. The useDeleteMany mutation has been changed to useUpdateMany so that records are not removed and can be modified multiple times.

I believe these changes provide a more simplistic use case which serves to demonstrate the issue. Disabling the "Delete selected items" button is definitely a work around for this issue, but a requirement to disable the user from disabling any edit functionality is not clearly mentioned in documentation.

https://user-images.githubusercontent.com/8311573/191482087-ef33607f-4ea5-4d25-83c6-4bbdec76c850.mov

Desktop (please complete the following information):

  • OS: MacOS
  • Browser chrome
  • Version 105.0.5195.125
  • Used dataProvider [e.g. custom, Strapi, Airtable]

Additional information A possible fix for this is shown here: https://github.com/pankod/refine/compare/next...collinpreston:refine:remove-notificationItem-at-time-zero

collinpreston avatar Sep 21 '22 10:09 collinpreston

Hey @collinpreston , Thank you for contacting us! We had the idea to refactor the undoable queue. with this issue, we can make it happen! 🚀

omeraplak avatar Sep 21 '22 12:09 omeraplak

Hey @collinpreston, We've created #2559 . We will probably release it tomorrow 💥 Thank you for your understanding and patience

omeraplak avatar Sep 21 '22 16:09 omeraplak

Hey @collinpreston , We've released @pankod/[email protected]. Could you approve this fix?

omeraplak avatar Sep 22 '22 11:09 omeraplak