Web: Esc inside the message composer navigates away from the session (global back shortcut has no focus guard)
Summary
On web, pressing Esc while the caret is inside the message composer navigates away from the session instead of doing nothing. The global back-navigation shortcut has no focus guard, so any unmodified Esc that the composer did not explicitly consume is turned into a router back().
Steps to reproduce
- Open the web app (reproduced on a self-hosted build of
8517ab2, also present on currentmain). - Open a session whose agent is idle (no abort button shown).
- Click into the message composer and type some text — do not trigger
/or@autocomplete. - Press Esc.
Expected: nothing happens. Esc inside a <textarea> has no native browser meaning, and no browser maps it to history back.
Actual: the app leaves the session screen (modal dismissed / zen exited / router back), so the composer the user was typing in disappears.
Root cause
Esc reaches the composer first, and MultiTextInput.web.tsx only calls preventDefault() when the onKeyPress handler returns true:
AgentInput.handleKeyPress returns true for Esc in only two cases — autocomplete suggestions are open, or the agent is running and can be aborted:
With an idle agent and no suggestions, the event stays defaultPrevented === false, bubbles to window, and the global listener installed by BrowserNavigationShortcuts turns it into a back navigation:
getKeyboardNavigationDirection guards on modifiers and on defaultPrevented, but not on where focus is. The unit test browserNavigation.test.ts documents the intent as "Escape maps to back only when it is unmodified and unhandled" — "unhandled" is being approximated by defaultPrevented, and a text field that simply ignores a key is indistinguishable from one that has no opinion about it.
There is no setting to turn the shortcut off; BrowserNavigationShortcuts is mounted unconditionally in sources/app/_layout.tsx for Platform.OS === 'web'.
Suggested fix
Add a focus guard to the global handler — skip back-navigation when the event target is a text entry (<input>, <textarea>, or contenteditable), or when the target sits inside the composer. That keeps Esc working for closing modals and exiting zen mode (where focus is not in a text field) while making it inert in the composer.
An alternative, or complement, would be to give Esc a useful meaning in the composer — blur the field on the first press, and only let it fall through to navigation on a second press with the field already blurred. Either way the guard belongs in getKeyboardNavigationDirection / the onKeyDown listener rather than in each input, so future text fields inherit it.
Source: slopus/happy