You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We’re using useInfiniteQuery() in a chat app to load messages between users. Each conversation is stored using a query key like:
[CurrentUserGUID, ParticipantGUID]
Messages are loaded in pages.
However, when we load messages for a new participant (e.g., [CurrentUserGUID, ParticipantGUIDN]), we noticed that React Query also re-fetches data for previously loaded conversations like:
we noticed that React Query also re-fetches data for previously loaded conversations like
I don’t know what that means. Please show a minimal reproduction instead of some code-snippets so that we can take a look.
Generally, React Query will re-fetch all pages in the cache for a given queryKey, which is on purpose. This sounds a lot like you’d want different query Keys for different conversations, but your example doesn’t show that. queryKey: key doesn’t tell me anything.
Describe the bug
We’re using useInfiniteQuery() in a chat app to load messages between users. Each conversation is stored using a query key like:
[CurrentUserGUID, ParticipantGUID]
Messages are loaded in pages.
However, when we load messages for a new participant (e.g., [CurrentUserGUID, ParticipantGUIDN]), we noticed that React Query also re-fetches data for previously loaded conversations like:
This causes unnecessary network requests for older chats.
Your minimal, reproducible example
na
Steps to reproduce
Have give entire repro above.
Expected behavior
We expect the backend call only for the pages we are loading currently and not a re-fetch of all previously loaded pages.
How often does this bug happen?
None
Screenshots or Videos
No response
Platform
Tanstack Query adapter
None
TanStack Query version
TypeScript version
using JS
Additional context
No response
The text was updated successfully, but these errors were encountered: