fix(scanner): camera restarts automatically after a scan (paused-driven lifecycle)

The camera stopped after decoding one code (by design, one scan at a time)
but was only ever started on mount, so it stayed dead until staff navigated
away and back. The parent now owns the lifecycle via a paused prop: Scan
pauses while busy or any sheet is open (camera re-arms when the sheet
closes), Login pauses while busy (re-arms after a failed scan). scannedRef
guards duplicate callbacks between decode and stop.
This commit is contained in:
Lago committed 2026-10-19 11:03:08 +02:00
1 parent 316f1316e6
commit c857204cfe
4 files changed
+59 -6

No files matched your search

+41
View File
@@ -118,3 +118,44 @@ the toggle:
**Deployed to production 2026-10-19**: migration applied + ledger (40 → 41);
`convivo-app` and `convivo-admin` rebuilt from HEAD behind the drift guard (all
three changed files byte-identical to the deployed baseline).
---
# Follow-up: camera stays dead after a scan (2026-10-19)
## Symptom (reported from production)
After a successful scan the camera stopped working — staff had to navigate to
another tab and back to re-activate it before scanning the next lanyard.
## Cause
`Scanner` deliberately stops the camera after decoding one code (so the same
lanyard cannot fire twice), but it only ever started the camera once, on mount.
Nothing restarted it afterwards.
## Fix
The camera lifecycle is now driven by a `paused` prop owned by the parent:
- `Scan.tsx` passes `paused = busy || a sheet is open` (connect, session
result, welcome confirm, welcome result). The camera stops while a sheet is
up and **restarts automatically the moment the sheet closes** — "Scan next"
or ✕ is all it takes now.
- `Login.tsx` passes `paused = busy` so a failed scan (e.g. unknown code)
re-arms the camera immediately instead of leaving it dead.
- A `scannedRef` guard ignores duplicate callbacks in the frames between the
decode and the camera actually stopping.
## Tests
Real-browser smoke against a local build: staff login → Welcome mode → scan →
confirm popup → **Yes** → result sheet → **Scan next** → sheet closes and the
camera effect re-runs (fresh `Html5Qrcode` instance starts; the library clears
the element in its constructor, so re-attaching to the same div is safe).
Badge queued correctly; test data cleaned afterwards.
## Deployment
**Deployed to production 2026-10-19**: attendee app only (`convivo-app`
rebuilt; no migration, admin/sidecar untouched).