Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(web): the device screen keeps focus when typing or returning to the window #14534

Mergedhaydenkz(GitHub profile, opens in a new tab)merged 10 commits intomain fromrefs/pull/14534/headmerged by juliusmarminge View on GitHub

Problem

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 window in the capture phase and redirect into the composer unless the event comes from an editable or interactive element. [role="application"] joins the interactive list in composerFocusRedirect.ts, so they yield while the device screen is focused.
  • shouldRefocusComposerOnWindowFocus in ChatView.logic.ts now 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 because composedPath() 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 focused role="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

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 7d24a74

      Macroscope'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).
    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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_commits setting.

      • Last reviewed commit: 7d24a7494dcebe6a7266908a10ab77b22d326d1a

      Use the following commands to manage reviews:

      • @coderabbitai resume to resume automatic reviews.
      • @coderabbitai review to 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.ts
      • apps/web/src/components/ChatView.logic.ts
      • apps/web/src/components/chat/composerFocusRedirect.browser.test.ts
      • apps/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.ts
      Both 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

      Merge 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 Summary

      Architecture risk: 🔵 Low · up to eb206

      The change affects 1 system.

      Changed systems: apps/web

      Architecture 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_SELECTOR now includes [role="application"].
      • observed — Modified behavior in apps/web/src/components/ChatView.logic.test.ts: Added a test expecting shouldRefocusComposerOnWindowFocus to return false when 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: Passed 4
      Check nameStatusExplanation
      Linked Issues checkPassedIssue #19488 requires printable keys to remain on the focused Device panel screen and requires window refocus to preserve that screen. composerFocusRedirect.ts now excludes [role="application"] fr…
      Out of Scope Changes checkPassedThe 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 checkPassedThe title clearly and concisely describes the primary fix: preserving device-screen focus during typing and window refocus.
      Description checkPassedThe 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 #19488 requires printable keys to remain on the focused Device panel screen and requires window refocus to preserve that screen. composerFocusRedirect.ts now excludes [role="application"] from type-to-focus redirection. ChatView.logic.ts now 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

      Autopilot is currently an internal CodeRabbit preview.

      Comment `@coderabbitai help` to get the list of available commands.
    4. juliusmarminge added labelsmacroscope-review

    5. Note

      Written by claude-opus-5-5 on behalf of Maria

      Hi! 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.

    6. maria-rcks closed this

    7. Note

      Written by claude-opus-5-5 on behalf of Maria

      Reopening, this was closed by mistake. Sorry for the noise!

    8. maria-rcks reopened this

    9. juliusmarminge assignedjuliusmarminge

    10. 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.

    11. juliusmarminge merged this0c609ab

    12. juliusmarminge closed this

Sign in to join this conversation.