Guard async input focus after unmount#1004
Conversation
Skip focusing when the config read completes after InputBox has unmounted. This prevents a null-ref exception without changing mounted behavior.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUpdated ChangesInput focus safety
Estimated code review effort: 1 (Trivial) | ~2 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
PR Summary by QodoGuard InputBox focus when async config resolves after unmount
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
There was a problem hiding this comment.
Code Review
This pull request introduces optional chaining to safely focus the input box, preventing errors if the ref is not yet set. The review feedback suggests further improving the robustness of this asynchronous effect by handling potential promise rejections and implementing a cleanup flag to prevent executing callbacks after the component has unmounted.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge OverviewThe single-line change in Adjacent robustness concerns raised by Files Reviewed (1 file)
Reviewed by hy3:free · Input: 29.6K · Output: 4.5K · Cached: 96.5K |
There was a problem hiding this comment.
Pull request overview
This PR prevents a runtime error in the InputBox component by safely guarding a deferred focus() call that can occur after the component has unmounted (e.g., while getUserConfig() is still resolving from extension storage).
Changes:
- Replaced a direct
inputRef.current.focus()call with optional chaining (inputRef.current?.focus()) to avoid throwing when the ref is cleared on unmount.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Guard the deferred input focus when
InputBoxunmounts before the user configuration finishes loading.Context
getUserConfig()reads extension storage asynchronously. If the component unmounts before that read completes, the textarea ref is cleared and callingfocus()throws. Optional chaining preserves the mounted behavior while making the unmounted path a no-op.Summary by CodeRabbit