refactor: use functional state updates in hero carousel callbacks#1021
Open
mvanhorn wants to merge 1 commit intoMODSetter:devfrom
Open
refactor: use functional state updates in hero carousel callbacks#1021mvanhorn wants to merge 1 commit intoMODSetter:devfrom
mvanhorn wants to merge 1 commit intoMODSetter:devfrom
Conversation
There was a problem hiding this comment.
Review by RecurseML
🔍 Review performed on 947def5..490510f
✨ No bugs found, your code is sparkling clean
Owner
|
@mvanhorn Thanks. Can you fix the merge conflicts? |
Switched goTo, goToPrev, and goToNext from depending on activeIndex to using functional setState updates. Removed activeIndex from the autoplay effect dependency array since the timer callback already uses a functional update. Callbacks are now stable references. Fixes MODSetter#951
490510f to
298e658
Compare
|
@mvanhorn is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
Rebased onto main and resolved merge conflicts in 298e658. |
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
Refactored carousel navigation callbacks to use functional state updates, making them stable references that don't change on every index update.
Why this matters
goTo,goToPrev, andgoToNexthadactiveIndexin their dependency arrays. Every slide change recreated these callbacks, causing unnecessary re-renders downstream. Functional updates read the previous state directly, so the callbacks become stable.Changes
surfsense_web/components/ui/hero-carousel.tsx: ConvertedgoTo,goToPrev,goToNextto usesetActiveIndex((prev) => ...). RemovedactiveIndexfrom the autoplayuseEffectdependency array (thesetTimeoutcallback already used a functional update). All threeuseCallbackhooks now have empty dependency arrays.Testing
Carousel behavior is identical - same navigation, same animation direction logic. The direction ref is set inside the functional updater before returning the new index.
Fixes #951
Retargeted to
devper @MODSetter's request.High-level PR Summary
This PR refactors the hero carousel navigation callbacks (
goTo,goToPrev,goToNext) to use functional state updates instead of depending onactiveIndex. This optimization makes the callback references stable, preventing unnecessary re-renders in child components whenever the slide index changes. The autoplay effect dependency array is also cleaned up by removingactiveIndexsince the timeout callback already uses functional updates.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_web/components/ui/hero-carousel.tsx