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 {