fix(web): the device screen keeps focus when typing or returning to the window #14534
main fromrefs/pull/14534/head·merged by juliusmarminge View on GitHubProblem#
With the Android emulator or iOS simulator screen focused in the Device panel, two window-level focus paths pulled input away from the device. Fixes #19488.
- Typing letters and digits sent them to the composer instead of the device. Backspace, Enter, and arrows still reached the device, so only printable keys were affected.
- Leaving the T3 Code window and coming back moved focus from the device screen to the composer.
Change#
The device screen in DeviceStreamView is a focusable role="application" element that forwards keys to the device. That ARIA role means the widget handles its own keyboard input, and the two paths now treat it that way:
- Type-to-focus and paste-to-focus listen on
windowin the capture phase and redirect into the composer unless the event comes from an editable or interactive element.[role="application"]joins the interactive list incomposerFocusRedirect.ts, so they yield while the device screen is focused. shouldRefocusComposerOnWindowFocusinChatView.logic.tsnow leaves a focused[role="application"]element alone, next to the existing terminal, dialog, and popup exceptions.
The device screen is the only role="application" element in the web app. Pasting while the device screen is focused now does nothing, which triage on #19488 accepted. Global shortcuts and modifier chords are unaffected: they never took the type-to-focus path.
Based on the original fix by @haydenkz in this PR; the implementation is theirs, with the new entries kept in the lists' existing order.
Tests#
Three focused cases across two files:
ChatView.logic.test.ts: the refocus check leaves a focused device screen alone (from the original PR).composerFocusRedirect.browser.test.ts(new, runs in Chromium becausecomposedPath()is only populated during a real dispatch): a letter typed on plain chat content still redirects to the composer, and a letter typed on a focusedrole="application"element does not.
Each case fails when its selector entry is removed and passes with it. vp test run on both files: 140/140. vp run typecheck for apps/web, scoped lint and format checks pass.
Verification limits#
This is a Linux headless run with no simulator host, so the Device panel could not be driven end to end here. The author's recordings on the original PR show the before and after with an Android emulator. Not verified: iOS simulator (macOS), the Electron desktop shell, Windows.
Taken over with Claude Opus 5.5 (tests, review), Claude Fable 5.1 (implementation), and GPT-6 Sol (review) through T3 Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.- Last reviewed commit: 7d24a7494dcebe6a7266908a10ab77b22d326d1a
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
- ▶️ Resume reviews
- 🔍 Trigger review
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
75c5d03f-8b3d-4263-aa33-7301ec29a8e8
📥 Commits
-
Reviewing files that changed from the base of the PR and between eb206c680870756c8ee063817b251a2cd0515cfb and 7d24a7494dcebe6a7266908a10ab77b22d326d1a.
📒 Files selected for processing: 4
-
apps/web/src/components/ChatView.logic.test.tsapps/web/src/components/ChatView.logic.tsapps/web/src/components/chat/composerFocusRedirect.browser.test.tsapps/web/src/components/chat/composerFocusRedirect.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.
-
📝 Walkthrough
-
The type-to-focus selector and the window refocus check now treat elements with
role="application"as focus-owning contexts. Tests cover input redirection and composer refocusing.Changes: Input focus
Layer / File(s) Summary Handle application-owned focus
apps/web/src/components/chat/composerFocusRedirect.ts,apps/web/src/components/ChatView.logic.ts,apps/web/src/components/chat/composerFocusRedirect.browser.test.ts,apps/web/src/components/ChatView.logic.test.tsBoth focus paths now exclude elements with [role="application"]. Browser tests verify that typing on a chat element redirects to the composer and typing on an application element does not. A unit test verifies that focus inside an application suppresses composer refocusing.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
juliusmarminge
### Architecture SummaryMerge Risk: ⚪ Minimal · up to
7d24a-
The change appears ready to merge after normal checks; no unresolved issue is established that would prevent device-screen focus from being preserved.
Architecture risk: 🔵 Low · up to
eb206The change affects 1 system.
Changed systems:
apps/webArchitecture concerns No architecture-level concerns identified.
Review details
-
Systems and components
- observed — apps/web (ui) was modified; 3 changed files map to changed impact.
Before / after behavior
- observed — Modified behavior in apps/web/src/components/chat/composerFocusRedirect.ts:
TYPE_TO_FOCUS_INTERACTIVE_SELECTORnow includes[role="application"]. - observed — Modified behavior in apps/web/src/components/ChatView.logic.test.ts: Added a test expecting
shouldRefocusComposerOnWindowFocusto returnfalsewhen the focused element is inside an application. - observed — Modified behavior in apps/web/src/components/ChatView.logic.ts: The focus-exclusion selector now includes
[role="application"]; previously, elements within that role did not block composer refocusing.
Pre-merge checks:
4-
Check name Status Explanation Linked Issues check Issue #19488requires printable keys to remain on the focused Device panel screen and requires window refocus to preserve that screen.composerFocusRedirect.tsnow excludes[role="application"]fr…Out of Scope Changes check The diff changes only the two focus selectors and adds focused regression tests for issue #19488. The test changes directly verify the required typing and window-refocus behavior. No unrelated product…Title check The title clearly and concisely describes the primary fix: preserving device-screen focus during typing and window refocus. Description check The description covers the problem, affected behavior, implementation, issue reference, focused tests, verification results, and known verification limits. It is sufficiently complete for the requeste… Full details: Linked Issues check
-
Explanation
Issue
#19488requires printable keys to remain on the focused Device panel screen and requires window refocus to preserve that screen.composerFocusRedirect.tsnow excludes[role="application"]from type-to-focus redirection.ChatView.logic.tsnow excludes the same role from composer refocus. Tests cover both paths. The change also preserves composer redirection for ordinary chat content.
Full details: Out of Scope Changes check
-
Explanation
The diff changes only the two focus selectors and adds focused regression tests for issue
#19488. The test changes directly verify the required typing and window-refocus behavior. No unrelated product behavior or unrelated files are changed.
Full details: Description check
-
Explanation
The description covers the problem, affected behavior, implementation, issue reference, focused tests, verification results, and known verification limits. It is sufficiently complete for the requested change.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment `@coderabbitai help` to get the list of available commands.Autopilot is currently an internal CodeRabbit preview.
juliusmarminge added labelsmacroscope-review
coderabbitai[bot](GitHub profile, opens in a new tab) approved these changes
Note
Written by
claude-opus-5-5on behalf of MariaHi! We are cleaning up open PRs, and this one does not say which model or harness was used to create it. If this change is really important, we recommend rebuilding the PR with a newer model and noting the model and harness in the PR description.
maria-rcks closed this
Note
Written by
claude-opus-5-5on behalf of MariaReopening, this was closed by mistake. Sorry for the noise!
maria-rcks reopened this
haydenkz(GitHub profile, opens in a new tab) changed the title
juliusmarminge assignedjuliusmarminge
Taking over this one. I'll trim the tests to what proves the behaviour, rebuild the change against current main, verify it, and push to this branch.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
juliusmarminge merged this0c609ab
juliusmarminge closed this
Sign in to join this conversation.
Approvability#
Verdict: Approved at
7d24a74Macroscope's review found this PR approvable — This narrowly fixes existing device-screen focus behavior by preventing chat-level typing and window-focus handlers from stealing input from the device widget. The production scope is small, the affected role is an existing device component, and focused tests cover both paths.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).