Build [v1.7.0] - GitGuard - Infrastructure Hardening
This commit is contained in:
@@ -25,6 +25,7 @@ export default function Scanner({ onScanSuccess, onOCRMatch, paused }: ScannerPr
|
||||
const [isSelecting, setIsSelecting] = useState(false);
|
||||
const [capturedImage, setCapturedImage] = useState<string | null>(null);
|
||||
const isBusy = useRef(false);
|
||||
const isTransitioning = useRef(false); // Flag to track start/stop transitions
|
||||
const scannerId = "reader-container-unique";
|
||||
|
||||
useEffect(() => {
|
||||
@@ -33,11 +34,20 @@ export default function Scanner({ onScanSuccess, onOCRMatch, paused }: ScannerPr
|
||||
}
|
||||
|
||||
const startScanner = async () => {
|
||||
if (isBusy.current) return;
|
||||
if (isBusy.current || isTransitioning.current) return;
|
||||
isBusy.current = true;
|
||||
isTransitioning.current = true;
|
||||
|
||||
try {
|
||||
// If already scanning, we MUST stop it first
|
||||
if (html5QrCodeRef.current?.isScanning) {
|
||||
await html5QrCodeRef.current.stop();
|
||||
try {
|
||||
await html5QrCodeRef.current.stop();
|
||||
} catch (e) {
|
||||
console.warn("Graceful stop failed, might be in transition:", e);
|
||||
// If it's already in transition, we just return and wait for the next effect trigger
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const config = {
|
||||
@@ -85,6 +95,7 @@ export default function Scanner({ onScanSuccess, onOCRMatch, paused }: ScannerPr
|
||||
}
|
||||
} finally {
|
||||
isBusy.current = false;
|
||||
isTransitioning.current = false;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -94,11 +105,15 @@ export default function Scanner({ onScanSuccess, onOCRMatch, paused }: ScannerPr
|
||||
|
||||
return () => {
|
||||
if (html5QrCodeRef.current?.isScanning) {
|
||||
isTransitioning.current = true;
|
||||
html5QrCodeRef.current.stop()
|
||||
.then(() => {
|
||||
setIsStarted(false);
|
||||
})
|
||||
.catch(e => console.error("Stop failed", e));
|
||||
.catch(e => console.error("Unmount stop failed", e))
|
||||
.finally(() => {
|
||||
isTransitioning.current = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
}, [paused, onScanSuccess]);
|
||||
|
||||
Reference in New Issue
Block a user