Skip to content

Fix infinite scrollToBottom method #390

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

Merged
merged 1 commit into from
Aug 25, 2022

Conversation

korungg
Copy link
Contributor

@korungg korungg commented Aug 14, 2022

What kind of this PR? (check at least one)

  • Bugfix

Other information:

In certain condition, the method scrollToBottom stuck in infinite loop due to this recursive statement.

setTimeout(() => {
  if (this.getOffset() + this.getClientSize() < this.getScrollSize()) {
    this.scrollToBottom()   
  }
}, 3)

The condition for checking whether scroll is at bottom or not equals to below.

scroller.scrollTop + scroller.clientHeight < scroller.scrollHeight

It works usually, but in case that clientHeight is non-integer value, there can be a problem.
Since user agents round those values(in my case, Chrome), sum of scrollTop and clientHeight can be 1px smaller than scrollHeight, though scroll is at bottom.

For example, this was my case.

real clientHeight: 533.41
real scrollHeight: 1511.58

rounded clientHeight: 533
rounded scrollHeight: 1512
scrollTop(double, not rounded): 978

scrollTop + clientHeight = 1511 // smaller than scrollHeight though scroll is at bottom

I'm not sure how scrollTop value is calculated internally, but tiny change can fix the problem. (https://stackoverflow.com/a/32283147)

@tangbc tangbc merged commit feb2135 into tangbc:master Aug 25, 2022
bimalghartimagar pushed a commit to bimalghartimagar/vue-virtual-scroll-list that referenced this pull request Jan 21, 2024
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

Successfully merging this pull request may close these issues.

2 participants