Skip to content

fix(VVirtualScroll): preserve height measurements when items array changes - #23072

Closed
waterWang wants to merge 1 commit into
vuetifyjs:masterfrom
waterWang:fix/virtual-scroll-preserve-heights-22590
Closed

fix(VVirtualScroll): preserve height measurements when items array changes#23072
waterWang wants to merge 1 commit into
vuetifyjs:masterfrom
waterWang:fix/virtual-scroll-preserve-heights-22590

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

Description

When using v-virtual-scroll with item-height="null" (dynamic height), the sizes array was completely reset whenever the items array was reassigned, causing all previously measured heights to be lost. This caused the scroll position to jump unexpectedly when:

  1. Expanding/collapsing rows in a subgrid
  2. Updating data that causes the items array to be reassigned
  3. Any change that triggers items reactivity

Root Cause

In packages/vuetify/src/composables/virtual.ts, the watch(items, ...) handler at line 294 was resetting both sizes and offsets arrays to empty arrays of the new length, discarding all previously measured heights.

Fix

Instead of creating empty arrays, the fix preserves existing height measurements for items at the same index:

  • Save the old sizes array before resetting
  • After creating new arrays of the correct length, restore heights for items at matching indices
  • Items at new indices (beyond the old length) remain unmeasured (will use estimated heights)
  • Items at removed indices (beyond the new length) are simply dropped

This way, scroll position remains stable when the items array changes but contains similar items.

Related Issue

Fixes #22590

…anges

When using v-virtual-scroll with dynamic heights (item-height="null"),
the sizes array was completely reset whenever the items array was
reassigned, causing scroll position to jump unexpectedly.

This fix preserves existing height measurements for items at the same
index, so scroll position remains stable when the items array changes
but contains similar items (e.g., expanding/collapsing rows, updating
sub-item data).

fixes vuetifyjs#22590
@J-Sek

J-Sek commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

duplicate of #23066

@J-Sek J-Sek closed this Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug Report][3.11.6] Virtual Scroll loses height measurements on items change with dynamic-height rows

2 participants