-
Notifications
You must be signed in to change notification settings - Fork 512
Fix useEffect dependency and cleanup issues in onboarding steps #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix useEffect dependency and cleanup issues in onboarding steps #819
Conversation
WalkthroughThis PR refactors React hooks patterns across onboarding step components by fixing useEffect dependency arrays to include dispatch and stepIndex, adding mount guards to prevent stale closures, and introducing early returns for proper loading/error control flow handling. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested labels
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
frontend/src/components/OnboardingSteps/ServerCheck.tsx (1)
43-58: Excellent fix: Early return prevents success logic after error.The early return after showing the error dialog and scheduling exit ensures that the success-handling logic at lines 59-62 doesn't execute when there's an error. This prevents incorrect completion signals.
♻️ Duplicate comments (1)
frontend/src/components/OnboardingSteps/ThemeSelectionStep.tsx (1)
33-37: Same navigation concern as FolderSetupStep.The addition of
stepIndexto the dependency array follows the same pattern asFolderSetupStep.tsx. The effect will re-run when users navigate between steps, potentially dispatchingmarkCompletedmultiple times. The localStorage check provides a guard, but verify this is the intended behavior.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (2)
frontend/pnpm-lock.yamlis excluded by!**/pnpm-lock.yamlpnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
docs/frontend/state-management.mdfrontend/src/components/OnboardingSteps/AvatarSelectionStep.tsxfrontend/src/components/OnboardingSteps/FolderSetupStep.tsxfrontend/src/components/OnboardingSteps/ServerCheck.tsxfrontend/src/components/OnboardingSteps/ThemeSelectionStep.tsxfrontend/src/components/OnboardingSteps/UpdateStep.tsx
🧰 Additional context used
🧬 Code graph analysis (3)
frontend/src/components/OnboardingSteps/ServerCheck.tsx (2)
frontend/src/features/loaderSlice.ts (1)
hideLoader(21-24)frontend/src/features/onboardingSlice.ts (1)
markCompleted(31-42)
frontend/src/components/OnboardingSteps/UpdateStep.tsx (2)
frontend/src/features/loaderSlice.ts (2)
showLoader(17-20)hideLoader(21-24)frontend/src/features/onboardingSlice.ts (1)
markCompleted(31-42)
frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx (1)
frontend/src/features/onboardingSlice.ts (1)
markCompleted(31-42)
🔇 Additional comments (6)
docs/frontend/state-management.md (1)
238-246: LGTM! Clear guidelines added.The React Hooks Guidelines section provides practical guidance that aligns well with the code changes in this PR. Documenting these best practices helps maintain consistency across the codebase.
frontend/src/components/OnboardingSteps/AvatarSelectionStep.tsx (1)
36-42: Good refactoring with constants; same navigation concern applies.The refactoring to use
hasNameandhasAvatarconstants improves readability. However, the same concern aboutstepIndexin the dependency array applies here as in the other onboarding steps—the effect will re-run when navigating between steps.frontend/src/components/OnboardingSteps/UpdateStep.tsx (2)
26-44: TheisMountguard pattern is acceptable for preventing updates after unmount.The introduction of the
isMountflag with cleanup is a valid pattern to prevent state updates on unmounted components. The early return on line 29-31 and the conditional dispatch on line 37 properly guard against stale updates.
25-45: No changes needed. The code inUpdateStep.tsxis correctly implemented. ThecheckForUpdatesfunction is already memoized withuseCallbackand an empty dependency array in theuseUpdaterhook, making it a stable reference across renders. Including it in the effect dependency array will not cause infinite loops or performance issues.Likely an incorrect or invalid review comment.
frontend/src/components/OnboardingSteps/ServerCheck.tsx (1)
63-72: Dependency array updated consistently with other onboarding steps.Adding
dispatchandstepIndexto the dependency array aligns with the pattern applied across other onboarding components. The same navigation concern applies: ifstepIndexchanges during navigation, the effect will re-run.frontend/src/components/OnboardingSteps/FolderSetupStep.tsx (1)
33-37: Verify the actual navigation flow and stepIndex behavior: does stepIndex change when users navigate between steps? If stepIndex changes during navigation, the effect will re-run on each step change. While the localStorage guard prevents marking a step twice in succession, confirm that markCompleted is designed to handle multiple invocations safely during rapid navigation or step transitions. If idempotency is confirmed, consider adding a comment documenting this design choice; otherwise, consider using useEffectEvent or memoizing stepIndex to prevent unnecessary re-executions.
| if (mainBackendLoading || syncMicroserviceLoading) { | ||
| dispatch(showLoader('Waiting for servers to start')); | ||
| return; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Excellent fix: Early return prevents logic bugs during loading.
Adding the early return after dispatching the loader prevents the subsequent success-handling logic from executing while services are still loading. This is an essential fix that ensures proper control flow.
🤖 Prompt for AI Agents
In frontend/src/components/OnboardingSteps/ServerCheck.tsx around lines 39 to
42, ensure the early-return remains: when mainBackendLoading ||
syncMicroserviceLoading is true, dispatch showLoader('Waiting for servers to
start') and immediately return so that the subsequent success-handling logic
does not run while services are still loading; keep this control flow and remove
or guard any downstream success code that would otherwise execute during
loading.
What was fixed
useEffectdependencies in onboarding stepsFiles updated
Testing
Fixes #799