Replies: 2 comments
-
I don’t necessarily agree with this, as the first invalidation could’ve already read the state on the backend when the new event comes in, and it might then return outdated data. That’s why calling Other than that, have a look at TanStack Pacer, which offers throttling utilities to do this in user-land: https://tanstack.com/pacer/latest/docs/guides/throttling But we will not build this into react-query. |
Beta Was this translation helpful? Give feedback.
-
I did in fact go with pacer for the throttling implementation. Will experiment more with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In applications using mutations and server-sent events (SSE), a common pattern involves invalidating queries upon both successful mutations and SSE updates. This can lead to redundant refetches when a mutation triggers an SSE event shortly after, resulting in over-fetching.
Current Workarounds:
onSuccess
: Sacrifices immediate UI updates post-mutation.Proposed Solution:
Introduce a throttle option to queryClient.invalidateQueries() to prevent rapid, redundant invalidations for the same query key.
API Suggestion:
Benefits:
Discussion Points:
Note: I'm aware that I might've missed a piece of the puzzle here and such an option (or an alternative way to do that) already exists. If this is the case, I would love to know how.
Note 2: I would be happy to work on this.
Beta Was this translation helpful? Give feedback.
All reactions