useInfiniteQuery only fetches last page when the cache is invalidated. #7569
-
|
I am using I need help to ensure that all pages are refetched correctly upon invalidation and to prevent the app from appearing broken due to the empty last page. Any guidance or examples on how to manage this with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Update: The issue appears to be that when the data becomes stale, the system attempts to refetch all pages starting from the first page. The first page does not have page parameters, while only subsequent pages do. Consequently, the |
Beta Was this translation helpful? Give feedback.
Alright, after digging deeper, I discovered the problem. The issue lies with the state of
pageParamswhen usinguseInfiniteScrollin reverse mode, i.e.,getPreviousPageinstead ofgetNextPage. In this scenario, the page parameters are stored in the wrong order, causing the issue. Ideally, with reverse pagination, Tanstack Query should intelligently store the page parameters in reverse order to maintain the pagination flow.Nevertheless, for future reference, there are two solutions you can choose from:
getNextPageParamand avoid usinggetPreviousPageParam(this is the solution I chose), which should work fine.selectcallback under the query option foruseInfin…