@remotion/three 4.0.301 → 4.0.303

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,17 @@ const Scale = ({ width, height, }) => {
17
17
  }, [setSize, width, height, set]);
18
18
  return null;
19
19
  };
20
+ const FiberFrameInvalidator = () => {
21
+ const { invalidate } = (0, fiber_1.useThree)();
22
+ const frame = (0, remotion_1.useCurrentFrame)();
23
+ (0, react_1.useEffect)(() => {
24
+ invalidate();
25
+ }, [frame, invalidate]);
26
+ return null;
27
+ };
28
+ const { isRendering } = (0, remotion_1.getRemotionEnvironment)();
29
+ // https://r3f.docs.pmnd.rs/advanced/scaling-performance#on-demand-rendering
30
+ const shouldUseFrameloopDemand = isRendering;
20
31
  /*
21
32
  * @description A wrapper for React Three Fiber's <Canvas /> which synchronizes with Remotion's useCurrentFrame().
22
33
  * @see [Documentation](https://www.remotion.dev/docs/three-canvas)
@@ -36,6 +47,6 @@ const ThreeCanvas = (props) => {
36
47
  (0, remotion_1.continueRender)(waitForCreated);
37
48
  onCreated === null || onCreated === void 0 ? void 0 : onCreated(state);
38
49
  }, [onCreated, waitForCreated]);
39
- return ((0, jsx_runtime_1.jsx)(SuspenseLoader_1.SuspenseLoader, { children: (0, jsx_runtime_1.jsxs)(fiber_1.Canvas, { style: actualStyle, ...rest, onCreated: remotion_onCreated, children: [(0, jsx_runtime_1.jsx)(Scale, { width: width, height: height }), (0, jsx_runtime_1.jsx)(remotion_1.Internals.RemotionContextProvider, { contexts: contexts, children: children })] }) }));
50
+ return ((0, jsx_runtime_1.jsx)(SuspenseLoader_1.SuspenseLoader, { children: (0, jsx_runtime_1.jsxs)(fiber_1.Canvas, { style: actualStyle, ...rest, frameloop: shouldUseFrameloopDemand ? 'demand' : 'always', onCreated: remotion_onCreated, children: [(0, jsx_runtime_1.jsx)(Scale, { width: width, height: height }), (0, jsx_runtime_1.jsxs)(remotion_1.Internals.RemotionContextProvider, { contexts: contexts, children: [shouldUseFrameloopDemand && (0, jsx_runtime_1.jsx)(FiberFrameInvalidator, {}), children] })] }) }));
40
51
  };
41
52
  exports.ThreeCanvas = ThreeCanvas;
@@ -79,7 +79,7 @@ const useVideoTexture = (videoRef) => {
79
79
  setError(err);
80
80
  });
81
81
  }, [loaded, vidText, videoRef]);
82
- react_1.default.useEffect(() => {
82
+ react_1.default.useLayoutEffect(() => {
83
83
  if (!videoRef.current) {
84
84
  return;
85
85
  }
@@ -24,8 +24,14 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
24
24
 
25
25
  // src/ThreeCanvas.tsx
26
26
  import { Canvas, useThree } from "@react-three/fiber";
27
- import { useCallback, useLayoutEffect as useLayoutEffect2, useState } from "react";
28
- import { Internals, continueRender as continueRender2, delayRender as delayRender2 } from "remotion";
27
+ import { useCallback, useEffect, useLayoutEffect as useLayoutEffect2, useState } from "react";
28
+ import {
29
+ Internals,
30
+ continueRender as continueRender2,
31
+ delayRender as delayRender2,
32
+ getRemotionEnvironment,
33
+ useCurrentFrame
34
+ } from "remotion";
29
35
 
30
36
  // src/SuspenseLoader.tsx
31
37
  import { Suspense, useLayoutEffect } from "react";
@@ -68,6 +74,16 @@ var Scale = ({
68
74
  }, [setSize, width, height, set]);
69
75
  return null;
70
76
  };
77
+ var FiberFrameInvalidator = () => {
78
+ const { invalidate } = useThree();
79
+ const frame = useCurrentFrame();
80
+ useEffect(() => {
81
+ invalidate();
82
+ }, [frame, invalidate]);
83
+ return null;
84
+ };
85
+ var { isRendering } = getRemotionEnvironment();
86
+ var shouldUseFrameloopDemand = isRendering;
71
87
  var ThreeCanvas = (props) => {
72
88
  const { children, width, height, style, onCreated, ...rest } = props;
73
89
  const [waitForCreated] = useState(() => delayRender2("Waiting for <ThreeCanvas/> to be created"));
@@ -87,15 +103,19 @@ var ThreeCanvas = (props) => {
87
103
  children: /* @__PURE__ */ jsxs(Canvas, {
88
104
  style: actualStyle,
89
105
  ...rest,
106
+ frameloop: shouldUseFrameloopDemand ? "demand" : "always",
90
107
  onCreated: remotion_onCreated,
91
108
  children: [
92
109
  /* @__PURE__ */ jsx2(Scale, {
93
110
  width,
94
111
  height
95
112
  }),
96
- /* @__PURE__ */ jsx2(Internals.RemotionContextProvider, {
113
+ /* @__PURE__ */ jsxs(Internals.RemotionContextProvider, {
97
114
  contexts,
98
- children
115
+ children: [
116
+ shouldUseFrameloopDemand && /* @__PURE__ */ jsx2(FiberFrameInvalidator, {}),
117
+ children
118
+ ]
99
119
  })
100
120
  ]
101
121
  })
@@ -108,8 +128,8 @@ import {
108
128
  cancelRender,
109
129
  continueRender as continueRender3,
110
130
  delayRender as delayRender3,
111
- getRemotionEnvironment,
112
- useCurrentFrame,
131
+ getRemotionEnvironment as getRemotionEnvironment2,
132
+ useCurrentFrame as useCurrentFrame2,
113
133
  useVideoConfig
114
134
  } from "remotion";
115
135
  import { NoReactInternals as NoReactInternals2 } from "remotion/no-react";
@@ -121,7 +141,7 @@ var useInnerVideoTexture = ({
121
141
  delayRenderRetries,
122
142
  delayRenderTimeoutInMilliseconds
123
143
  }) => {
124
- const frame = useCurrentFrame();
144
+ const frame = useCurrentFrame2();
125
145
  const { fps } = useVideoConfig();
126
146
  const mediaStartsAt = Internals2.useMediaStartsAt();
127
147
  const currentTime = useMemo(() => {
@@ -190,8 +210,8 @@ function useOffthreadVideoTexture({
190
210
  if (!src) {
191
211
  throw new Error("src must be provided to useOffthreadVideoTexture");
192
212
  }
193
- const { isRendering } = getRemotionEnvironment();
194
- if (!isRendering) {
213
+ const { isRendering: isRendering2 } = getRemotionEnvironment2();
214
+ if (!isRendering2) {
195
215
  throw new Error("useOffthreadVideoTexture() can only be used during rendering. Use getRemotionEnvironment().isRendering to render it conditionally.");
196
216
  }
197
217
  return useInnerVideoTexture({
@@ -204,8 +224,8 @@ function useOffthreadVideoTexture({
204
224
  });
205
225
  }
206
226
  // src/use-video-texture.ts
207
- import React3, { useCallback as useCallback3, useEffect, useState as useState3 } from "react";
208
- import { continueRender as continueRender4, delayRender as delayRender4, useCurrentFrame as useCurrentFrame2 } from "remotion";
227
+ import React3, { useCallback as useCallback3, useEffect as useEffect2, useState as useState3 } from "react";
228
+ import { continueRender as continueRender4, delayRender as delayRender4, useCurrentFrame as useCurrentFrame3 } from "remotion";
209
229
  var warned = false;
210
230
  var warnAboutRequestVideoFrameCallback = () => {
211
231
  if (warned) {
@@ -224,7 +244,7 @@ var useVideoTexture = (videoRef) => {
224
244
  const [videoTexture, setVideoTexture] = useState3(null);
225
245
  const [vidText] = useState3(() => import("three/src/textures/VideoTexture.js"));
226
246
  const [error, setError] = useState3(null);
227
- const frame = useCurrentFrame2();
247
+ const frame = useCurrentFrame3();
228
248
  if (error) {
229
249
  throw error;
230
250
  }
@@ -242,7 +262,7 @@ var useVideoTexture = (videoRef) => {
242
262
  setError(err);
243
263
  });
244
264
  }, [loaded, vidText, videoRef]);
245
- React3.useEffect(() => {
265
+ React3.useLayoutEffect(() => {
246
266
  if (!videoRef.current) {
247
267
  return;
248
268
  }
@@ -266,7 +286,7 @@ var useVideoTexture = (videoRef) => {
266
286
  const ready = () => {};
267
287
  current.requestVideoFrameCallback(ready);
268
288
  }, [frame, loaded, videoRef]);
269
- useEffect(() => {
289
+ useEffect2(() => {
270
290
  return () => {
271
291
  continueRender4(loaded);
272
292
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "url": "https://github.com/remotion-dev/remotion/tree/main/packages/three"
4
4
  },
5
5
  "name": "@remotion/three",
6
- "version": "4.0.301",
6
+ "version": "4.0.303",
7
7
  "description": "Include React Three Fiber components in a Remotion video",
8
8
  "main": "dist/cjs/index.js",
9
9
  "types": "dist/cjs/index.d.ts",
@@ -16,14 +16,14 @@
16
16
  "url": "https://github.com/remotion-dev/remotion/issues"
17
17
  },
18
18
  "dependencies": {
19
- "remotion": "4.0.301"
19
+ "remotion": "4.0.303"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "@react-three/fiber": ">=8.0.0",
23
23
  "react": ">=16.8.0",
24
24
  "react-dom": ">=16.8.0",
25
25
  "three": ">=0.137.0",
26
- "remotion": "4.0.301"
26
+ "remotion": "4.0.303"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@react-three/fiber": "9.1.2",
@@ -34,8 +34,8 @@
34
34
  "react-dom": "19.0.0",
35
35
  "three": "0.171.0",
36
36
  "eslint": "9.19.0",
37
- "remotion": "4.0.301",
38
- "@remotion/eslint-config-internal": "4.0.301"
37
+ "remotion": "4.0.303",
38
+ "@remotion/eslint-config-internal": "4.0.303"
39
39
  },
40
40
  "keywords": [
41
41
  "remotion",