Skip to content

🎥 Make videos programmatically with React

fix effects

Jonny Burger54d2057b9b96
diff --git a/packages/core/src/Img.tsx b/packages/core/src/Img.tsx
index 9a6895dd0a..b504d75cd2 100644
--- a/packages/core/src/Img.tsx
+++ b/packages/core/src/Img.tsx
@@ -45,13 +45,12 @@ const ImgRefForwarding: React.ForwardRefRenderFunction<
[handle, onError]
);
+ // If tag gets unmounted, clear pending handles because image is not going to load
useEffect(() => {
- console.log('mounting', props.src);
return () => {
continueRender(handle);
- console.log('unmounting', props.src);
};
- }, []);
+ }, [handle]);
return <img {...props} ref={ref} onLoad={didLoad} onError={didGetError} />;
};
diff --git a/packages/core/src/video/VideoForRendering.tsx b/packages/core/src/video/VideoForRendering.tsx
index 6b42bb9cf1..f2faa5a978 100644
--- a/packages/core/src/video/VideoForRendering.tsx
+++ b/packages/core/src/video/VideoForRendering.tsx
@@ -175,6 +175,11 @@ const VideoForRenderingForwardFunction: React.ForwardRefRenderFunction<
},
{once: true}
);
+
+ // If video skips to another frame or unmounts, we clear the created handle
+ return () => {
+ continueRender(handle);
+ };
}, [
volumePropsFrame,
props.src,