Mobile: composer stranded mid-screen after sending — --keyboard-height goes stale because visualViewport resize is its only writer
Describe the bug
On a phone, a session renders fine until the first message is sent. Pressing send dismisses the keyboard, but the composer stays where the keyboard's top edge was — roughly mid-screen — and the bottom half of the page is empty background. Every subsequent send reproduces it. Rotating the device or switching tabs and back restores the layout.
A secondary symptom of the same stuck state: while the shell is stranded, tapping the visible composer sometimes fails to bring the keyboard up at all — where iOS draws the input and where it hit-tests it no longer agree.
To reproduce
- Open any session in a mobile browser or the installed PWA
- Tap the composer — keyboard opens, layout adjusts correctly
- Type a message and send it
- Keyboard dismisses; the composer remains mid-screen with dead space below it
Expected behavior
When the keyboard hides, the workspace shell returns to full height and the composer sits at the bottom of the screen.
Analysis (against v1.37.3; the code is unchanged on current main)
The workspace shell is fixed inset-0 with bottom: var(--keyboard-height, 0px) (ProjectWorkspaceShell.tsx:20). That variable's only writer is useVisualViewportKeyboardOffset.ts, which computes window.innerHeight - visualViewport.height inside a single visualViewport resize listener.
The keyboard-hide after a send is not a user-initiated blur — the composer re-render moves focus — and in that path iOS Safari (especially in standalone/PWA display mode) does not reliably emit visualViewport resize. When that one event is missed there is no recovery path: no focusout handling, no re-read, no clamp. The stale offset keeps the shell lifted indefinitely.
Two facts make this cleanly fixable:
- The
visualViewportvalues stay live even when its events go missing, so re-reading them on other signals is sufficient — no polling needed. - Without a focused editable element there is no keyboard, so the offset can always be clamped to 0 in that state.
Suggested fix
Recompute on focus changes (with a short re-check to outlast the keyboard animation) and clamp to 0 when nothing editable has focus — see the linked PR.
We have been running exactly this logic (injected into the served index.html of a self-hosted 1.37.3) and it resolves both symptoms.
Environment
- Server: self-hosted v1.37.3 (npm package
@cloudcli-ai/cloudcli), Linux/Docker - Client: iPhone, iOS Safari — both as a Safari tab and installed as a PWA
Source: siteboon/claudecodeui