fix(slider): add async to spring animation#2978
Conversation
📝 WalkthroughWalkthroughThe Slider component's scroll position boundary logic now includes a margin offset that adjusts when state transitions between "end" and "middle/start" occur. The animation system was refactored to convert the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/components/Slider/index.tsx (1)
104-142:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winReuse
handleScroll()after the animation.These branches still recompute
isStart/isEndwith the old exact thresholds, so the new 5px margin is ignored immediately after a button-triggered slide. IfnewXlands inside that buffer, the arrow state can be wrong until the debouncedonScrollcatches up.Suggested simplification
await setX.start({ from: { x: scrollPosition }, to: { x: newX }, onChange: (results) => { if (containerRef.current) { containerRef.current.scrollLeft = results.value.x; } }, reset: true, config: { friction: 60, tension: 500, velocity: 20 }, })[0]; - if (newX === 0) { - setScrollPos({ isStart: true, isEnd: false }); - } else { - setScrollPos({ isStart: false, isEnd: false }); - } + handleScroll(); } else if (direction === Direction.RIGHT) { const newX = Math.min( scrollPosition - scrollOffset + visibleItems * cardWidth, containerRef.current?.scrollWidth ?? 0 - clientWidth ); await setX.start({ from: { x: scrollPosition }, to: { x: newX }, onChange: (results) => { if (containerRef.current) { containerRef.current.scrollLeft = results.value.x; } }, reset: true, config: { friction: 60, tension: 500, velocity: 20 }, })[0]; - if (newX >= (containerRef.current?.scrollWidth ?? 0) - clientWidth) { - setScrollPos({ isStart: false, isEnd: true }); - } else { - setScrollPos({ isStart: false, isEnd: false }); - } + handleScroll(); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/Slider/index.tsx` around lines 104 - 142, The branches that call setX.start(...) currently set isStart/isEnd manually using exact thresholds and ignore the new 5px buffer; replace the manual setScrollPos(...) logic by invoking the existing handleScroll() after the awaited animation so the same debounced/edge-buffer logic is reused. Specifically, in both Direction.LEFT and Direction.RIGHT branches, after the await setX.start(...) completes (and after containerRef.scrollLeft has been updated by the animation), call handleScroll() instead of the current setScrollPos(...) conditional blocks so arrow state is computed consistently (use the existing containerRef, newX and handleScroll function).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/components/Slider/index.tsx`:
- Around line 104-142: The branches that call setX.start(...) currently set
isStart/isEnd manually using exact thresholds and ignore the new 5px buffer;
replace the manual setScrollPos(...) logic by invoking the existing
handleScroll() after the awaited animation so the same debounced/edge-buffer
logic is reused. Specifically, in both Direction.LEFT and Direction.RIGHT
branches, after the await setX.start(...) completes (and after
containerRef.scrollLeft has been updated by the animation), call handleScroll()
instead of the current setScrollPos(...) conditional blocks so arrow state is
computed consistently (use the existing containerRef, newX and handleScroll
function).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 3468cf77-b1f5-4f1e-a3db-4e05e14e16c7
📒 Files selected for processing (1)
src/components/Slider/index.tsx
|
What do you think about coderabbit's suggestion ? |
Description
Due to the update of
react-springto v10 in #2874, the buttons of the slider in the Discover page where not working anymore.This PRs fixes this and also adds a small
marginto enable/disable the buttons when the scroll is very near the beginning/end of the scrollWidth.How Has This Been Tested?
Click on the slider buttons on the homepage
Screenshots / Logs (if applicable)
These buttons where not working anymore.

Checklist:
pnpm buildpnpm i18n:extractSummary by CodeRabbit