fix(ScrollControls): resolve infinite scrolling issues across browsers #2508
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
There were a couple of issues with the current infinite scrolling behavior mentioned in #2507:
<ScrollControls infinite/>current scroll position is less thanscrollThreshold, leads to unable reset to top. #1615scrollTopwould never reach the actual maximum; it would always be one pixel shortWhat
These are the fixes applied for each of the issues above:
.scrollLeftis often rounded to an integer or 0.5 precision. To ensure consistent behavior across browsers, we now explicitly floor the value so it reflects the actual maximumscrollLeftcan reach. This has been tested on Chrome, Firefox, and EdgedisableScrollwas incorrectly set totrueon load. It should befalseinitially, since we already handle the first run using a separate mechanism. This flag is only needed later to prevent event bubblingscrollLefttoscrollLength, which is incorrect. It should instead be set toscrollThreshold - 1. The minus one acts as padding because just as wrapping backward, we don't set the scroll to0, but to1, so the browser triggersonScrollon the next wheel eventonWheeland updatingscrollLeft, which normally triggersonScroll. However, if we are already at the edge, this doesn’t happen. We now manually callonScrollwhen at the scroll boundary to ensure wrappingonWheelnot only for horizontal scrolling but also during scroll wrapping. This way, when the browser fails to triggeronScrollnear the edge, we can manually call it to ensure wrapping occursChecklist