fix: non-loop scrollTo offset regression#891
Merged
dohooo merged 5 commits intodohooo:mainfrom Mar 2, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: e20fd99 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@notsuhas is attempting to deploy a commit to the Caspian's Team Team on Vercel. A member of the Team first needs to authorize it. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #891 +/- ##
==========================================
+ Coverage 84.06% 84.32% +0.25%
==========================================
Files 37 37
Lines 1042 1040 -2
Branches 364 362 -2
==========================================
+ Hits 876 877 +1
Misses 67 67
+ Partials 99 96 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This fixes a non-loop
scrollTo({ index })regression where navigating backward could produce a positive offset and briefly render a blank item/state.User Impact
In
v5.0.0-beta.4, whenloop={false}and a consumer computes a previous index manually (for example with modulo arithmetic) then callsscrollTo({ index: prevIndex, animated: false }), some transitions can land in an invalid offset direction. That can surface as a blank frame/item.v5.0.0-beta.0did not show this behavior in the same usage pattern.Root Cause
useCarouselControllerused loop-style direction math insideto()for both loop and non-loop modes. In non-loop mode, moving to a lower target index could flip direction and compute a positive final offset.Fix
In non-loop mode,
scrollTo({ index })now uses direct page mapping:finalOffset = -index * sizeLoop mode keeps existing direction and wrap behavior.
Tests
Added regression coverage in
useCarouselController.test.tsx:should keep negative offsets when scrollTo() moves backward in non-loop modeshould map scrollTo({ index: 0 }) to zero offset from end in non-loop modeAlso re-ran the existing non-loop left-overscroll integration check in
Carousel.test.tsx(targeted test).Validation Run
yarn test src/hooks/useCarouselController.test.tsx --runInBand --watchman=falseyarn test src/components/Carousel.test.tsx -t "left overscroll" --runInBand --watchman=false