Skip to content

🎥 Make videos programmatically with React

timeout structure

Jonny Burger1d708e9da377
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 3c599f85dc..12c8bd7a40 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -123,6 +123,7 @@ import {
useRemotionContexts,
} from './wrap-remotion-context';
import * as AssetCompression from './compress-assets';
+import {DEFAULT_TIMEOUT} from './timeout';
const Timeline = {...TimelinePosition, ...TimelineInOutPosition};
// Mark them as Internals so use don't assume this is public
@@ -202,6 +203,7 @@ export const Internals = {
invalidCompositionErrorMessage,
isCompositionIdValid,
AssetCompression,
+ DEFAULT_TIMEOUT,
};
export type {
diff --git a/packages/core/src/ready-manager.ts b/packages/core/src/ready-manager.ts
index ac56f22317..764538bf6a 100644
--- a/packages/core/src/ready-manager.ts
+++ b/packages/core/src/ready-manager.ts
@@ -1,4 +1,5 @@
import {getRemotionEnvironment} from './get-environment';
+import {DEFAULT_TIMEOUT} from './timeout';
if (typeof window !== 'undefined') {
window.ready = false;
@@ -15,10 +16,11 @@ export const delayRender = (): number => {
if (getRemotionEnvironment() === 'rendering') {
timeouts[handle] = setTimeout(() => {
throw new Error(
- 'A delayRender was called but not cleared after 25000ms. See https://remotion.dev/docs/timeout for help. The delayRender was called: ' +
- called
+ `A delayRender was called but not cleared after ${
+ DEFAULT_TIMEOUT - 2000
+ }ms. See https://remotion.dev/docs/timeout for help. The delayRender was called: ${called}`
);
- }, 25000);
+ }, DEFAULT_TIMEOUT - 2000);
}
if (typeof window !== 'undefined') {
diff --git a/packages/core/src/timeout.ts b/packages/core/src/timeout.ts
new file mode 100644
index 0000000000..b7b4e65f0c
--- /dev/null
+++ b/packages/core/src/timeout.ts
@@ -0,0 +1 @@
+export const DEFAULT_TIMEOUT = 30000;
diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.ts
index 5bb2a33862..d3701553ce 100644
--- a/packages/renderer/src/get-compositions.ts
+++ b/packages/renderer/src/get-compositions.ts
@@ -3,6 +3,7 @@ import {Browser, BrowserExecutable, Internals, TCompMetadata} from 'remotion';
import {openBrowser} from './open-browser';
import {serveStatic} from './serve-static';
import {setPropsAndEnv} from './set-props-and-env';
+import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';
type GetCompositionsConfig = {
browser?: Browser;
@@ -10,6 +11,7 @@ type GetCompositionsConfig = {
envVariables?: Record<string, string>;
browserInstance?: PuppeteerBrowser;
browserExecutable?: BrowserExecutable;
+ timeoutInMilliseconds?: number;
};
const getPageAndCleanupFn = async ({
@@ -61,6 +63,7 @@ export const getCompositions = async (
webpackBundle: string,
config?: GetCompositionsConfig
): Promise<TCompMetadata[]> => {
+ validatePuppeteerTimeout(config?.timeoutInMilliseconds);
const {page, cleanup} = await getPageAndCleanupFn({
passedInInstance: config?.browserInstance,
browser: config?.browser ?? Internals.DEFAULT_BROWSER,
@@ -77,6 +80,7 @@ export const getCompositions = async (
page,
port,
initialFrame: 0,
+ timeoutInMilliseconds: config?.timeoutInMilliseconds,
});
await page.goto(`http://localhost:${port}/index.html?evaluation=true`);
diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.ts
index 837aeeb4c0..0f66771a3c 100644
--- a/packages/renderer/src/render-still.ts
+++ b/packages/renderer/src/render-still.ts
@@ -7,6 +7,7 @@ import {provideScreenshot} from './provide-screenshot';
import {seekToFrame} from './seek-to-frame';
import {serveStatic} from './serve-static';
import {setPropsAndEnv} from './set-props-and-env';
+import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';
/**
* @description Render a still frame from a composition and returns an image path
@@ -26,6 +27,7 @@ export const renderStill = async ({
frame = 0,
overwrite = true,
browserExecutable,
+ timeoutInMilliseconds,
}: {
composition: TCompMetadata;
output: string;
@@ -41,6 +43,7 @@ export const renderStill = async ({
envVariables?: Record<string, string>;
overwrite?: boolean;
browserExecutable?: BrowserExecutable;
+ timeoutInMilliseconds?: number;
}) => {
Internals.validateDimension(
composition.height,
@@ -62,6 +65,7 @@ export const renderStill = async ({
);
Internals.validateNonNullImageFormat(imageFormat);
Internals.validateFrame(frame, composition.durationInFrames);
+ validatePuppeteerTimeout(timeoutInMilliseconds);
if (typeof output !== 'string') {
throw new TypeError('`output` parameter was not passed or is not a string');
@@ -122,6 +126,7 @@ export const renderStill = async ({
page,
port,
initialFrame: frame,
+ timeoutInMilliseconds,
});
const site = `http://localhost:${port}/index.html?composition=${composition.id}`;
diff --git a/packages/renderer/src/render.ts b/packages/renderer/src/render.ts
index d20c8b1345..efb57aad2c 100644
--- a/packages/renderer/src/render.ts
+++ b/packages/renderer/src/render.ts
@@ -21,6 +21,7 @@ import {seekToFrame} from './seek-to-frame';
import {serveStatic} from './serve-static';
import {setPropsAndEnv} from './set-props-and-env';
import {OnErrorInfo, OnStartData, RenderFramesOutput} from './types';
+import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';
export const renderFrames = async ({
config,
@@ -40,6 +41,7 @@ export const renderFrames = async ({
puppeteerInstance,
onError,
browserExecutable,
+ timeoutInMilliseconds,
}: {
config: VideoConfig;
compositionId: string;
@@ -58,6 +60,7 @@ export const renderFrames = async ({
puppeteerInstance?: PuppeteerBrowser;
browserExecutable?: BrowserExecutable;
onError?: (info: OnErrorInfo) => void;
+ timeoutInMilliseconds?: number;
}): Promise<RenderFramesOutput> => {
Internals.validateDimension(
config.height,
@@ -84,6 +87,7 @@ export const renderFrames = async ({
}
Internals.validateQuality(quality);
+ validatePuppeteerTimeout(timeoutInMilliseconds);
const actualParallelism = getActualConcurrency(parallelism ?? null);
@@ -121,6 +125,7 @@ export const renderFrames = async ({
page,
port,
initialFrame,
+ timeoutInMilliseconds,
});
const site = `http://localhost:${port}/index.html?composition=${compositionId}`;
diff --git a/packages/renderer/src/set-props-and-env.ts b/packages/renderer/src/set-props-and-env.ts
index 3e8e094d56..40551ae3eb 100644
--- a/packages/renderer/src/set-props-and-env.ts
+++ b/packages/renderer/src/set-props-and-env.ts
@@ -1,5 +1,6 @@
import {Page} from 'puppeteer-core';
import {Internals} from 'remotion';
+import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';
export const setPropsAndEnv = async ({
inputProps,
@@ -7,13 +8,20 @@ export const setPropsAndEnv = async ({
page,
port,
initialFrame,
+ timeoutInMilliseconds,
}: {
inputProps: unknown;
envVariables: Record<string, string> | undefined;
page: Page;
port: number;
initialFrame: number;
+ timeoutInMilliseconds: number | undefined;
}) => {
+ validatePuppeteerTimeout(timeoutInMilliseconds);
+ const actualTimeout = timeoutInMilliseconds ?? Internals.DEFAULT_TIMEOUT;
+ page.setDefaultTimeout(actualTimeout);
+ page.setDefaultNavigationTimeout(actualTimeout);
+
if (inputProps || envVariables) {
await page.goto(`http://localhost:${port}/index.html`);
diff --git a/packages/renderer/src/validate-puppeteer-timeout.ts b/packages/renderer/src/validate-puppeteer-timeout.ts
new file mode 100644
index 0000000000..1eea5d0dab
--- /dev/null
+++ b/packages/renderer/src/validate-puppeteer-timeout.ts
@@ -0,0 +1,37 @@
+export const validatePuppeteerTimeout = (timeoutInMilliseconds: unknown) => {
+ if (timeoutInMilliseconds === null || timeoutInMilliseconds === undefined) {
+ return;
+ }
+
+ if (typeof timeoutInMilliseconds !== 'number') {
+ throw new TypeError(
+ `'timeoutInMilliseconds' should be a number, but is: ${JSON.stringify(
+ timeoutInMilliseconds
+ )}`
+ );
+ }
+
+ if (timeoutInMilliseconds < 7000) {
+ throw new TypeError(
+ `'timeoutInMilliseconds' should be bigger or equal than 7000, but is ${timeoutInMilliseconds}`
+ );
+ }
+
+ if (Number.isNaN(timeoutInMilliseconds)) {
+ throw new TypeError(
+ `'timeoutInMilliseconds' should not be NaN, but is ${timeoutInMilliseconds}`
+ );
+ }
+
+ if (!Number.isFinite(timeoutInMilliseconds)) {
+ throw new TypeError(
+ `'timeoutInMilliseconds' should be finite, but is ${timeoutInMilliseconds}`
+ );
+ }
+
+ if (timeoutInMilliseconds % 1 !== 0) {
+ throw new TypeError(
+ `'timeoutInMilliseconds' should be an integer, but is ${timeoutInMilliseconds}`
+ );
+ }
+};