Add a new live mode that uses the event payload to update the query cache #5704
TomCaserta
started this conversation in
Ideas
Replies: 1 comment
-
Hey @TomCaserta thanks for bringing this up! Actualy, this is something we've been thinking before. See my comment here. Would be more than happy to review if you would send a PR! Looking forward to discuss it more so we can get it released. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Been using refine now for a little while, we've just implemented our own live provider. After using it and looking at the refine codebase I see that the primary purpose of a live provider is simply invalidating the cache while seemingly not actively using anything else in the event payload.
I would therefore like to propose a couple new live modes:
payload
:When an event comes in of type
updated
it will update the tanstack query cache much like optimistic mutations do but not invalidate the data.This helps in scenarios where your event payload has the same schema as your resource and you do not want live events causing a refetch (beit 'list', 'one' or 'many').
When a created/deleted event comes in and pagination is enabled then
useList
etc could update some state that countains a counter of events and return that from the hook so in the UI you can show a message eg.Theres X new <resource> [Refresh]
. This hopefully gets around the issue of trying to update paginated data.optimistic-payload
Similar to the above however it will invalidate the query after optimistically updating the query cache.
Failing this, could there instead be extra parameters passed to the
onLiveEvent
callback that gives developers the ability to modify the query cache for that resource manually. So far we're basically importing the query client from tanstack/react-query and thekeys
helper from refine and updating the query data but this seems brittle.I have no hesitations with working on and creating a PR for either of these options myself, just asking if this is something you've thought about?
Beta Was this translation helpful? Give feedback.
All reactions