Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(editor): don't schedule a teardown for an AudioContext that never existed

EtienneLescotd29c481980d1
diff --git a/src/components/ai-edition/VirtualPreview.tsx b/src/components/ai-edition/VirtualPreview.tsx
index 6a49ce61a..d202d0084 100644
--- a/src/components/ai-edition/VirtualPreview.tsx
+++ b/src/components/ai-edition/VirtualPreview.tsx
@@ -340,6 +340,12 @@ export function VirtualPreview({
audioContextCloseTimerRef.current = null;
}
return () => {
+ // Nothing to tear down means nothing to schedule. WebAudio is unavailable
+ // under jsdom and under a denied audio policy, so this ref is often still
+ // null — and an unmount that leaves a timer behind for a context that was
+ // never created is both waste and a lie to anyone counting timers to prove
+ // this component cleans up after itself (see VirtualPreview.mediaError).
+ if (!audioContextRef.current) return;
audioContextCloseTimerRef.current = setTimeout(() => {
audioContextCloseTimerRef.current = null;
const context = audioContextRef.current;