infiniteQuery throws "getNextPageParam is not a function" when 2+ stale pages are cached
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 42/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- typescript
- Domaine
- frontend
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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.
- Langage dominant
- TypeScript
- Étoiles
- 50.6k
- Forks
- 4.2k
- Merge moyen
- 8 h 37 min
- PR mergées (30 j)
- 450
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de TanStack/query
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
TanStack/query#12466 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
solid-query: STRICT_READ_UNTRACKED on Solid 2 — client()/options() read in component body (useMutation, useBaseQuery)Peut-être à nouveau libre @LeonxLJX l’a pris il y a 74 jours, et aucune pull request n’est ouverte. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
TanStack/query#11358 · 2 commentaires · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
Les mainteneurs répondent en général sous 1 jour
-
Infinite render loop when select maps keepPreviousData to undefined in v5.105.2+Peut-être pris @mooxl l’a pris il y a 6 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 35/100
TanStack/query#12574 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de TanStack/query
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
ilan-pinto/roaring-lions#1552 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
bug: [React Native/Android] KeepAliveService never starts when CAMERA is not granted (Android 14+)Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
cloudflare/realtimekit-ui#208 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
usebruno/bruno-vscode#235 ·
Les mainteneurs répondent en général sous 3 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour