Skip to content

🎥 Make videos programmatically with React

`@remotion/three`: More resilient lifecycle of useVideoTexture() for React 19

Jonny Burger93db9d94ce78
diff --git a/packages/three/src/use-video-texture.ts b/packages/three/src/use-video-texture.ts
index 1c0e488d07..72900be8a2 100644
--- a/packages/three/src/use-video-texture.ts
+++ b/packages/three/src/use-video-texture.ts
@@ -1,4 +1,4 @@
-import React, {useCallback, useState} from 'react';
+import React, {useCallback, useEffect, useState} from 'react';
import type {Video} from 'remotion';
import {continueRender, delayRender, useCurrentFrame} from 'remotion';
import type {VideoTexture} from 'three/src/textures/VideoTexture';
@@ -100,6 +100,14 @@ export const useVideoTexture = (
current.requestVideoFrameCallback(ready);
}, [frame, loaded, videoRef]);
+ useEffect(() => {
+ // Clean up on unmount
+
+ return () => {
+ continueRender(loaded);
+ };
+ }, [loaded]);
+
if (
typeof HTMLVideoElement === 'undefined' ||
!HTMLVideoElement.prototype.requestVideoFrameCallback