fix(launcher): Modal focus stealing during polling-induced re-renders - #569
Open
chundaoketa wants to merge 1 commit into
Open
fix(launcher): Modal focus stealing during polling-induced re-renders#569chundaoketa wants to merge 1 commit into
chundaoketa wants to merge 1 commit into
Conversation
The Modal useEffect had [open, onClose] as dependencies. When parent components pass inline arrow functions as onClose (which is the common pattern across all pages), any parent re-render changes onClose's reference identity. This triggers the useEffect cleanup function which calls previouslyFocused?.focus() — restoring focus to the element outside the dialog — then re-runs the effect which detects activeElement is no longer inside the panel and forcibly focuses the first focusable child. Pages like agents (5s polling), workspaces (8s), and logs (3s) all have setInterval that triggers re-renders, making the dialog's focus jump back to the first input every few seconds while a dialog is open. Fix: Store onClose in a ref (onCloseRef) so the effect no longer depends on its identity. Also deduplicate modalStack pushes to avoid accumulation on effect re-runs.
|
@chundaoketa is attempting to deploy a commit to the Raphael's projects Team on Vercel. A member of the Team first needs to authorize it. |
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.
Problem
In any dialog (New Agent, Configure, Connect, Delete confirmation, etc.), clicking an input field that is not the first one causes focus to jump back to the first input after a few seconds. This happens on all pages with open dialogs.
Root Cause
The Modal component useEffect had
[open, onClose]as dependencies. When parent components pass inline arrow functions asonClose(the common pattern across all pages), any parent re-render changesonClosereference identity. This triggers:previouslyFocused.focus()- restores focus to the element outside the dialogPages like agents (5s polling), workspaces (8s), and logs (3s) all have
setIntervalthat triggers re-renders, making the dialog focus jump back to the first input every few seconds while a dialog is open.Fix
onClosein a ref (onCloseRef) so the effect no longer depends on its reference identityonClosefrom the effect dependency array ([open]only)modalStack.pushto avoid accumulating duplicate entries on effect re-runsFiles Changed
packages/launcher/src/renderer/components/ui/Modal.tsx