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

scrollToIndex leads to blank screen during inertia scroll on iOS Safari #483

Open
LookRain opened this issue Aug 6, 2024 · 8 comments
Open

Comments

@LookRain
Copy link

LookRain commented Aug 6, 2024

Describe the bug
Calling scrolLToIndex in middle of a scroll on iOS Safari has a very high chance of getting a blank screen

ScreenRecording_08-06-2024.12-48-28_1.mp4

To Reproduce

  1. go to https://inokawa.github.io/virtua/?path=/story/basics-vlist--scroll-to
  2. swipe to scroll and let the inertia scroll keeps going
  3. click on scroll to

Expected behavior
Should scroll to intended target

Platform:
iOS Safari

  • OS: [Windows, MacOS, Linux, Android, iOS]
  • Browser: [Chrome, Firefox, Safari, Edge]
  • Version of this package: [x.x.x]
  • Version of framework: [react, vue, solid-js, svelte] [x.x.x]

Additional context
I understand this probably is because of the weird thing Apple does to the scroll behavior on Safari, but is there any possible workaround this issue, like stopping the scroll before firing scrollToIndex? @inokawa

@inokawa
Copy link
Owner

inokawa commented Aug 6, 2024

Current logic defers jump compensation in iOS Safari during scrolling and freezes visible range during imperative smooth scrolling in every browsers. So smooth scroll during inertia scrolling will cause weird behavior.

@LookRain
Copy link
Author

LookRain commented Aug 6, 2024

actually it's not just smooth scrolling, in the video smooth option is false

@inokawa
Copy link
Owner

inokawa commented Aug 6, 2024

Oh, thanks. Maybe it's fixable if it happened without smooth option.

@inokawa inokawa changed the title scrollToIndex leads to blank screen during inertia scroll on Safari scrollToIndex leads to blank screen during inertia scroll on iOS Safari Aug 6, 2024
@LookRain
Copy link
Author

@inokawa
I assume if I'm able to stop the scrolling before calling scrollToIndex, this wouldn't be an issue.

Any Virtua API i can use to stop the scroll? if no, would modifying the scroll container to overflow:hidden do the trick?

many thanks!

@inokawa
Copy link
Owner

inokawa commented Aug 28, 2024

would modifying the scroll container to overflow:hidden do the trick?

I think it is the only way in iOS Safari as far as I know. Or you can disable scrollTo button while scrolling for some use case.

@LookRain
Copy link
Author

@inokawa
in your mind what would be the fix for this issue?

I'm thinking we can add a check for the scrollToIndex function, and disable scroll before the rest of the scroll logic.

if that is what you had in mind, I could try and submit a PR?

@inokawa
Copy link
Owner

inokawa commented Aug 28, 2024

Yeah, PR is welcome. I thought it may solve the problem to discard current jumps(maybe just call _flushJump()) when smooth scrolling started, but not tested yet.

For reference, Virtua locks visible range while smooth scrolling here:

_frozenRange = getRange(payload);

virtua/src/core/store.ts

Lines 209 to 214 in 63e9285

if (_frozenRange) {
return [
min(_prevRange[0], _frozenRange[0]),
max(_prevRange[1], _frozenRange[1]),
];
}

@ArianHamdi
Copy link

@inokawa I assume if I'm able to stop the scrolling before calling scrollToIndex, this wouldn't be an issue.

Any Virtua API i can use to stop the scroll? if no, would modifying the scroll container to overflow:hidden do the trick?

many thanks!

Thanks for this amazing library @inokawa

I tried this trick and worked fine:

const chatContainer = document.getElementById(chatContainerId);
if (chatContainer && isIOS) {
  chatContainer.style.overflow = 'hidden';
  setTimeout(() => {
    chatContainer.style.overflow = 'auto';
    ref.current?.scrollTo(1e8);
  }, 0);
} else {
  ref.current?.scrollTo(1e8);
}

It would be great if we can have something like this in Virtua itself.

Also not sure if it is fine to use scrollTo(1e8) to scroll to the bottom of the list. 😬

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