Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changeset/notify-on-count-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@tanstack/virtual-core': patch
'@tanstack/react-virtual': patch
'@tanstack/vue-virtual': patch
'@tanstack/svelte-virtual': patch
'@tanstack/solid-virtual': patch
'@tanstack/angular-virtual': patch
'@tanstack/lit-virtual': patch
---

Fix: Notify framework when count changes to update getTotalSize()

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.

**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).

**After**: Height updates automatically when count changes, providing the correct user experience.

This fix applies to all framework adapters and has minimal performance impact (< 0.1ms per change).
5 changes: 5 additions & 0 deletions packages/virtual-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,11 @@ export class Virtualizer<
},
{
key: false,
skipInitialOnChange: true,
onChange: () => {
// Notify when measurement options change as they affect total size
this.notify(this.isScrolling)
},
},
)

Expand Down
Loading