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

Erratic behaviour with onRangeChange while scrolling up #478

Open
mrooding opened this issue Jul 29, 2024 · 8 comments
Open

Erratic behaviour with onRangeChange while scrolling up #478

mrooding opened this issue Jul 29, 2024 · 8 comments

Comments

@mrooding
Copy link

Describe the bug
When using a Virtualizer with a list index component to jump to a specific point within the list, scrolling upwards really quickly after loading makes the scrollbar jitter. It continuously calls range change event handler until it reaches start index 0.

To Reproduce
Video: https://photos.app.goo.gl/j9SXEJGUyirVuCyY7

Expected behavior
It should just load the previous items once and not loop all the way back to 0

Platform:

  • OS: MacOS
  • Browser: Electron
  • Version of this package: 0.33.3
  • Version of framework: vue 3.4.27

Additional context

I'm trying to implement a virtual list that supports a list index component used for jumping to a specific index. Regular horizontal scrolling from the start of the list until the end works perfect.

After using the list index to jump to a specific offset, scrolling downwards to load higher index items works fine too. However, when scrolling upwards extremely fast seems to create a state where the scrollbar is stuck and a update loop is triggered which loads all the items until index 0 is reached.

I've tried using a normal VList instead of a Virtualizer (with scroll-ref) but that had the same effect. I've based my implementation on the feed example

Simplified usage of the component:

 <Virtualizer
      v-slot="item"
      ref="virtualizer"
      :item-size="85"
      :data="list.items"
      :scroll-ref="scrollRef"
      :shifting="shifting"
      @range-change="onRangeChange"
    >
      <component
        v-if="item"
        :key="item.index"
        :item="item"
      />
    </Virtualizer>
@inokawa
Copy link
Owner

inokawa commented Jul 30, 2024

Hi, could you make a minimal reproduction?

@mrooding
Copy link
Author

Hi @inokawa I've created an isolated electron app that's as close as possible to how the actual app functions. If possible, I'd like to share it privately. Could you let me know how I could do so?

@WalrusSoup
Copy link

I want to chime in and say I've also been experiencing this, and I have some theories on what's causing it.

When I trip the loader to load more, the load happens but the scroll has continued to move up during that same period (inertial scrolling?). Because I'm only appending 25 items to the head of the list, the visible range is immediately put back into the "go get more to load" state due to the upward momentum.

I have a really weird fix where i basically timeout the ability to load more for 1.5s, and after a mutation and a nextTick(), I move the scroll position back to where it should be (i mark the item that was at the top prior to when I started loading). This is... not great, because the scroll is still basically firing. So for end users, it kinda just feels like they are shoved back down and then it pops around.

@mrooding i think maybe you could be experiencing the same thing?

@mrooding
Copy link
Author

mrooding commented Aug 25, 2024

@WalrusSoup that's interesting. Even without this bug I noticed that the range change event handler was firing very often so I already introduced a debounce function. That didn't seem to fix it for me though. Possible, manually moving the scroll position would fix it like you did.

Would you be able to share an isolated example of your solution?

@inokawa @WalrusSoup I've stripped the example app to the bare minimum of what my overall setup looks like: https://drive.google.com/file/d/1RiToR4mq0iitkQKbbg6vQ_DdDy7ubGEi/view?usp=sharing

To reproduce:

  1. Install dependencies using pnpm install
  2. Run the app using pnpm watch
  3. Move your cursor to the right side of the window so that the list index appears
  4. Click on one of the list index options in the middle or near the end of the list (e.g. L).
  5. Try scrolling down and upwards

@inokawa
Copy link
Owner

inokawa commented Aug 28, 2024

Thanks! I'll take a look.

@inokawa
Copy link
Owner

inokawa commented Aug 28, 2024

Your application logic fetches new items in onRangeChange callback. Prepending items will change visible range so onRangeChange can be called infinitely if we don't have proper guard. So please consider adding guard.

@inokawa inokawa changed the title Erratic behaviour Erratic behaviour with onRangeChange while scrolling up Aug 28, 2024
@mrooding
Copy link
Author

@inokawa thank you for the reply. What would a proper guard look like to you?

@mrooding
Copy link
Author

mrooding commented Oct 7, 2024

Hi @inokawa I'd appreciate your input on this one. Thanks again

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

No branches or pull requests

3 participants