T
TanStack3y ago
fascinating-indigo

Infinite queries fetching behavior (and preventing duplicates/missing data)

I have been looking at the following portion of the docs that talks about how all pages are sequentially refetched when the entire infinite query needs to be refetched. I am curious to how react-query handles fetching new pages. Do previous pages also get refetched? For example: 1. User loads page 1 2. User scrolls down and loads page 2. 3. Does page 1 get refetched as well? In other words, whenever new pages are fetched, do all the previous pages also get refetched? If not, then won't we run into the issue of duplicates/missing data?
No description
4 Replies
ratty-blush
ratty-blush3y ago
when you scroll down, you have to invoke fetchNextPage(), which will only fetch page 2 fetching the next page is not a refetch
fascinating-indigo
fascinating-indigoOP3y ago
Gotcha thanks for clarifying. So if we’re currently using offset based pagination, is it possible to have issues with duplicates / missing records this way? When the underlying data has changed in between the page 1 fetch and the page 2 fetch
ratty-blush
ratty-blush3y ago
Yes that can happen
fascinating-indigo
fascinating-indigoOP3y ago
I see. This can also happen with cursor based pagination as well right? So would the recommended approach be to always refetch all pages whenever fetching new pages? That way you guarantee no duplicates or missing records fully?

Did you find this page helpful?