infiniteQuery throws "getNextPageParam is not a function" when 2+ stale pages are cached
維護者通常 1 天內回覆
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 42/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- typescript
- 領域
- frontend
研究方向
The failing path is the infiniteQuery and fetchInfiniteQuery handling in query-core when stale pages are already cached, and the error surfaces as options.getNextPageParam is not a function. Start by reproducing with the stackblitz example or a small test that seeds two pages with setQueryData, then trace where getNextPageParam is read during the refetch of existing pages. Done means the call either works without the callback or the types require it, with a regression test covering the stale multi-page case.
由索引模型根據 Issue 內容生成。
描述
Describe the bug
Hey :)
I ran into this while testing query-core.
I can call queryClient.infiniteQuery without getNextPageParam as long as I don't pass pages. TypeScript is fine with it, and it works on an empty cache.
But if the same key already has 2 or more pages cached and they're stale, the exact same call throws:
TypeError: options.getNextPageParam is not a function
Same with fetchInfiniteQuery. prefetchInfiniteQuery doesn't throw, but it leaves the query in an error state.
So the same call works or crashes depending on what's already in the cache.
Thanks!
Your minimal, reproducible example
https://stackblitz.com/github/a-botermans/tanstack-query-infinite-repro
Steps to reproduce
- Have 2 pages in the cache for a key. The demo uses
setQueryData, but loading them withuseInfiniteQuery+fetchNextPagegives the same result. - Let them go stale. The default
staleTime: 0is enough. - Call
infiniteQueryon the same key, withoutpagesand withoutgetNextPageParam:
queryClient.setQueryData(['pages'], {
pages: ['page 0', 'page 1'],
pageParams: [0, 1],
})
await queryClient.infiniteQuery({
queryKey: ['pages'],
queryFn: ({ pageParam }) => `page ${pageParam}`,
initialPageParam: 0,
})
It refetches the first page fine, then throws when it needs the param for page 2.
Expected behavior
No internal TypeError for a call the types accept. Either it works without the callback, or the types should ask for it.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Not platform specific. Reproduced on Node 26 and in Chromium.
Tanstack Query adapter
vanilla
TanStack Query version
v5.107.1
TypeScript version
v5.6.3
Additional context
- The same steps work on 4.44.0 and fail on 5.0.0, so it looks like it came in with v5.
- With the default retries in the browser, the TypeError gets retried like a network error. The call hangs for about 7 seconds before it rejects.
- Workaround: pass
getNextPageParamin the call too. Then it refetches all the pages.
- 主要語言
- TypeScript
- 星號
- 50.6k
- 分支
- 4.2k
- 平均合併
- 8 小時 37 分鐘
- 30 天內合併 PR
- 450
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
TanStack/query 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
TanStack/query#12466 · 1 則留言 ·
維護者通常 1 天內回覆
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)可能重新可做 @LeonxLJX 於 74 天前認領,目前沒有進行中的 PR。 未關閉
難度 2/5 1-3 小時 新手友好度 84/100
TanStack/query#11358 · 2 則留言 · 1 個 reaction ·
維護者通常 1 天內回覆
-
難度 4/5 3-5 天 新手友好度 25/100
維護者通常 1 天內回覆
-
Infinite render loop when select maps keepPreviousData to undefined in v5.105.2+可能已有人在做 @mooxl 於 7 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 35/100
TanStack/query#12574 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 5/5 一週以上 新手友好度 25/100
維護者通常 1 天內回覆
相似的 Issue
-
難度 1/5 1-3 小時 新手友好度 83/100
gofish-graphics/gofish-graphics#1384 ·
維護者通常 1 天內回覆
-
adapter bug
難度 2/5 1-3 小時 新手友好度 83/100
Olanetsoft/agent-lookout#353 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
vicharanashala/vibe#1542 ·
維護者通常 1 天內回覆
-
bug chore P2 size:XS
難度 2/5 1-3 小時 新手友好度 77/100
josephfung/curia#2666 ·
維護者通常 1 天內回覆
-
bug good first issue
難度 2/5 1-3 小時 新手友好度 84/100
devarshishimpi/codra#178 ·
維護者通常 1 天內回覆