[Perf] Delay video cleanup with onFullyIdle
This commit is contained in:
parent
35948a8bcb
commit
d0d1a57cf3
@ -1,21 +1,20 @@
|
|||||||
import type { RefObject } from 'react';
|
import type { RefObject } from 'react';
|
||||||
import { useEffect } from '../lib/teact/teact';
|
import { useEffect } from '../lib/teact/teact';
|
||||||
|
|
||||||
import { requestNextMutation } from '../lib/fasterdom/fasterdom';
|
|
||||||
import unloadVideo from '../util/browser/unloadVideo';
|
import unloadVideo from '../util/browser/unloadVideo';
|
||||||
|
import { onFullyIdle } from './useHeavyAnimationCheck';
|
||||||
|
|
||||||
// Fix for memory leak when unmounting video element
|
// Fix for memory leak when unmounting video element
|
||||||
export default function useVideoCleanup(videoRef: RefObject<HTMLVideoElement>, dependencies: any[]) {
|
export default function useVideoCleanup(videoRef: RefObject<HTMLVideoElement>, dependencies: any[]) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const videoEl = videoRef.current;
|
const videoEl = videoRef.current;
|
||||||
|
if (!videoEl) return undefined;
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
if (videoEl) {
|
// It may be slow (specifically on iOS), so we postpone it after unmounting
|
||||||
// It may be slow (specifically on iOS), so we postpone it after unmounting
|
onFullyIdle(() => {
|
||||||
requestNextMutation(() => {
|
unloadVideo(videoEl);
|
||||||
unloadVideo(videoEl);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
// eslint-disable-next-line react-hooks-static-deps/exhaustive-deps
|
// eslint-disable-next-line react-hooks-static-deps/exhaustive-deps
|
||||||
}, dependencies);
|
}, dependencies);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user