measureElement caches 0 size for nodes that aren't attached yet (Vue: rows stack at start 0 and the list scrolls away on mount)
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 78/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- typescript
- Domaine
- frontend, performance
Piste de recherche
Commencez par Virtualizer.measureElement et comparez son chemin de mesure synchrone avec la gestion existante de ResizeObserver pour les nœuds déconnectés. Vérifiez que les nœuds détachés conservent leur taille estimée tout en restant observés, puis ajoutez ou exécutez un test de régression couvrant la mesure des nœuds détachés, leur rattachement ultérieur et la conservation de la position de défilement.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug
Virtualizer.measureElement(node) measures the node synchronously right after observing it, even when the node is not attached to the document yet. A detached node reports offsetHeight === 0, and since there is no cached size on the first measurement, that 0 is stored as the item size.
In Vue this is easy to hit. Function refs run synchronously during patch, so when the rows are created in the same patch as their parent (the sizer is behind v-if and shows up once data is loaded), :ref="(el) => virtualizer.measureElement(el)" is called while the sizer is still detached:
- Every visible row gets size
0and renders atstart: 0, on top of each other. - On the next frame the ResizeObserver reports the real sizes and the rows spread out.
- The list ends up scrolled down (~305px in the repro, row 9 at the top) instead of staying at the top.
The ResizeObserver callback already ignores disconnected nodes (#1135), but the sync path in measureElement doesn't. #1226 only rejects a 0 when there is a previously cached size, so it doesn't cover the first measurement either.
Your minimal, reproducible example
https://stackblitz.com/github/webn00b/tanstack-vue-virtual-detached-measure
Steps to reproduce
- Open the repro. The scroll container is always rendered; the sizer and the rows are behind
v-if="loaded", which flips after a simulated fetch. - Rows are measured with
:ref="(el) => virtualizer.measureElement(el)",estimateSizeis 60. - Check the output under the list: the ref calls log
isConnected: false, offsetHeight: 0, and right afternextTickthe visible items havestart: 0, size: 0. - After the ResizeObserver fires, the list is at
scrollTop ≈ 305.
Expected behavior
Rows keep their estimateSize positions until they are measured, and the list stays at scrollTop: 0.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
Not browser-specific, it comes from when Vue calls function refs.
tanstack-virtual version
@tanstack/vue-virtual 3.13.39, @tanstack/virtual-core 3.17.11
TypeScript version
No response
Additional context
Skipping the sync measurement when !node.isConnected fixes it. The node is still observed, so the first frame uses estimateSize, the ResizeObserver delivers the real size once the node is attached, and the scroll position stays at 0. I have a fix with a regression test and can open a PR.
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- Langage dominant
- TypeScript
- Étoiles
- 7.1k
- Forks
- 468
- Merge moyen
- 1 j 2 h
- PR mergées (30 j)
- 12
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/virtual
-
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 38/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 62/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 4/5 3-5 jours Accessibilité débutants 55/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 3/5 1-2 jours Accessibilité débutants 68/100
TanStack/virtual#1257 · 1 réaction ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de TanStack/virtual
Issues similaires
-
docs
Difficulté 1/5 Moins d'une heure Accessibilité débutants 68/100
remix-run/react-router#15558 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
solana-foundation/pay-kit#341 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
supabase/agent-skills#607 ·
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 84/100
opengovsg/FormSG#10118 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour