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

Unexpected behavior when jumping to the first item of reversed infinite list #357

Closed
mariia-mitiureva opened this issue Jan 31, 2024 · 14 comments · Fixed by #358 or #361
Closed

Unexpected behavior when jumping to the first item of reversed infinite list #357

mariia-mitiureva opened this issue Jan 31, 2024 · 14 comments · Fixed by #358 or #361
Assignees

Comments

@mariia-mitiureva
Copy link
Contributor

Describe the bug
When I jump to the first item of reversed infinite list using scrollToIndex, scrollbar stays at the top and it keeps loading more and more items. It's not reproduced if I increase a new page loading delay.
Video attached:
https://github.com/inokawa/virtua/assets/37265338/47cfab6b-058b-4449-8df9-620d0356fd93

To Reproduce
Link to the sandbox https://codesandbox.io/p/sandbox/virtua-reverse-infinite-scroll-74jnpn

Expected behavior
Scrollbar position is updated correctly as soon as new items are prepended, no matter if there is a delay or not

Platform:

  • Version of this package: 0.23.0
  • Version of framework: react 18.2.0
@inokawa
Copy link
Owner

inokawa commented Feb 1, 2024

The codesandbox looks private or not existed.

@mariia-mitiureva
Copy link
Contributor Author

Sorry, now it should be available

@inokawa
Copy link
Owner

inokawa commented Feb 1, 2024

Prepending during scrolling to was not expected. It might be better to fix the logic of imperative scrolling.

@inokawa
Copy link
Owner

inokawa commented Feb 1, 2024

I fixed the logic of scrollTo a bit in 0.23.2.
You can use ref.current.scrollTo(0) for the purpose without unintended infinite loading.

@mariia-mitiureva
Copy link
Contributor Author

For some reason codesandbox doesn't see the new package version, but I ran the same example in storybook locally (pulled the latest changes), and seems like it's still reproduced

@inokawa
Copy link
Owner

inokawa commented Feb 1, 2024

You should replace scrollToIndex(0) with scrollTo(0), otherwise it will be reproduced.

@mariia-mitiureva
Copy link
Contributor Author

I also managed to reproduce it with scrollToIndex(1), probably the main condition - close to top enough to trigger next page loading. I don't think I can use scrollTo(0) instead of scrollToIndex(1)

@mariia-mitiureva
Copy link
Contributor Author

Can it be related to this issue by the way? Behavior looks similar

@inokawa
Copy link
Owner

inokawa commented Feb 2, 2024

#346 is a problem with prepending during native scroll. This issue is a problem with prepending during imperative scroll.
They are similar issue but the solution can be a bit different.

@mariia-mitiureva
Copy link
Contributor Author

Does it make sense to reopen this issue? Since it's reproduced not only for index=0?

@inokawa
Copy link
Owner

inokawa commented Feb 2, 2024

OK. I reopened it.
It's a bit complicated problem so I recommend using a workaround like scrollTo, if you are in hurry.

@inokawa inokawa reopened this Feb 2, 2024
@mariia-mitiureva
Copy link
Contributor Author

Thanks, I will try using scrollTo + loading delay (only for jumping) for now

@inokawa
Copy link
Owner

inokawa commented Feb 4, 2024

Probably fixed in 0.23.3.

@mariia-mitiureva
Copy link
Contributor Author

mariia-mitiureva commented Feb 5, 2024

@inokawa it seems to be fixed, thanks! Your lib is awesome 🤩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants