Repository navigation
fix(native-chat): focus the composer after a keyboard switch between chats - #29152
Conversation
…chats The previous tab's hidden composer still held focus when the reveal hook ran, and was treated as a live text field, so the new composer never got focus. Fixes stablyai#28157
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to
|
ELI5
With two chats open, switching between them with Ctrl+1 / Ctrl+2 often left the message box unfocused, so nothing you typed went anywhere until you clicked into it. Now the message box is ready every time.
What Changed
Before: a keyboard switch between two chat tabs usually left focus on the page body. Clicking a tab worked, because the click moved focus off the old chat first.
After: the chat you switch to gets its message box focused, however you got there.
Mechanism: when a chat is revealed, it focuses its composer unless some other text field already has focus.
shouldPreserveEditableFocusdecides what counts as a text field the user is editing. Right after a keyboard switch, the previous chat's composer is stilldocument.activeElement, even though its pane is alreadyinertanddisplay: none. Chromium only moves focus to<body>a task later, after the reveal has already given up. The check now ignores a field inside a[hidden]or[inert]subtree, since nobody can be typing into it.Why
The wrong answer came from this check, so the fix goes there and not into the chat hook. The two terminal callers get the corrected answer too, and they had no reason to protect a hidden field either. Adding an explicit focus call to every keyboard tab-switch path would also work, but it would leave the check giving the wrong answer to anything else that relies on it.
[hidden], [inert]is the same selector the reveal hook already uses for focus that is about to drop.Linked Issue
Fixes #28157
Visual Proof
N/A for screenshots: nothing on screen changes except where the caret ends up. In a hidden dev build with two Claude chats, I traced
focusin/focusout/focus()over 30 alternatingactivateTabNumberShortcutswitches (the handler behind Ctrl+digit). On main, 29 of 30 ended with focus on<body>and nofocus()call. With this change, all 30 focused the new composer, and typed text went into the right chat with each draft kept.Testing
Review
Renderer-only. No wire, saved-state or platform-specific changes, so SSH, folder workspaces and mobile are unaffected.
Agent skill upstream boundary
Notes
#28987 changes the same hook for new chats in split panes. That's a separate path and doesn't cover this bug. The two changes don't conflict.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)