TanStack / TanStack/virtual

Layout breaks when changing lanes option with measureElement used

Open
#1,036 0 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
7.1k
Forks
466
Avg merge
2d 31m
Merged PRs (30d)
13

Description

Describe the bug

When using measureElement with useVirtualizer, changing the number of lanes dynamically causes the layout to break.
The virtualizer calculates incorrect ranges for items with indices beyond the visible range, resulting in mispositioned items or empty spaces.

Your minimal, reproducible example

https://codesandbox.io/p/devbox/tankstack-virtual-range-extractor-forked-wlddzn?workspaceId=ws_NvUKNhUDiFBCs4Fb9Zkkhb

Steps to reproduce
  1. Scroll to the end of the list (so that only higher-index items are rendered).
  2. Change the number of lanes from 10 to 5 dynamically.
Expected behavior
  • The virtualizer should correctly invalidate cached measurements for all items and recalculate their positions when the number of lanes changes.
  • The layout should adjust seamlessly after changing lanes.
How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

Any platform

tanstack-virtual version

3.13.12

TypeScript version

5.2.2

Additional context

No response

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and trace the useVirtualizer path involving measureElement, dynamic lanes, and cached item measurements. Reproduce the failure by scrolling to the end, changing lanes from 10 to 5, and confirm the layout recalculates positions without mispositioned items or empty spaces.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.