🎥 Make videos programmatically with React
test cancelling
Jonny Burger2e1f111a8b8b
diff --git a/packages/example/src/ErrorOnFrame10/index.tsx b/packages/example/src/ErrorOnFrame10/index.tsxnew file mode 100644index 0000000000..4f771519ed--- /dev/null+++ b/packages/example/src/ErrorOnFrame10/index.tsx@@ -0,0 +1,10 @@+import {AbsoluteFill, useCurrentFrame} from 'remotion';++export const ErrorOnFrame10: React.FC = () => {+ const frame = useCurrentFrame();+ if (frame === 10) {+ const a = new Array(0.5);+ console.log(a);+ }+ return <AbsoluteFill />;+};diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex c274bfba81..e650679a0e 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -3,6 +3,7 @@ import {Composition, Folder, getInputProps, Still} from 'remotion';import {TwentyTwoKHzAudio} from './22KhzAudio';import BetaText from './BetaText';import {ColorInterpolation} from './ColorInterpolation';+import {ErrorOnFrame10} from './ErrorOnFrame10';import {FontDemo} from './Fonts';import {Framer} from './Framer';import {FreezeExample} from './Freeze/FreezeExample';@@ -122,6 +123,14 @@ export const Index: React.FC = () => {fps={30}durationInFrames={30}/>+ <Composition+ id="error-on-frame-10"+ component={ErrorOnFrame10}+ width={1280}+ height={720}+ fps={30}+ durationInFrames={1000000}+ /></Folder><Folder name="creatives"><Compositiondiff --git a/packages/it-tests/src/ssr/fatal-error-correct-error.test.ts b/packages/it-tests/src/ssr/fatal-error-correct-error.test.tsnew file mode 100644index 0000000000..a43df26c21--- /dev/null+++ b/packages/it-tests/src/ssr/fatal-error-correct-error.test.ts@@ -0,0 +1,18 @@+import { renderMedia } from "@remotion/renderer";++test("Fatal error on frame 10 should yield correct error", async () => {+ await expect(() => {+ return renderMedia({+ codec: "h264",+ serveUrl: "https://silly-crostata-c4c336.netlify.app/",+ composition: {+ durationInFrames: 1000000,+ fps: 30,+ height: 720,+ id: "error-on-frame-10",+ width: 1280,+ },+ outputLocation: "out/render.mp4",+ });+ }).rejects.toThrow(/Invalid array length/);+});diff --git a/packages/it-tests/src/ssr/render-frames.test.ts b/packages/it-tests/src/ssr/render-frames.test.tsindex 432bc22b3e..b7a8d6d79d 100644--- a/packages/it-tests/src/ssr/render-frames.test.ts+++ b/packages/it-tests/src/ssr/render-frames.test.ts@@ -12,7 +12,7 @@ import execa from "execa";test("Legacy SSR way or rendering videos should still work", async () => {const puppeteerInstance = await openBrowser("chrome");const compositions = await getCompositions(- "https://fascinating-selkie-c7398a.netlify.app/",+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",{puppeteerInstance,}@@ -38,7 +38,8 @@ test("Legacy SSR way or rendering videos should still work", async () => {imageFormat: "jpeg",inputProps: {},onFrameUpdate: () => undefined,- webpackBundle: "https://fascinating-selkie-c7398a.netlify.app/",+ webpackBundle:+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",parallelism: null,frameRange: [0, 10],outputDir: framesDir,diff --git a/packages/it-tests/src/ssr/render-media.test.ts b/packages/it-tests/src/ssr/render-media.test.tsindex 235be971d7..2f76fb42f7 100644--- a/packages/it-tests/src/ssr/render-media.test.ts+++ b/packages/it-tests/src/ssr/render-media.test.ts@@ -6,7 +6,7 @@ import { existsSync } from "fs";test("Render video with browser instance open", async () => {const puppeteerInstance = await openBrowser("chrome");const compositions = await getCompositions(- "https://fascinating-selkie-c7398a.netlify.app/",+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",{puppeteerInstance,}@@ -25,7 +25,8 @@ test("Render video with browser instance open", async () => {await renderMedia({outputLocation: outPath,codec: "h264",- serveUrl: "https://fascinating-selkie-c7398a.netlify.app/",+ serveUrl:+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",composition: reactSvg,frameRange: [0, 2],puppeteerInstance,@@ -36,7 +37,7 @@ test("Render video with browser instance open", async () => {test("Render video with browser instance not open", async () => {const compositions = await getCompositions(- "https://fascinating-selkie-c7398a.netlify.app/"+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/");const reactSvg = compositions.find((c) => c.id === "react-svg");@@ -52,7 +53,8 @@ test("Render video with browser instance not open", async () => {await renderMedia({outputLocation: outPath,codec: "h264",- serveUrl: "https://fascinating-selkie-c7398a.netlify.app/",+ serveUrl:+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",composition: reactSvg,frameRange: [0, 2],});@@ -69,7 +71,8 @@ test("should fail on invalid CRF", async () => {return renderMedia({outputLocation: outPath,codec: "h264",- serveUrl: "https://fascinating-selkie-c7398a.netlify.app/",+ serveUrl:+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",// @ts-expect-errorcrf: "wrong",config: {diff --git a/packages/it-tests/src/ssr/render-still.test.ts b/packages/it-tests/src/ssr/render-still.test.tsindex eaded36fd8..de01b138a1 100644--- a/packages/it-tests/src/ssr/render-still.test.ts+++ b/packages/it-tests/src/ssr/render-still.test.ts@@ -15,7 +15,7 @@ afterEach(async () => {test("Render video with browser instance open", async () => {const puppeteerInstance = await openBrowser("chrome");const compositions = await getCompositions(- "https://fascinating-selkie-c7398a.netlify.app/",+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",{puppeteerInstance,}@@ -33,7 +33,8 @@ test("Render video with browser instance open", async () => {await renderStill({output: outPath,- serveUrl: "https://fascinating-selkie-c7398a.netlify.app/",+ serveUrl:+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",composition: reactSvg,puppeteerInstance,});@@ -42,7 +43,7 @@ test("Render video with browser instance open", async () => {test("Render still with browser instance not open and legacy webpack config", async () => {const compositions = await getCompositions(- "https://fascinating-selkie-c7398a.netlify.app/"+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/");const reactSvg = compositions.find((c) => c.id === "react-svg");@@ -57,7 +58,8 @@ test("Render still with browser instance not open and legacy webpack config", asawait renderStill({output: outPath,- webpackBundle: "https://fascinating-selkie-c7398a.netlify.app/",+ webpackBundle:+ "https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/",composition: reactSvg,});expect(existsSync(outPath)).toBe(true);diff --git a/packages/it-tests/tsconfig.json b/packages/it-tests/tsconfig.jsonindex 499dba227e..1ef68be266 100644--- a/packages/it-tests/tsconfig.json+++ b/packages/it-tests/tsconfig.json@@ -11,6 +11,7 @@"strict": true,"esModuleInterop": true,"resolveJsonModule": true,- "incremental": true+ "incremental": true,+ "noUnusedLocals": true}}diff --git a/packages/lambda/src/test/integration/renders/other-bucket.test.ts b/packages/lambda/src/test/integration/renders/other-bucket.test.tsindex e2d6098ab4..d34c485d6f 100644--- a/packages/lambda/src/test/integration/renders/other-bucket.test.ts+++ b/packages/lambda/src/test/integration/renders/other-bucket.test.ts@@ -31,7 +31,8 @@ test('Should be able to render to another bucket', async () => {const res = await handler({type: LambdaRoutines.start,- serveUrl: 'https://fascinating-selkie-c7398a.netlify.app/',+ serveUrl:+ 'https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/',chromiumOptions: {},codec: 'h264-mkv',composition: 'react-svg',diff --git a/packages/lambda/src/test/integration/renders/silent-audio.test.ts b/packages/lambda/src/test/integration/renders/silent-audio.test.tsindex e2f7bcb59a..437f07df42 100644--- a/packages/lambda/src/test/integration/renders/silent-audio.test.ts+++ b/packages/lambda/src/test/integration/renders/silent-audio.test.ts@@ -31,7 +31,8 @@ test('Should add silent audio if there is no audio', async () => {const res = await handler({type: LambdaRoutines.start,- serveUrl: 'https://fascinating-selkie-c7398a.netlify.app/',+ serveUrl:+ 'https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/',chromiumOptions: {},codec: 'h264-mkv',composition: 'react-svg',diff --git a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts b/packages/lambda/src/test/integration/renders/transparent-webm.test.tsindex 28ae311532..d4dc319250 100644--- a/packages/lambda/src/test/integration/renders/transparent-webm.test.ts+++ b/packages/lambda/src/test/integration/renders/transparent-webm.test.ts@@ -33,7 +33,8 @@ test('Should make a transparent video', async () => {const res = await handler({type: LambdaRoutines.start,- serveUrl: 'https://fascinating-selkie-c7398a.netlify.app/',+ serveUrl:+ 'https://6297949544e290044cecb257--cute-kitsune-214ea5.netlify.app/',chromiumOptions: {},codec: 'vp8',composition: 'ten-frame-tester',diff --git a/packages/renderer/src/cycle-browser-tabs.ts b/packages/renderer/src/cycle-browser-tabs.tsindex 1f826e89d0..e4323b5e3a 100644--- a/packages/renderer/src/cycle-browser-tabs.ts+++ b/packages/renderer/src/cycle-browser-tabs.ts@@ -17,6 +17,7 @@ export const cycleBrowserTabs = (let interval: NodeJS.Timeout | null = null;let i = 0;+ let stopped = false;const set = () => {interval = setTimeout(() => {Promise.resolve(puppeteerInstance)@@ -24,7 +25,11 @@ export const cycleBrowserTabs = (.then((pages) => {const currentPage = pages[i % pages.length];i++;- if (!(currentPage?.isClosed?.() ?? true)) {+ if (+ !currentPage?.isClosed?.() &&+ !stopped &&+ currentPage.url() !== 'about:blank'+ ) {return currentPage.bringToFront();}})@@ -43,6 +48,8 @@ export const cycleBrowserTabs = (return;}+ stopped = true;+return clearInterval(interval);},};diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.tsindex 06c524cd11..7df2b09f81 100644--- a/packages/renderer/src/render-frames.ts+++ b/packages/renderer/src/render-frames.ts@@ -434,6 +434,7 @@ export const renderFrames = (proxyPort: offthreadPort,});cancel = () => {+ stopCycling();renderFramesProm.cancel();};