Implement Delayed Query Invalidation Until All LocalStorage Mutations are Processed in React Query #7700
Replies: 1 comment
-
Invalidation is something that you do on your own - it's not the library doing it. Long story short, if you don't want invalidations at a certain point (e.g. while you are still resuming paused mutations), then don't call Usually, invalidation happens in |
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.
-
Hello @TkDodo,
I am currently utilizing React Query to manage the state and synchronization of data in an application with offline capabilities. Our setup involves saving mutations to local storage when the client is offline. Upon regaining internet connectivity, these mutations are processed sequentially.
Issue: Each mutation triggers query invalidations immediately upon processing. This behavior is suboptimal because it can lead to unnecessary re-fetching and potential performance issues, especially when multiple mutations are involved.
Requirement: I am seeking a more efficient approach where no queries are invalidated while mutations are still being processed. Only after all mutations stored in localStorage are completed should the queries be invalidated collectively. This would ensure that the data remains consistent and minimizes the number of re-fetches.
Proposed Solution: Ideally, I would like to implement a mechanism where query invalidation is queued and executed only after all offline mutations have been successfully applied. This approach would likely involve modifications to the mutation synchronization logic to batch or defer the invalidation process until after all mutations are settled.
Could you please provide guidance or consider enhancing the library to support this use case? It would greatly benefit applications that heavily rely on offline functionality and need to manage data synchronization efficiently when coming back online.
Here's my approach:
Beta Was this translation helpful? Give feedback.
All reactions