Fix: barcode scan lookup hangs — stop camera before fetch + add api timeout #64

Open
opened 2026-06-02 22:24:37 +00:00 by shawn · 0 comments
Owner

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'

## 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'
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shawn/canteen-asset-tracker#64