diff --git a/apps/convivo/src/components/ui.tsx b/apps/convivo/src/components/ui.tsx index f9b40f6..a6314ae 100644 --- a/apps/convivo/src/components/ui.tsx +++ b/apps/convivo/src/components/ui.tsx @@ -85,19 +85,27 @@ export function QrImage({ value, size = 180 }: { value: string; size?: number }) * decoded text. The camera only works on a secure context (https or localhost); * the manual field always works. */ -export function Scanner({ onResult, label = 'Scan a lanyard QR', entryLabel = 'QR code', placeholder = '…or type the code (e.g. CVV-XXX-NNNN)', submitLabel = 'Go', disabled = false, submitDisabled = false, onEntryChange }: { onResult: (text: string) => void; label?: string; entryLabel?: string; placeholder?: string; submitLabel?: string; disabled?: boolean; submitDisabled?: boolean; onEntryChange?: (text: string) => void }) { +export function Scanner({ onResult, label = 'Scan a lanyard QR', entryLabel = 'QR code', placeholder = '…or type the code (e.g. CVV-XXX-NNNN)', submitLabel = 'Go', disabled = false, submitDisabled = false, onEntryChange, paused = false }: { onResult: (text: string) => void; label?: string; entryLabel?: string; placeholder?: string; submitLabel?: string; disabled?: boolean; submitDisabled?: boolean; onEntryChange?: (text: string) => void; paused?: boolean }) { const [manual, setManual] = useState(''); const [camError, setCamError] = useState(null); const scannerRef = useRef(null); const [camOn, setCamOn] = useState(false); - // The camera callback below is registered once on mount; without a ref it + // The camera runs only while `paused` is false. The parent sets `paused` + // while it is busy or a result sheet is open, so a scan stops the camera + // (one code at a time) and closing the sheet restarts it automatically — + // no need to navigate away to re-arm it. + // The camera callback below is registered once per start; without a ref it // would keep calling the FIRST render's onResult, whose closures over // parent state (welcome mode, selected session) are stale. Always invoke // the latest handler through this ref. const onResultRef = useRef(onResult); onResultRef.current = onResult; + // Guards against the callback firing again for the same lanyard in the + // frames between the decode and the camera actually stopping. + const scannedRef = useRef(false); useEffect(() => { + if (paused) return; let cancelled = false; const el = document.getElementById('qr-reader'); if (!el) return; @@ -114,6 +122,7 @@ export function Scanner({ onResult, label = 'Scan a lanyard QR', entryLabel = 'Q } let scanner: Html5Qrcode | null = null; + scannedRef.current = false; try { scanner = new Html5Qrcode('qr-reader'); scannerRef.current = scanner; @@ -122,8 +131,11 @@ export function Scanner({ onResult, label = 'Scan a lanyard QR', entryLabel = 'Q { facingMode: 'environment' }, { fps: 10, qrbox: { width: 220, height: 220 } }, (text) => { - if (cancelled) return; + if (cancelled || scannedRef.current) return; + scannedRef.current = true; setCamOn(false); + // One code at a time: stop the camera now; the parent's `paused` + // (busy / sheet open) keeps it off, and clearing it restarts it. scanner?.stop().catch(() => {}); onResultRef.current(text); }, @@ -147,8 +159,7 @@ export function Scanner({ onResult, label = 'Scan a lanyard QR', entryLabel = 'Q /* ignore */ } }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [paused]); return (
diff --git a/apps/convivo/src/screens/Login.tsx b/apps/convivo/src/screens/Login.tsx index 2489688..f9fba35 100644 --- a/apps/convivo/src/screens/Login.tsx +++ b/apps/convivo/src/screens/Login.tsx @@ -118,6 +118,7 @@ export function Login() {
Welcome back 👋
)} - + {busy &&
} {activeStaff && !welcomeMode && selSession && (
diff --git a/docs/releases/2026-10-19.md b/docs/releases/2026-10-19.md index 7f92734..44aa88d 100644 --- a/docs/releases/2026-10-19.md +++ b/docs/releases/2026-10-19.md @@ -118,3 +118,44 @@ the toggle: **Deployed to production 2026-10-19**: migration applied + ledger (40 → 41); `convivo-app` and `convivo-admin` rebuilt from HEAD behind the drift guard (all three changed files byte-identical to the deployed baseline). + +--- + +# Follow-up: camera stays dead after a scan (2026-10-19) + +## Symptom (reported from production) + +After a successful scan the camera stopped working — staff had to navigate to +another tab and back to re-activate it before scanning the next lanyard. + +## Cause + +`Scanner` deliberately stops the camera after decoding one code (so the same +lanyard cannot fire twice), but it only ever started the camera once, on mount. +Nothing restarted it afterwards. + +## Fix + +The camera lifecycle is now driven by a `paused` prop owned by the parent: + +- `Scan.tsx` passes `paused = busy || a sheet is open` (connect, session + result, welcome confirm, welcome result). The camera stops while a sheet is + up and **restarts automatically the moment the sheet closes** — "Scan next" + or ✕ is all it takes now. +- `Login.tsx` passes `paused = busy` so a failed scan (e.g. unknown code) + re-arms the camera immediately instead of leaving it dead. +- A `scannedRef` guard ignores duplicate callbacks in the frames between the + decode and the camera actually stopping. + +## Tests + +Real-browser smoke against a local build: staff login → Welcome mode → scan → +confirm popup → **Yes** → result sheet → **Scan next** → sheet closes and the +camera effect re-runs (fresh `Html5Qrcode` instance starts; the library clears +the element in its constructor, so re-attaching to the same div is safe). +Badge queued correctly; test data cleaned afterwards. + +## Deployment + +**Deployed to production 2026-10-19**: attendee app only (`convivo-app` +rebuilt; no migration, admin/sidecar untouched).