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

When Scrolled to bottom scrollOffset is not equal to scrollSize in Windows #175

Closed
saqlain1020 opened this issue Sep 12, 2023 · 8 comments
Closed
Assignees

Comments

@saqlain1020
Copy link

Describe the bug
Cannot determine by looking at scrollOffset, scrollSize and viewportSize that the user has scrolled to bottom.
scrollOffset + viewportSize does not equal scrollSize, the sum is usually 2-15 units different.

To Reproduce
Scroll to bottom in a virtual list then console vlist refrence and check scrollOffset,scrollSize and viewportSize to see if by any combination you can identify if user has scrolled to bottom

Expected behavior
scrollOffset should be equal to scrollSize.

Platform:

  • OS: [Windows,]
  • Browser: [Chrome]
  • Version of this package: [0.8.2]

Additional context
If we can get refrence to the html element which has the scroll bar in onScroll event listener that would be make things easier.

@inokawa inokawa changed the title When Scrolled to bottom scrollOffset is not equal to scrollSize When Scrolled to bottom scrollOffset is not equal to scrollSize in Windows Sep 12, 2023
@inokawa
Copy link
Owner

inokawa commented Sep 12, 2023

@saqlain1020
Hi, could you tell me the value of window.devicePixelRatio in your chrome browser? because it will be a problem only happens under specific dpr.

If we can get refrence to the html element which has the scroll bar in onScroll event listener that would be make things easier.

You can access html element of scroller with passing your custom component to components.Root prop like #154 (comment) .

@saqlain1020
Copy link
Author

saqlain1020 commented Sep 12, 2023

@inokawa

@saqlain1020 Hi, could you tell me the value of window.devicePixelRatio in your chrome browser? because it will be a problem only happens under specific dpr.

If we can get refrence to the html element which has the scroll bar in onScroll event listener that would be make things easier.

You can access html element of scroller with passing your custom component to components.Root prop.

window.devicePixelRatio is 1.25

@inokawa inokawa self-assigned this Sep 12, 2023
@saqlain1020
Copy link
Author

@inokawa How can i get html element ref, basically i am thinking of checking scrollHeight for determining if scrolled to bottom.
Can you write me a snippet or something, i can use a workaround like giving class to parent and using css selector to get the element, but it would be great if we can directly get the ref.
Thanks a lot!
Your library is working pretty great, and it's straight forward.

@inokawa
Copy link
Owner

inokawa commented Sep 12, 2023

Thank you!

My recommended workaround for now is just add offset for the error likescrollOffset > scrollSize - viewportSize - 1.5. It's actually used in at-bottom-detection of this lib for some PCs which has dpr like 1.25 not integer.

virtua/src/core/store.ts

Lines 223 to 224 in 146811e

scrollOffset >
getScrollOffsetMax() - SUBPIXEL_THRESHOLD

VListHandle.scrollSize returns actual scrollHeight of element currently so it may not solve the problem. However you can get the element of scroller like this:

useEffect(() => {
  const el = document.querySelector(".foo"); 
}, [])

<VList className="foo">
  {items}
</VList>

I'll try to investigate why they are not equal under some dpr.

@saqlain1020
Copy link
Author

Also there is a warning in nextjs console that useLayoutEffect should not be used in server environment, i want to use VList on client side only, so take a look at it as well, might change useLayoutEffect to useEffect

@inokawa
Copy link
Owner

inokawa commented Sep 12, 2023

Also there is a warning in nextjs console that useLayoutEffect should not be used in server environment

I implemented not to use useLayoutEffect in server like this. Maybe it isn't working for some reason with Next.js... 🤔

export const useIsomorphicLayoutEffect =
typeof window !== "undefined" ? useLayoutEffect : useEffect;

@inokawa
Copy link
Owner

inokawa commented Sep 12, 2023

The warn will be fixed in 0.8.3. Thanks!

@inokawa
Copy link
Owner

inokawa commented Sep 13, 2023

I found that scrollSize from handle has rounded value but scrollSize internally used in this lib is not. I fixed that in 0.8.4 so you can get more precise scrollSize from handle.

I close this issue because I have no idea how to reduce the error further and I think the fix made we can detect at bottom stably now like this:

if (
ref.current.scrollOffset -
ref.current.scrollSize +
ref.current.viewportSize >=
// FIXME: The sum may not be 0 because of sub-pixel value when browser's window.devicePixelRatio has decimal value
-1.5
) {

Of Course any improvements and information are welcome.

@inokawa inokawa closed this as completed Sep 13, 2023
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

2 participants