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

[Bug Report][3.7.1] v-virtual-scroll will not scroll to newly created item using scrollToIndex #20482

Open
griffinallen opened this issue Sep 16, 2024 · 10 comments
Assignees
Labels
C: VVirtualScroll T: enhancement Functionality that enhances existing features

Comments

@griffinallen
Copy link

Environment

Vuetify Version: 3.7.1
Vue Version: 3.5.6
Browsers: Chrome 128.0.0.0
OS: Windows 10

Steps to reproduce

  1. Create the virtual scroll container and initialize it with a bunch of random items
  • the list must extend beyond the height of the container
  • the container must have the height and item-height properties
  1. Create a button for adding an item to the list
  2. Upon clicking the button, add an item to the list and use "scrollToIndex" with the index being the length of the list

Expected Behavior

The list should be scrolled so that the newest added item is now visible.

Actual Behavior

The list scrolls such that the second to last item is visible, but the newly added item is still not visible.

Reproduction Link

https://play.vuetifyjs.com/#...

@KaelWD
Copy link
Member

KaelWD commented Sep 17, 2024

It has a frame debounce, you will have to use requestAnimationFrame instead of nextTick:

function calculateVisibleItems () {
cancelAnimationFrame(raf)
raf = requestAnimationFrame(_calculateVisibleItems)
}

scrollToIndex should be async and wait for render before returning.

setTimeout(50) might work sometimes but will break if you get a frame that takes over 50ms.

@KaelWD KaelWD added T: enhancement Functionality that enhances existing features C: VVirtualScroll labels Sep 17, 2024
@KaelWD KaelWD added this to the v4.0.0 (Revisionist) milestone Sep 17, 2024
@griffinallen
Copy link
Author

It has a frame debounce, you will have to use requestAnimationFrame instead of nextTick:

function calculateVisibleItems () {
cancelAnimationFrame(raf)
raf = requestAnimationFrame(_calculateVisibleItems)
}

scrollToIndex should be async and wait for render before returning.

setTimeout(50) might work sometimes but will break if you get a frame that takes over 50ms.

I have tried your instructions and it solves one part of the issue. When you are at the bottom of the list and add another item, it now displays the next item. However, if you are not add the bottom of the list and add another item, it will still scroll to the second to last item in the list.

Maybe I have misunderstood your instructions. Can you provide a working example?

See my code here:
https://play.vuetifyjs.com/#eNptUslu2zAQ/ZUH9RAXpRe5ddoattFcCvTc3OIcWImOiVKUwsVwIOjfMyTlRUkOEsl5b9Y3D21mTTG9a5rJwYtsma2cqBrFndhsNbA6jHnTxGt8FLV2XGphelM0/nMavwoli//rbcbLcvR5m23oXE0jdk09SOM8V2NbmFqpEwAYsSPfHv2bwOwCLyVVZYkRz2tkL+TT3hGSz2bN8Z3P+IzPFxfwXBHVdGoXn0qx414FbovgyyB1KY7oqJuLQ3AxsO5FCWKm8EvMFyH5gBaI5aZtQ6iuW03pMYgydZchxuf13JPp7bxOOhAwFCJYkk6DOPQkR9k4WOF8klFWTW0c2jByBi2O7p6EQ4edqSvc0BLcBEeAMliHgSRYBy+S9wxHPXrzQ84wZ/jK8I1hwXDL8J3hB8NPhnxGH+E5EXJi5ETJiZPfPlK0EI/bF11g53XhZK0R1whtajhmmRy48mLSeLsfXRuU0E9ujy/IY1049zSiAOvNKUbYsWcvrLvTsuIhx2/DK/GWhGHHfY40/vv6T1iID7L3mYGuv6WzC3okBWj2Wce0Vyr+Hl8B9cQQDQ==

@MaxenceMouchard
Copy link

MaxenceMouchard commented Oct 3, 2024

This look like my closed issue

@griffinallen
Copy link
Author

This look like my closed issue

Did your solution work for you? I still seem to get the same error with your solution.

If you are already on the last element and add another, it correctly scrolls to the newly added element. However, if you aren't at the bottom of the list, it scrolls to the second to last element.

@jflemingframe
Copy link

also affecting me

@jflemingframe
Copy link

what i had going on was after scrolling to bottom, a moment later the scrollHeight would increase by an item's height. The list size wasn't changing.
Ended up doing setTimeout 250ms and doing requestAnimationFrame scrollToIndex again after the initial scroll.

@griffinallen
Copy link
Author

griffinallen commented Oct 17, 2024

what i had going on was after scrolling to bottom, a moment later the scrollHeight would increase by an item's height. The list size wasn't changing. Ended up doing setTimeout 250ms and doing requestAnimationFrame scrollToIndex again after the initial scroll.

This works for me too. Still hoping the correct fix gets implemented soon, but this works for the time being.

@KaelWD KaelWD self-assigned this Oct 29, 2024
@rousos87
Copy link

Hi @KaelWD,

I am encountering the same issue with onMounted. I am trying to go to the last item; however, it displays the previous item instead. I have also attempted to resolve this using setTimeout, but without luck.

VPlay

Thanks

@griffinallen
Copy link
Author

Hi @KaelWD,

I am encountering the same issue with onMounted. I am trying to go to the last item; however, it displays the previous item instead. I have also attempted to resolve this using setTimeout, but without luck.

VPlay

Thanks

Here's a workaround fix for you. Should be okay until the proper solution is implemented.

https://play.vuetifyjs.com/#eNqVUcFO6zAQ/JVR3oEiuW2c9/qAqq3EkQMneqMcotQFC9eOErsURfl31nbTNHDiEMfemZ3dnX1ukroqpvdlOTk4kcyThRX7UuVWrDYaWBzGeVmGa3gURttcalGdQiF4kJV1uRrXRWWU6gCgErvlJjmhTxFMenguqVRNjPC/RN6EfH2zhGRpWh5/5Ix7fNaD546op24G/NmKXe6U5zbwuQxSb8UR7Sa5SPApFWr7qQQxo/wc2cwXH9A8cbtqGi/VtospPQYqU9s7E56XZsbQd786cwkYuusj0fyBDj0pUZYWtbAu7kbuS1NZNN5yBi2Odi2LdwajH43TVmzRYleZPa5oyVdeA6BitcVgO1h6gdF1D4fVnMLPsVHOkDH8ZfjHMGP4z3DDcMtwx8BT+gjnRODE4EThxOFE4sTiROPEy1LmtV6okP/n9acusHO6sNJoRFtG12hiwUGLk0OunJhEzto8+GWOsjS0TEofubTn+eMg8D6t5V4YZ0ekulx1wr+SbmnaeG/9cXZ2KNn1Hnh0LqZxV7SlpGXaKRWOly8TLQ2Z

@rousos87
Copy link

Hi @griffinallen,

I tested it and is working. Quick fix until the proper solution. Thanks for the help, greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: VVirtualScroll T: enhancement Functionality that enhances existing features
Projects
None yet
Development

No branches or pull requests

5 participants