-
-
Notifications
You must be signed in to change notification settings - Fork 412
fix(virtual-core): Notify framework when count changes to update getTotalSize() #1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+24
−0
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
73f744b
Fix: Notify framework when count changes to update getTotalSize()
shunn2 04f12ca
feat: add changeset
shunn2 680867c
Merge remote-tracking branch 'upstream/main'
shunn2 0024982
refactor: apply skipInitialOnChange and use isScrolling parameter in …
shunn2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shunn2 I created a PR earlier (#1088) that adds an initialization guard to the memo system so we avoid the extra initial
notifycall. This keeps theonChangesemantics consistent (only firing when state actually changes), preserves the existing React re-render count expectations, and still fixes the stalegetTotalSizeissue.With that now merged into
master, you can simplify this block toThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@piecyk Thank you for the helpful changes!
I think your work will lead to even better results.
I will reflect your feedback and let you know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0024982
I applied your review. Thanks 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passing this.isScrolling is correct here, as options can change while the user is scrolling, and in that case we do want the framework to know the update happened in a scrolling context. Using this.isScrolling keeps the onChange notification semantics aligned with the rest of the virtualizer and preserves the adapters’ scroll-specific optimizations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree. Thanks for the explanation.