Skip to content

Adapt default logic to adjust scroll position only on backward scrolling #1002

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

balzdur
Copy link

@balzdur balzdur commented May 14, 2025

This change is based on those issues: #910, #562
It tries to implement the idea from this message:

@kmpeeduwee it's default behaviour, can be disabled using shouldAdjustScrollPositionOnItemSizeChange, please checkout docs https://tanstack.com/virtual/latest/docs/api/virtualizer#shouldadjustscrollpositiononitemsizechange

Overall we should change the logic to adjust position only on scrolling backward.

Originally posted by @piecyk in #910

Disclaimer: I'm not an expert of the lib, neither someone used to contribute a lot to open source (and/or on tanstack repositories). In particular, I do not know if this should be considered breaking (since the default behaviour will change) or not.

Copy link

changeset-bot bot commented May 14, 2025

🦋 Changeset detected

Latest commit: fc4f0e2

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/angular-virtual Patch
@tanstack/lit-virtual Patch
@tanstack/react-virtual Patch
@tanstack/solid-virtual Patch
@tanstack/svelte-virtual Patch
@tanstack/vue-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

Copy link

nx-cloud bot commented May 16, 2025

View your CI Pipeline Execution ↗ for commit fc4f0e2.

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

☁️ Nx Cloud last updated this comment at 2025-05-16 15:11:41 UTC

@piecyk piecyk changed the title Adapt default logic to adjust scroll position item size change Adapt default logic to adjust scroll position only on backward scrolling May 16, 2025
Copy link

pkg-pr-new bot commented May 16, 2025

More templates

@tanstack/angular-virtual

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

@tanstack/lit-virtual

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

@tanstack/react-virtual

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

@tanstack/solid-virtual

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

@tanstack/virtual-core

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

@tanstack/vue-virtual

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

@tanstack/svelte-virtual

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

commit: fc4f0e2

@piecyk
Copy link
Collaborator

piecyk commented May 16, 2025

@balzdur Yeah, I think this makes sense as the default behavior. Adjusting the scroll position only during backward scrolling seems more intuitive and prevents unexpected jumps when resizing items. Regarding the breaking change, good question! It technically changes the default behavior, but I believe it's more of a bug fix than a breaking change since the current behavior is often not what users expect.

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