π₯ Make videos programmatically with React
cancelRender()
Jonny Burgerf55f58793997
diff --git a/packages/docs/docs/after-effects.md b/packages/docs/docs/after-effects.mdindex be4e3fbb70..3048f814b8 100644--- a/packages/docs/docs/after-effects.md+++ b/packages/docs/docs/after-effects.md@@ -58,7 +58,12 @@ Copy the file into the Remotion project. The recommended way is to put the JSON```tsx twoslash title="Animation.tsx"import { Lottie, LottieAnimationData } from "@remotion/lottie";import { useEffect, useState } from "react";-import { continueRender, delayRender, staticFile } from "remotion";+import {+ cancelRender,+ continueRender,+ delayRender,+ staticFile,+} from "remotion";const Balloons = () => {const [handle] = useState(() => delayRender("Loading Lottie animation"));@@ -74,6 +79,7 @@ const Balloons = () => {continueRender(handle);}).catch((err) => {+ cancelRender(err);console.log("Animation failed to load", err);});}, [handle]);diff --git a/packages/docs/docs/audiobuffertodataurl.md b/packages/docs/docs/audiobuffertodataurl.mdindex 15083620d6..863d63b0b5 100644--- a/packages/docs/docs/audiobuffertodataurl.md+++ b/packages/docs/docs/audiobuffertodataurl.md@@ -28,6 +28,7 @@ import { audioBufferToDataUrl } from "@remotion/media-utils";import { useCallback, useEffect, useState } from "react";import {Audio,+ cancelRender,continueRender,delayRender,interpolate,@@ -69,7 +70,7 @@ export const OfflineAudioBufferExample: React.FC = () => {}, [handle, lengthInSeconds]);useEffect(() => {- renderAudio();+ renderAudio().catch((err) => cancelRender(err));}, [renderAudio]);return audioBuffer ? (diff --git a/packages/docs/docs/cancel-render.md b/packages/docs/docs/cancel-render.mdindex 27bae5c8f6..27395f1f7f 100644--- a/packages/docs/docs/cancel-render.md+++ b/packages/docs/docs/cancel-render.md@@ -17,7 +17,7 @@ import React, { useEffect, useState } from "react";import { cancelRender, continueRender, delayRender } from "remotion";export const MyComp: React.FC = () => {- const [handle] = useState(() => delayRender("Fetching audio data..."));+ const [handle] = useState(() => delayRender("Fetching data..."));useEffect(() => {fetch("https://example.com")@@ -33,5 +33,6 @@ export const MyComp: React.FC = () => {## See also+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/cancel-render.ts)- [delayRender()](/docs/delay-render)- [continueRender()](/docs/continue-render)diff --git a/packages/docs/docs/continue-render.md b/packages/docs/docs/continue-render.mdindex 3a0b07dd68..9174475400 100644--- a/packages/docs/docs/continue-render.md+++ b/packages/docs/docs/continue-render.md@@ -13,3 +13,4 @@ Using `continueRender`, you can unblock a rendering that has been deferred using- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/delay-render.ts)- [Data fetching](/docs/data-fetching)+- [cancelRender()](/docs/cancel-render)diff --git a/packages/docs/docs/delay-render.md b/packages/docs/docs/delay-render.mdindex 95596ecaa3..308b1fab5a 100644--- a/packages/docs/docs/delay-render.md+++ b/packages/docs/docs/delay-render.md@@ -124,7 +124,34 @@ const MyComp: React.FC = () => {};```+## Failing with an error++_available from v3.3.44_++If your code fails to do an asynchronous operation and you want to cancel the render, you can call `cancelRender()` with an error message. This will automatically cancel all `delayRender()` calls to not further delay the render.++```tsx twoslash title="MyComposition.tsx"+import React, { useEffect, useState } from "react";+import { cancelRender, continueRender, delayRender } from "remotion";++export const MyComp: React.FC = () => {+ const [handle] = useState(() => delayRender("Fetching data..."));++ useEffect(() => {+ fetch("https://example.com")+ .then(() => {+ continueRender(handle);+ })+ .catch((err) => cancelRender(err));+ }, []);++ return null;+};+```+## See also- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/core/src/delay-render.ts)- [Data fetching](/docs/data-fetching)+- [continueRender()](/docs/continue-render)+- [cancelRender()](/docs/cancel-render)diff --git a/packages/docs/docs/lottie/lottie-lottiefiles.md b/packages/docs/docs/lottie/lottie-lottiefiles.mdindex 4b071a4500..a61d827ae8 100644--- a/packages/docs/docs/lottie/lottie-lottiefiles.md+++ b/packages/docs/docs/lottie/lottie-lottiefiles.md@@ -26,7 +26,12 @@ Copy the file into the Remotion project. The recommended way is to put the JSON```tsx twoslash title="Animation.tsx"import { Lottie, LottieAnimationData } from "@remotion/lottie";import { useEffect, useState } from "react";-import { continueRender, delayRender, staticFile } from "remotion";+import {+ cancelRender,+ continueRender,+ delayRender,+ staticFile,+} from "remotion";const Balloons = () => {const [handle] = useState(() => delayRender("Loading Lottie animation"));@@ -42,7 +47,7 @@ const Balloons = () => {continueRender(handle);}).catch((err) => {- console.log("Animation failed to load", err);+ cancelRender(err);});}, [handle]);diff --git a/packages/docs/docs/lottie/lottie-remote.md b/packages/docs/docs/lottie/lottie-remote.mdindex f25da86f08..f9f972940e 100644--- a/packages/docs/docs/lottie/lottie-remote.md+++ b/packages/docs/docs/lottie/lottie-remote.md@@ -16,7 +16,7 @@ Use the `LottieAnimationData` type to keep a state using React's `useState()` an```tsx twoslash title="Animation.tsx"import { Lottie, LottieAnimationData } from "@remotion/lottie";import { useEffect, useState } from "react";-import { continueRender, delayRender } from "remotion";+import { cancelRender, continueRender, delayRender } from "remotion";const Balloons = () => {const [handle] = useState(() => delayRender("Loading Lottie animation"));@@ -32,7 +32,7 @@ const Balloons = () => {continueRender(handle);}).catch((err) => {- console.log("Animation failed to load", err);+ cancelRender(err);});}, [handle]);diff --git a/packages/docs/docs/lottie/lottie-staticfile.md b/packages/docs/docs/lottie/lottie-staticfile.mdindex b80ad65f2f..9f81ec036f 100644--- a/packages/docs/docs/lottie/lottie-staticfile.md+++ b/packages/docs/docs/lottie/lottie-staticfile.md@@ -14,7 +14,12 @@ Use the `LottieAnimationData` type to keep a state using React's `useState()` an```tsx twoslash title="Animation.tsx"import { Lottie, LottieAnimationData } from "@remotion/lottie";import { useEffect, useState } from "react";-import { continueRender, delayRender, staticFile } from "remotion";+import {+ cancelRender,+ continueRender,+ delayRender,+ staticFile,+} from "remotion";const Square = () => {const [handle] = useState(() => delayRender("Loading Lottie animation"));@@ -30,7 +35,7 @@ const Square = () => {continueRender(handle);}).catch((err) => {- console.log("Animation failed to load", err);+ cancelRender(err);});}, [handle]);diff --git a/packages/docs/docs/offthreadvideo.md b/packages/docs/docs/offthreadvideo.mdindex 7ace8bb8fa..e353a3c3be 100644--- a/packages/docs/docs/offthreadvideo.md+++ b/packages/docs/docs/offthreadvideo.md@@ -71,6 +71,7 @@ Unlike [`<Video>`](/docs/video), `OffthreadVideo` does not currently implement timport { getVideoMetadata } from "@remotion/media-utils";import React, { useEffect, useState } from "react";import {+ cancelRender,continueRender,delayRender,Loop,@@ -93,6 +94,7 @@ export const LoopedOffthreadVideo: React.FC = () => {continueRender(handle);}).catch((err) => {+ cancelRender(handle);console.log(err);});}, [handle]);diff --git a/packages/docs/docs/troubleshooting/defaultprops-too-big.md b/packages/docs/docs/troubleshooting/defaultprops-too-big.mdindex a18a2724d2..b5aa058804 100644--- a/packages/docs/docs/troubleshooting/defaultprops-too-big.md+++ b/packages/docs/docs/troubleshooting/defaultprops-too-big.md@@ -38,7 +38,13 @@ Example:```tsx twoslash title="β Avoid - big data chunk as defaultProps"import { AudioData, getAudioData } from "@remotion/media-utils";import { useEffect, useState } from "react";-import { Composition, continueRender, delayRender, staticFile } from "remotion";+import {+ cancelRender,+ Composition,+ continueRender,+ delayRender,+ staticFile,+} from "remotion";// MyComp.tsxconst MyComp: React.FC<{@@ -59,7 +65,7 @@ const RemotionRoot = () => {continueRender(handle);}).catch((e) => {- console.log(e);+ cancelRender(e);});}, [handle]);@@ -84,7 +90,13 @@ This can lead to problems because the `audioData` variable can become very big s```tsx twoslash title="β Do - Fetch data inside composition"import { getAudioData } from "@remotion/media-utils";import { useEffect, useState } from "react";-import { Composition, continueRender, delayRender, staticFile } from "remotion";+import {+ cancelRender,+ Composition,+ continueRender,+ delayRender,+ staticFile,+} from "remotion";// MyComp.tsxconst MyComp: React.FC<{ src: string }> = ({ src }) => {@@ -98,7 +110,7 @@ const MyComp: React.FC<{ src: string }> = ({ src }) => {continueRender(handle);}).catch((e) => {- console.log(e);+ cancelRender(e);});}, [handle]);