Skip to content

Commit 0429502

Browse files
Partha-dev01claude
andcommitted
Fix camera flickering in preparation + double-speed timer in video capture
- useActionCamera: defensive re-attach useEffect now gated on [isActive] instead of running every render, preventing camera flicker from continuous srcObject re-assignment - video-capture: clear existing intervals before creating new ones in startAssessment to prevent stacked timers causing 2x countdown speed Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fcd01b4 commit 0429502

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

app/hooks/useActionCamera.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,17 @@ export function useActionCamera(): UseActionCameraReturn {
240240
detectingRef.current = false;
241241
}, []);
242242

243-
// Defensive: re-attach stream when video element appears in DOM
244-
// (no deps — runs every render to catch ref changes)
243+
// Defensive: re-attach stream when video element appears in DOM.
244+
// Only runs when isActive changes (camera just started).
245245
useEffect(() => {
246+
if (!isActive) return;
246247
const video = videoRef.current;
247248
const stream = streamRef.current;
248249
if (video && stream && !video.srcObject) {
249250
video.srcObject = stream;
250251
video.play().catch(() => {});
251252
}
252-
});
253+
}, [isActive]);
253254

254255
// Cleanup on unmount
255256
useEffect(() => {

app/intake/video-capture/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ export default function VideoCapturePage() {
149149
setTimeLeft(ASSESSMENT_SECONDS);
150150
setSamplesCollected(0);
151151

152+
// Clear any existing intervals to prevent double-speed
153+
if (timerRef.current) clearInterval(timerRef.current);
154+
if (biomarkerTimerRef.current) clearInterval(biomarkerTimerRef.current);
155+
152156
// Countdown timer
153157
timerRef.current = setInterval(() => {
154158
setTimeLeft((t) => {

0 commit comments

Comments
 (0)