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}
)} +
+}