Skip to content

Commit 0a66bab

Browse files
authored
fix: edge case when refetching infinite query (TanStack#409)
1 parent 9cd7a35 commit 0a66bab

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/useInfiniteQuery.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,20 @@ export function useInfiniteQuery(...args) {
2828
data.push(await originalQueryFn(...args))
2929
rebuiltPageVariables.push(args)
3030
} else {
31+
// get an up-to-date cursor based on the previous data set
32+
const nextCursor = getGetFetchMore()(data[data.length - 1], data);
33+
34+
// break early if there's no next cursor
35+
// otherwise we'll start from the beginning
36+
// which will cause unwanted duplication
37+
if (!nextCursor) {
38+
break;
39+
}
40+
3141
const pageArgs = [
3242
// remove the last argument (the previously saved cursor)
3343
...args.slice(0, -1),
34-
// generate an up-to-date cursor based on the previous data set
35-
getGetFetchMore()(data[data.length - 1], data),
44+
nextCursor
3645
]
3746

3847
data.push(await originalQueryFn(...pageArgs))

0 commit comments

Comments
 (0)