Skip to content

Conversation

@shunn2
Copy link
Contributor

@shunn2 shunn2 commented Dec 3, 2025

🎯 Changes

Fixes issue where getTotalSize() returns stale values when count changes during filtering/search, causing blank space or inaccessible items.

Added onChange callback to getMeasurementOptions memo that auto-notifies framework when count/measurement options change.

✅ Checklist

  • I have followed the steps listed in the Contributing guide.
  • I have tested and linted this code locally.
  • I have generated a changeset for this PR, or this PR should not release a new version.

@changeset-bot
Copy link

changeset-bot bot commented Dec 3, 2025

🦋 Changeset detected

Latest commit: 0024982

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@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

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@shunn2 shunn2 changed the title Fix: Notify framework when count changes to update getTotalSize() fix(virtual-core): Notify framework when count changes to update getTotalSize() Dec 3, 2025
@nx-cloud
Copy link

nx-cloud bot commented Dec 7, 2025

View your CI Pipeline Execution ↗ for commit 0024982

Command Status Duration Result
nx run-many --target=build --exclude=examples/** ✅ Succeeded 16s View ↗
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 6s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-08 05:53:30 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 7, 2025

More templates

@tanstack/angular-virtual

npm i https://pkg.pr.new/@tanstack/angular-virtual@1085

@tanstack/lit-virtual

npm i https://pkg.pr.new/@tanstack/lit-virtual@1085

@tanstack/react-virtual

npm i https://pkg.pr.new/@tanstack/react-virtual@1085

@tanstack/solid-virtual

npm i https://pkg.pr.new/@tanstack/solid-virtual@1085

@tanstack/svelte-virtual

npm i https://pkg.pr.new/@tanstack/svelte-virtual@1085

@tanstack/virtual-core

npm i https://pkg.pr.new/@tanstack/virtual-core@1085

@tanstack/vue-virtual

npm i https://pkg.pr.new/@tanstack/vue-virtual@1085

commit: 0024982

Copy link
Collaborator

@piecyk piecyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, great work!

Please rebase onto the latest master and update the memo to use skipInitialOnChange (added in #1088). This will ensure we avoid the extra initial notify while preserving correct onChange semantics.

After that, we can merge.

Comment on lines 649 to 652
onChange: () => {
// Notify when measurement options change as they affect total size
this.notify(false)
},
Copy link
Collaborator

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 notify call. This keeps the onChange semantics consistent (only firing when state actually changes), preserves the existing React re-render count expectations, and still fixes the stale getTotalSize issue.

With that now merged into master, you can simplify this block to

Suggested change
onChange: () => {
// Notify when measurement options change as they affect total size
this.notify(false)
},
skipInitialOnChange: true
onChange: () => {
// Notify when measurement options change as they affect total size
this.notify(this.isScrolling)
},

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 🙏

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

@piecyk piecyk merged commit 2542c5a into TanStack:main Dec 8, 2025
5 checks passed
@github-actions github-actions bot mentioned this pull request Dec 8, 2025
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.

2 participants