From 336d2a5c83f6ef583b7665fb11bf4edfee97300f Mon Sep 17 00:00:00 2001 From: Hank Date: Wed, 8 Jul 2026 16:31:25 +0000 Subject: [PATCH] Fix banquet mode ignored on web: use latest onScan in camera loop The web scanner's camera loop starts once in useEffect and closed over the mount-time onScan handler, so switching modes (e.g. to Banquet) kept invoking the original ticket-check-in handler. Route onScan through a ref updated each render so the loop always calls the current handler. Native was unaffected. Co-Authored-By: Claude Fable 5 --- app/components/QRScanner.web.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/components/QRScanner.web.tsx b/app/components/QRScanner.web.tsx index 06f1f64..43ee6d5 100644 --- a/app/components/QRScanner.web.tsx +++ b/app/components/QRScanner.web.tsx @@ -10,11 +10,16 @@ export default function QRScanner({ onScan, active }: QRScannerProps) { const streamRef = useRef(null); const rafRef = useRef(null); const activeRef = useRef(active); + // Route onScan through a ref so the long-lived camera loop (started once in + // useEffect) always calls the LATEST handler — otherwise a mode switch + // (e.g. to Banquet) keeps hitting the mount-time handler. + const onScanRef = useRef(onScan); const lastScan = useRef<{ code: string; at: number }>({ code: "", at: 0 }); const [error, setError] = useState(null); const [starting, setStarting] = useState(true); activeRef.current = active; + onScanRef.current = onScan; async function start() { setError(null); @@ -45,7 +50,7 @@ export default function QRScanner({ onScan, active }: QRScannerProps) { const now = Date.now(); if (!(data === lastScan.current.code && now - lastScan.current.at < 3000)) { lastScan.current = { code: data, at: now }; - onScan(data); + onScanRef.current(data); } } } catch {