Skip to content

🎥 Make videos programmatically with React

add proper cleanup for unmount

Igor Samokhovets7c0875faeab3
diff --git a/packages/media-utils/src/use-windowed-audio-data.ts b/packages/media-utils/src/use-windowed-audio-data.ts
index 877eae6963..3b0141e8cc 100644
--- a/packages/media-utils/src/use-windowed-audio-data.ts
+++ b/packages/media-utils/src/use-windowed-audio-data.ts
@@ -59,6 +59,17 @@ export const useWindowedAudioData = ({
return () => {
isMounted.current = false;
+
+ // abort all pending requests
+ Object.values(requests.current).forEach((controller) => {
+ if (controller) {
+ controller.abort();
+ }
+ });
+ requests.current = {};
+
+ // clear all Float32Array references
+ setWaveformMap({});
};
}, []);