Skip to content

refactor: move onboarding animation state into event handlers#1024

Open
qorexdev wants to merge 2 commits intoMODSetter:devfrom
qorexdev:fix/onboarding-animation-state-in-handlers
Open

refactor: move onboarding animation state into event handlers#1024
qorexdev wants to merge 2 commits intoMODSetter:devfrom
qorexdev:fix/onboarding-animation-state-in-handlers

Conversation

@qorexdev
Copy link
Copy Markdown

@qorexdev qorexdev commented Mar 28, 2026

Summary

Fixes #1017.

shouldAnimate and contentKey in TourTooltip were driven by a useEffect watching stepIndex. Since stepIndex only ever changes from user-triggered handleNext / handlePrev, the effect is unnecessary.

Changes

  • Removed the useEffect (lines 180–188) that set shouldAnimate / contentKey on stepIndex change
  • Removed contentKey state and prevStepIndexRef — both were always equal to stepIndex; replaced key={contentKey} with key={stepIndex} directly
  • Lifted shouldAnimate state to the parent OnboardingTour; set setShouldAnimate(true) inside handleNext and handlePrev when the step actually changes
  • Passed shouldAnimate and onAnimationEnd as props to TourTooltip

Acceptance criteria checklist

  • No useEffect for animation state in TourTooltip
  • contentKey state variable removed; stepIndex used directly as the animation key
  • Step transitions still animate correctly (fade-in slide)
  • onAnimationEnd callback still resets shouldAnimate to false

High-level PR Summary

This PR refactors the onboarding tour animation logic by eliminating an unnecessary useEffect that was watching stepIndex changes. The animation state (shouldAnimate) is now lifted to the parent OnboardingTour component and set directly within the handleNext and handlePrev event handlers. Additionally, the redundant contentKey state variable and prevStepIndexRef are removed since they were always equal to stepIndex, which is now used directly as the animation key. This simplifies the component structure while maintaining the same fade-in slide animation behavior.

⏱️ Estimated Review Time: 5-15 minutes

💡 Review Order Suggestion
Order File Path
1 surfsense_web/components/onboarding-tour.tsx

Need help? Join our Discord

Analyze latest changes

Remove useEffect that watched stepIndex to drive shouldAnimate/contentKey.
stepIndex only changes from handleNext/handlePrev, so set shouldAnimate
directly in those handlers. Replace contentKey state (always equal to
stepIndex) with stepIndex as the animation key.

Fixes MODSetter#1017
Copy link
Copy Markdown

@recurseml recurseml bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review by RecurseML

🔍 Review performed on 947def5..3b33a3e

✨ No bugs found, your code is sparkling clean

✅ Files analyzed, no issues (1)

surfsense_web/components/onboarding-tour.tsx

Copy link
Copy Markdown

@JiwaniZakir JiwaniZakir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactor cleanly removes the useEffect/useRef pattern in TourTooltip by placing setShouldAnimate(true) at the call sites in handleNext and handlePrev — this makes the causality explicit and easier to follow. However, if any other navigation paths exist in OnboardingTour (e.g., keyboard shortcuts or a direct step-jump handler not shown in this diff), they would silently skip the animation since setShouldAnimate(true) would need to be added there too; the old useEffect approach was immune to this since it reacted to any stepIndex change regardless of source.

The onAnimationEnd prop is passed as an inline arrow function (() => setShouldAnimate(false)) at line 769, which creates a new function reference on every render of OnboardingTour. This is harmless today, but if TourTooltip is ever wrapped in React.memo for performance, it will defeat memoization — wrapping it in useCallback alongside handleNext/handlePrev would be more consistent with the existing pattern in the file.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 28, 2026

@qorexdev 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.

Copy link
Copy Markdown
Author

@qorexdev qorexdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catches, thanks for the review.

On the keyboard/direct-jump concern: Looking at the current implementation, the only keyboard handler in OnboardingTour is the Escape key which calls setIsActive(false) — it doesn't navigate between steps. So there's no silent path today, but you're right that if arrow-key navigation or a step-jump handler is added later, it would need an explicit setShouldAnimate(true). Worth keeping in mind.

On useCallback for onAnimationEnd: Valid — it was inconsistent with the pattern used for handleNext, handlePrev, etc. Extracted it into handleAnimationEnd = useCallback(() => setShouldAnimate(false), []) in the latest commit.

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