infiniteQuery throws "getNextPageParam is not a function" when 2+ stale pages are cached

未關閉
#12,569 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@abu-tahir-0 已經在處理了。

開始於 2026年11月10日。

  • #12570 來自 @abu-tahir-0 —— 未關閉

評估

難度
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
  1. Have 2 pages in the cache for a key. The demo uses setQueryData, but loading them with useInfiniteQuery + fetchNextPage gives the same result.
  2. Let them go stale. The default staleTime: 0 is enough.
  3. Call infiniteQuery on the same key, without pages and without getNextPageParam:
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 getNextPageParam in the call too. Then it refetches all the pages.
主要語言
TypeScript
星號
50.6k
分支
4.2k
平均合併
8 小時 37 分鐘
30 天內合併 PR
450

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

TanStack/query 的其他 Issue

查看 TanStack/query 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。