virtual icon indicating copy to clipboard operation
virtual copied to clipboard

Dynamic item sizes are not recalculated after reordering

Open Misha6787 opened this issue 3 weeks ago • 2 comments

Describe the bug

In a virtualized list using @tanstack/vue-virtual, reordering items with dynamic or varying sizes (e.g., different heights) does not trigger a recalculation of their cached measurements. As a result, the items retain their initial rendered dimensions post-reorder, leading to visual artifacts such as:

  • Larger items being clipped or overflowing within the constrained space originally allocated to smaller items.
  • Smaller items leaving empty gaps due to mismatched container sizes.

Your minimal, reproducible example

https://stackblitz.com/edit/tanstack-virtual-xbv5kvkh?file=src%2FApp.vue

Steps to reproduce

  1. Click the Swap button
  2. Look at the list's second and third items

Expected behavior

After reordering, the virtualizer should re-measure and update the sizes for affected items

How often does this bug happen?

Every time

Screenshots or Videos

No response

Platform

  • Windows - Chrome - v.142.0.7444.61

tanstack-virtual version

v3.13.12

TypeScript version

v5.4.5

Additional context

No response

Terms & Code of Conduct

  • [x] I agree to follow this project's Code of Conduct
  • [x] 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.

Misha6787 avatar Dec 01 '25 20:12 Misha6787

This issue can be "fixed" in the userland by calling virtualizer.measure() when the ordering in the item list is changed. The issues are:

  1. The performance drawbacks are unclear
  2. Reordering detection looks like a pretty low-level code, which can be written in the library itself

IMO, ideally, the library should automatically handle size recalculation during reordering

Ilanaya avatar Dec 01 '25 21:12 Ilanaya

I found a reference where @piecyk recommends using useCallback to solve a (looks like) similar issue. In vue, however, we don't have such an API and rely on a smarter reactivity system rather than handling dependencies manually.

Ilanaya avatar Dec 01 '25 21:12 Ilanaya