From a7d710902cc0fac0c9ff4e1cc847e6691a95eae7 Mon Sep 17 00:00:00 2001 From: Duarte Santos Date: Sun, 20 Sep 2026 19:56:42 +0200 Subject: [PATCH] =?UTF-8?q?iOS:=20the=20keyboard=20stays=20open=20?= =?UTF-8?q?=E2=80=94=20the=20viewport=20guard=20no=20longer=20blurs=20the?= =?UTF-8?q?=20field=20you=20are=20typing=20in=20(#242)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tapping the name or invite-code field on the login sheet threw the keyboard straight back out, about four times in five, and the same happened in every other sheet on iPad and iPhone. `realign()` corrects a page iOS left displaced after the keyboard closed, and it used to let go of a text field that still held focus, because WebKit does not blur an input when a button is tapped and iOS only puts the viewports back once focus has left. The guard around it is `keyboardOpen()`, which compares `innerHeight` with the visual viewport — and both of those move while the keyboard animates in, because the browser chrome collapses at the same time. Measured on iOS 26.6: `innerHeight` fell 684 → 374 while the visual viewport sat at 158, so the difference dipped back under the threshold and the keyboard read as closed roughly 100 ms after every tap. The guard then blurred the field the person had just tapped. The detector cannot be made reliable, so nothing acts on it while somebody is typing: with a text field focused, `realign()` now does nothing at all — no blur, no scroll, and no unpin of a body that a sheet has pinned. The correction still runs from `focusout`, which is when iOS actually needs it, and the two cases the blur was written for already let go of the field themselves: Workout.jsx blurs when a set is ticked, Modals.jsx when a sheet opens. Reported by FabianReitz with a screen recording, and diagnosed by hectorroaz, who instrumented a build on a real device and posted the timings that show the mid-animation misfire. --- frontend/src/lib/viewport-guard.js | 16 +++++++++++----- frontend/src/lib/viewport-guard.test.js | 25 +++++++++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/frontend/src/lib/viewport-guard.js b/frontend/src/lib/viewport-guard.js index 2ba6102..390f3b0 100644 --- a/frontend/src/lib/viewport-guard.js +++ b/frontend/src/lib/viewport-guard.js @@ -37,11 +37,17 @@ export function keyboardOpen(win = window) { export function realign(win = window) { if (keyboardOpen(win)) return false if (viewportDisplacement(win) <= 1) return false - // The keyboard is gone but a text field may still hold focus: on WebKit tapping a