From 0819d03efbb0e42bdcdce5ea69d288c5e5891058 Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Mon, 21 Sep 2026 16:07:23 -0400 Subject: [PATCH] Measure the iOS touch offset on the device that has it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Press a row on an iPhone and the one above it reacts — but only sometimes, and only after typing. That is the shape of the keyboard displacement the app already fights in lib/viewport-guard.js: iOS slides the *visual* viewport inside the layout one, everything `position:fixed` is painted against the layout viewport, and the app and the finger disagree until something scrolls. The guard stands down while a text field has focus on purpose (touching the page there threw the keyboard back out — issue #242), and that is precisely the window this falls into. Which correction is right depends on numbers that only exist on the phone: visualViewport.offsetTop, innerHeight, the scale, whether the body is pinned. So this adds a readout instead of a guess. Open the app with `vvdebug` anywhere in the URL, type in a field, tap the row that misbehaves, and read what the viewports were at the moment of that tap — plus which element the browser believed was under the finger, which is the other half of the question ("did it hit the row above, or the row it hit is not where it is drawn?"). It renders nothing without the parameter, and removing it is this file plus one line in App.jsx. --- frontend/src/App.jsx | 3 + frontend/src/components/TouchDebug.jsx | 88 ++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 frontend/src/components/TouchDebug.jsx diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index 1cb41a6..179b364 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -38,6 +38,7 @@ import Admin from './views/Admin.jsx' import CoachChat from './views/CoachChat.jsx' import CoachIntake from './views/CoachIntake.jsx' import CoachSetup from './views/CoachSetup.jsx' +import TouchDebug from './components/TouchDebug.jsx' // last known scrollY per route, so back-navigation can put the page where it was const scrollPositions = new Map() @@ -181,6 +182,8 @@ function Shell() { + {/* Renders nothing unless the URL carries `vvdebug` — see the file for what it is for. */} + ) } diff --git a/frontend/src/components/TouchDebug.jsx b/frontend/src/components/TouchDebug.jsx new file mode 100644 index 0000000..b66d240 --- /dev/null +++ b/frontend/src/components/TouchDebug.jsx @@ -0,0 +1,88 @@ +/* Touch diagnostics, for the one bug that cannot be reproduced off a phone. + * + * On iOS the keyboard does not resize the layout viewport: it slides the *visual* viewport inside + * it. Everything `position:fixed` is painted against the layout viewport, so while that gap is + * open the app and the finger disagree — press a row and the one above it reacts. The app already + * carries lib/viewport-guard.js for it, and that module stands down while a text field has focus + * on purpose (touching the page there threw the keyboard back out — issue #242), which is exactly + * the window this falls into. + * + * A fix needs the numbers, and the numbers only exist on the device. Open the app with `vvdebug` + * anywhere in the URL (`…/?vvdebug=1`, `…/#/settings?vvdebug=1`), type in a field, tap the thing + * that misbehaves, and read the panel: it shows what the viewports were at the moment of that tap + * and which element the browser believed was under the finger. + * + * It is deliberately a separate component rather than a branch inside the app: it renders nothing + * at all unless the parameter is there, and deleting this file and its one line in App.jsx is the + * whole removal. + */ +import { useEffect, useRef, useState } from 'react' + +const enabled = () => typeof location !== 'undefined' && /[?&#]vvdebug\b/.test(location.href) + +const read = () => { + const vv = window.visualViewport + const b = document.body?.style + return { + innerHeight: Math.round(window.innerHeight), + visualHeight: vv ? Math.round(vv.height) : null, + visualTop: vv ? Math.round(vv.offsetTop || 0) : null, + visualPageTop: vv ? Math.round(vv.pageTop || 0) : null, + scrollY: Math.round(window.scrollY || 0), + scale: vv && vv.scale ? Math.round(vv.scale * 100) / 100 : null, + pinned: b?.position === 'fixed' ? (b.top || 'fixed') : 'no', + active: document.activeElement?.tagName || '—', + } +} + +export default function TouchDebug() { + const [rows, setRows] = useState([]) + const [snap, setSnap] = useState(null) + const box = useRef(null) + + useEffect(() => { + if (!enabled()) return + setSnap(read()) + const vv = window.visualViewport + const onMove = () => setSnap(read()) + + // Capture phase, so the reading is the one the browser is about to act on rather than the + // one after React has handled the tap. + const onDown = e => { + const x = Math.round(e.clientX), y = Math.round(e.clientY) + const el = document.elementFromPoint(x, y) + const label = el ? `${el.tagName.toLowerCase()}${el.className ? '.' + String(el.className).split(' ')[0] : ''} "${(el.textContent || '').trim().slice(0, 24)}"` : '—' + const line = `tap ${x},${y} → ${label} · vvTop ${read().visualTop}` + setRows(r => [line, ...r].slice(0, 6)) + } + + window.addEventListener('pointerdown', onDown, true) + window.addEventListener('touchstart', onDown, true) + vv?.addEventListener('resize', onMove) + vv?.addEventListener('scroll', onMove) + window.addEventListener('scroll', onMove) + window.addEventListener('resize', onMove) + const tick = setInterval(onMove, 500) + return () => { + window.removeEventListener('pointerdown', onDown, true) + window.removeEventListener('touchstart', onDown, true) + vv?.removeEventListener('resize', onMove) + vv?.removeEventListener('scroll', onMove) + window.removeEventListener('scroll', onMove) + window.removeEventListener('resize', onMove) + clearInterval(tick) + } + }, []) + + if (!enabled() || !snap) return null + const line = Object.entries(snap).map(([k, v]) => `${k} ${v}`).join(' ') + + return
+ {'VVDEBUG ' + line} + {rows.map((r, i) =>
{r}
)} +
+}