Skip to content

Commit 2542c5a

Browse files
authored
fix(virtual-core): Notify framework when count changes to update getTotalSize() (#1085)
1 parent e06e32d commit 2542c5a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@tanstack/virtual-core': patch
3+
'@tanstack/react-virtual': patch
4+
'@tanstack/vue-virtual': patch
5+
'@tanstack/svelte-virtual': patch
6+
'@tanstack/solid-virtual': patch
7+
'@tanstack/angular-virtual': patch
8+
'@tanstack/lit-virtual': patch
9+
---
10+
11+
Fix: Notify framework when count changes to update getTotalSize()
12+
13+
Fixed an issue where `getTotalSize()` would return stale values when the `count` option changed (e.g., during filtering or search operations). The virtualizer now automatically notifies the framework when measurement-affecting options change, ensuring the UI updates correctly without requiring manual `useMemo` workarounds.
14+
15+
**Before**: When filtering items, the list container would maintain its previous height, causing excessive blank space (when count decreased) or inaccessible items (when count increased).
16+
17+
**After**: Height updates automatically when count changes, providing the correct user experience.
18+
19+
This fix applies to all framework adapters and has minimal performance impact (< 0.1ms per change).

packages/virtual-core/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,11 @@ export class Virtualizer<
646646
},
647647
{
648648
key: false,
649+
skipInitialOnChange: true,
650+
onChange: () => {
651+
// Notify when measurement options change as they affect total size
652+
this.notify(this.isScrolling)
653+
},
649654
},
650655
)
651656

0 commit comments

Comments
 (0)