Infinite render loop when select maps keepPreviousData to undefined in v5.105.2+
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Accessibilité débutants
- 35/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- À l'abandon
- Stack technique
- react, typescript
- Domaine
- backend-api-design
Piste de recherche
Start with the linked reproduction and compare behavior in v5.105.1 with v5.107.1; the issue points to QueryObserver.createResult and the repeated getOptimisticResult and setOptions calls in useQuery. Reproduce by rendering Picker and clicking its button, then trace why the placeholder result alternates between success and pending. Done when the result settles with status: 'success', isPlaceholderData: true, and data: undefined, without a React update-depth error.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
Since v5.105.2, a disabled query with placeholderData: keepPreviousData and a select that returns undefined loops until React throws "Maximum update depth exceeded". Unlike #12532, select does not throw. Still reproducible on v5.107.1 and main; v5.105.1 is fine.
Your minimal, reproducible example
https://stackblitz.com/github/mooxl/tanstack-query-12574-repro?file=src%2Fmain.jsx
Click the button. Switch @tanstack/react-query to 5.105.1 in package.json and it settles instead.
function Picker() {
const [id, setId] = useState('a')
const { data } = useQuery({
queryKey: ['items', id],
queryFn: () => [id],
enabled: id !== '',
placeholderData: keepPreviousData,
select: (items) => items.find((item) => item === id),
})
return <button onClick={() => setId('')}>{data ?? 'none'}</button>
}
Steps to reproduce
Render Picker, wait for a, click the button.
Expected behavior
The result settles as placeholder data (status: 'success', isPlaceholderData: true, data: undefined).
How often does this bug happen?
Every time
Platform
Any
Tanstack Query adapter
react-query
TanStack Query version
5.107.1
Additional context
QueryObserver.createResult has no fixed point here. When the previous result was a placeholder, it reuses prevResult.data, which select already mapped to undefined, so the result falls back to pending. The next call computes the placeholder again (success). #12230 makes useQuery call getOptimisticResult and then setOptions on every render, which keeps flipping it. It also reproduces with QueryObserver alone.
- 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
-
infiniteQuery throws "getNextPageParam is not a function" when 2+ stale pages are cachedPeut-être pris @abu-tahir-0 l’a pris il y a 7 jours. Ouverte
Difficulté 3/5 1-2 jours Accessibilité débutants 42/100
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
-
Type/Improvement
Difficulté 2/5 1-3 heures Accessibilité débutants 67/100
OpenNSW/nsw-srilanka#1259 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
oxc-project/tsrs#1010 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Fission-AI/OpenSpec#2260 ·
Les mainteneurs répondent en général sous 1 jour
-
Add: ESP 1 UKOuvertecheck:passed streams:add
Difficulté 1/5 1-3 heures Accessibilité débutants 64/100
Les mainteneurs répondent en général sous 1 jour
-
area:infra area:storage bug
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
THU-MAIC/OpenMAIC#2311 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour