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(useVirtualList): List sometimes missing elements #2477

Merged
merged 8 commits into from Jan 4, 2023
Merged

fix(useVirtualList): List sometimes missing elements #2477

merged 8 commits into from Jan 4, 2023

Conversation

begedin
Copy link
Contributor

@begedin begedin commented Nov 25, 2022

Description

Fixes #2065

This fixes an issue that was closed, seemingly due to inactivity, but was not actually fixed.

This fixes a single scenario I was able to isolate, but I'm not sure if there are actually others. One of the added tests covers the scenario.

Additional context

The scenario I can reliably reproduce the issue in is if the original list is smaller than the capacity of the virtual list. It just doesn't render all the items in that case.

For example, render a list of 5 elements when the screen is able to show 10. With an overscan of 2, 2 + 1 elements will be rendered. With an overscan of 1, it will be 1 + 1 = 2, etc.

Extra notes

It seems that there is still some faulty logic around how overscan works. If you set the overscan to 0, based on tests, you can't really get the first item in the original list to display, possibly the last as well.

I would love to look into that, but it's a bit difficult to unravel what all the start/end variables are intended to be. Not always clear if they are 0 or 1-indexed, inclusive or exclusive, etc.

After this is accepted in, I can look into investigating that and opening a ticket.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

if (typeof itemSize === 'number')
return Math.ceil(containerHeight / itemSize)
return Math.ceil(containerSize / itemSize)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Height naming was from when list was vertical only. Size is more appropriate, IMO

Comment on lines +137 to +138
capacity = i
if (sum > containerSize)
Copy link
Contributor Author

@begedin begedin Nov 25, 2022

Choose a reason for hiding this comment

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

Moving capacity out of the if is the fix. Without this, if the original list size is smaller than what could fit in the view, we end up with a capacity of 1 + overscan

Choose a reason for hiding this comment

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

Shouldn't the same thing be done with 'offset = i' in function 'createGetOffset'?

@begedin begedin changed the title FIX 2065: List sometimes missing elements fix(useVirtualList): List sometimes missing elements Nov 25, 2022
@wheatjs wheatjs merged commit 25f6e30 into vueuse:main Jan 4, 2023
@begedin begedin deleted the fix-2065 branch January 11, 2023 07:00
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.

useVirtualList sometimes missing elements
3 participants