#1845·happy

Web: Esc inside the message composer navigates away from the session (global back shortcut has no focus guard)

Author: sami-mp-aiCreated Sep 28, 2026Updated Sep 28, 2026

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

  1. Open the web app (reproduced on a self-hosted build of 8517ab2, also present on current main).
  2. Open a session whose agent is idle (no abort button shown).
  3. Click into the message composer and type some text — do not trigger / or @ autocomplete.
  4. 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:

https://github.com/slopus/happy/blob/8517ab232528a6046271d6010aaed663e1187dfc/packages/happy-app/sources/components/MultiTextInput.web.tsx#L117-L119

AgentInput.handleKeyPress returns true for Esc in only two cases — autocomplete suggestions are open, or the agent is running and can be aborted:

https://github.com/slopus/happy/blob/8517ab232528a6046271d6010aaed663e1187dfc/packages/happy-app/sources/components/AgentInput.tsx#L1434-L1438

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:

https://github.com/slopus/happy/blob/8517ab232528a6046271d6010aaed663e1187dfc/packages/happy-app/sources/hooks/useBrowserNavigationShortcuts.ts#L78-L86

https://github.com/slopus/happy/blob/8517ab232528a6046271d6010aaed663e1187dfc/packages/happy-app/sources/navigation/browserNavigation.ts#L87-L92

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.