fix: clear stale peaks before decoding a new source

Reset peaks to null immediately when an uncached URL is set, so the
previous video's waveform is not shown during decode. Also clear on
decode failure so stale data does not persist indefinitely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Davide Mendolia
2026-05-23 18:10:36 +02:00
co-authored by Claude Sonnet 4.6
parent 98f7441dfa
commit f19d1bc668
+3 -1
View File
@@ -70,6 +70,7 @@ export function useAudioPeaks(videoUrl?: string): Float32Array | null {
return;
}
setPeaks(null);
let cancelled = false;
(async () => {
@@ -83,7 +84,8 @@ export function useAudioPeaks(videoUrl?: string): Float32Array | null {
cacheRef.current.set(videoUrl, p);
setPeaks(p);
} catch {
// No audio track or unsupported format — silent degradation.
// No audio track or unsupported format — clear stale data silently.
if (!cancelled) setPeaks(null);
}
})();