fix(app): prevent terminal mount from stealing focus#36576
Open
Hona wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates terminal focus behavior in the app session UI to prevent terminal mounts/restores from stealing focus, and to only focus terminals when the user explicitly requests it (toggle, tab selection, or terminal creation).
Changes:
- Introduces an explicit terminal focus-request lifecycle (
requestFocus/focusRequested/consumeFocus/cancelFocus) in the terminal context. - Updates the V2 terminal panel + terminal tabs to focus terminals only when a focus request is active, and cancels pending focus on unmount / outside focus.
- Adjusts the Terminal component to preserve/restore prior focus when
autoFocusis not explicitly requested, and expands Playwright regression coverage for focus scenarios.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/app/src/pages/session/use-session-commands.tsx | Makes terminal toggle/new commands use explicit focus requests and cancel pending focus on close. |
| packages/app/src/pages/session/terminal-panel.tsx | Adds focus-cancellation cleanup and wires onAutoFocus consumption (legacy panel). |
| packages/app/src/pages/session/terminal-panel-v2.tsx | Removes delayed focus retries and gates focusing on explicit focus requests; focuses new-terminal actions explicitly. |
| packages/app/src/context/terminal.tsx | Adds focus request state machine to the terminal workspace session and updates terminal.new to accept { focus }. |
| packages/app/src/components/terminal.tsx | Adds onAutoFocus and restores prior focus when autoFocus isn’t explicitly true. |
| packages/app/src/components/session/session-sortable-terminal-tab-v2.tsx | Requests/consumes focus on explicit tab focus actions. |
| packages/app/e2e/regression/terminal-composer-focus.spec.ts | Adds regression tests for cached-mount focus, delayed mount completion, and new-terminal focus. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
305
to
309
| <Terminal | ||
| pty={pty()} | ||
| autoFocus={opened()} | ||
| onAutoFocus={() => terminal.consumeFocus(id)} | ||
| onConnect={() => markTerminalConnected(terminalRecoveryKey(pty()), id, ops.trim)} |
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
Testing
bun run typecheckfrompackages/appNotes
upstream/devprovider/share generated SDK type mismatches; the app package typecheck passes