Fix: barcode scan lookup hangs — stop camera before fetch + add api timeout #64
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Root cause
Two issues caused barcode scans to hang on 'looking up...':
1. Camera stream blocking fetch on mobile
On mobile browsers, an active camera stream (getUserMedia) can throttle or block concurrent fetch requests. The original code called switchTab('tabAssets') after the API call, which stopped the camera via tab lifecycle — but my change to showScannedAsset kept the camera running.
Fix: Call stopScanning() BEFORE the API call in handleBarcode, not after.
2. No fetch timeout
Even without the camera issue, if the network is slow or drops packets, the fetch could hang indefinitely with no user feedback.
Fix: Added a 15s AbortController timeout to the api() wrapper function. If a request hangs, the user sees 'Request timed out — check your connection'.
Commit
3fa76cc— 'Fix barcode scan hanging: stop camera before API call + add 15s fetch timeout'