Skip to content
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

fix(virtual-core): fix total size calculation for single item in multi-lane #967

Merged
merged 3 commits into from
Mar 31, 2025

Conversation

greenblues1190
Copy link
Contributor

@greenblues1190 greenblues1190 commented Mar 28, 2025

This is a follow-up to #961. The original issue still occurs when there's only one item in a multi-lane layout.

This PR changes the loop condition in getTotalSize() to handle cases where only one item exists in multi-lane. The previous condition skipped the loop when endIndex === 0, which caused the total size to be incorrectly calculated as 0.

I used the following test to verify the fix locally:

test("should return correct total size with single item in multi-lane", () => {
  const virtualizer = new Virtualizer({
    count: 1,
    lanes: 2,
    getScrollElement: () => null,
    estimateSize: () => 50,
    scrollToFn: vi.fn(),
    observeElementRect: vi.fn(),
    observeElementOffset: vi.fn(),
  });
  expect(virtualizer.getTotalSize()).toBe(50);
});

This is a fairly specific edge case, so I didn’t include the test in the commit.
Happy to add it if you think it’d be useful to include in the suite!

Fixes #963

Copy link

changeset-bot bot commented Mar 28, 2025

⚠️ No Changeset found

Latest commit: d82f15f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@piecyk
Copy link
Collaborator

piecyk commented Mar 28, 2025

Thanks, @greenblues1190! Let's add the test. Overall, the tests need some attention. The plan is to refactor the current unit tests a bit and add browser testing using Playwright.

Copy link
Contributor

@soren121 soren121 left a comment

Choose a reason for hiding this comment

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

If this is an off-by-one, then the condition on L1165 also needs to be adjusted (it's essentially the same loop.)

@greenblues1190
Copy link
Contributor Author

@piecyk Test added!

@soren121 You're right, I’ve updated the condition too.

Copy link

nx-cloud bot commented Mar 31, 2025

View your CI Pipeline Execution ↗ for commit d82f15f.

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

☁️ Nx Cloud last updated this comment at 2025-03-31 06:28:27 UTC

Copy link

pkg-pr-new bot commented Mar 31, 2025

Open in Stackblitz

More templates

@tanstack/angular-virtual

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

@tanstack/lit-virtual

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

@tanstack/solid-virtual

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

@tanstack/react-virtual

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

@tanstack/svelte-virtual

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

@tanstack/virtual-core

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

@tanstack/vue-virtual

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

commit: d82f15f

@piecyk piecyk merged commit e6504e7 into TanStack:main Mar 31, 2025
4 checks passed
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.

getTotalSize() returns 0 when using multiple lanes with a single item
3 participants