Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

fix: capture webcam preview refs at effect setup to prevent stale closure reads

Long9a38961b6b64
diff --git a/src/components/launch/LaunchWindow.tsx b/src/components/launch/LaunchWindow.tsx
index 852c520e..f2af0fcb 100644
--- a/src/components/launch/LaunchWindow.tsx
+++ b/src/components/launch/LaunchWindow.tsx
@@ -300,11 +300,13 @@ export function LaunchWindow() {
useEffect(() => {
let mounted = true;
let previewStream: MediaStream | null = null;
+ const initialWebcam = webcamPreviewRef.current;
+ const initialRecordingWebcam = recordingWebcamPreviewRef.current;
const startPreview = async () => {
if (
!shouldStreamWebcamPreview ||
- (!webcamPreviewRef.current && !recordingWebcamPreviewRef.current)
+ (!initialWebcam && !initialRecordingWebcam)
) {
return;
}
@@ -331,7 +333,7 @@ export function LaunchWindow() {
return;
}
- [webcamPreviewRef.current, recordingWebcamPreviewRef.current]
+ [initialWebcam, initialRecordingWebcam]
.filter((node): node is HTMLVideoElement => Boolean(node))
.forEach((videoElement) => {
videoElement.srcObject = previewStream;
@@ -351,7 +353,7 @@ export function LaunchWindow() {
return () => {
mounted = false;
- [webcamPreviewRef.current, recordingWebcamPreviewRef.current]
+ [initialWebcam, initialRecordingWebcam]
.filter((node): node is HTMLVideoElement => Boolean(node))
.forEach((videoElement) => {
videoElement.pause();