Processing realtime updates to the cache whilst initially fetching data #8325
Unanswered
eesamunir055
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I fetch chats initially, using useQuery, and then any subsequent updates to chats such as new chats are handled by my realtime socket handlers.
Whenever I receieve a new chat in real-time, I add it to the cache. If the query is initially fetching for the first time, the cache is obviously empty at this point. I check whether this existing chat is already in the cache, and if not I add it to the cache.
The problem I have is that if a chat is added to the cache whilst initially fetching, it is then overwritten when
useQuery
finishes fetching. This data fromuseQuery
may not include this new chat. I tried to callinvalidateQueries
given I receieve a chat in realtime andisFetching
for the chats is true, however this is pointless as the cache is empty at this point soinvalidateQueries
does nothing.One solution I tried was storing realtime updates in a queue whilst isFetching is true for the chats query and then merge the updates once fetching completes, however this seems tedious especially considering
onSuccess
was removed from the useQuery hook. Any ways I could potentially handle this?Beta Was this translation helpful? Give feedback.
All reactions