Skip to content

🎥 Make videos programmatically with React

Make scope mandatory

JonnyBurgerc4caaf93d4de
diff --git a/packages/core/src/delay-render.ts b/packages/core/src/delay-render.ts
index e79f2754e2..a283cbcb9d 100644
--- a/packages/core/src/delay-render.ts
+++ b/packages/core/src/delay-render.ts
@@ -51,7 +51,7 @@ export const delayRenderInternal = ({
label,
options,
}: {
- scope: DelayRenderScope | undefined;
+ scope: DelayRenderScope;
environment: RemotionEnvironment;
label: string | null;
options: DelayRenderOptions;
@@ -70,55 +70,33 @@ export const delayRenderInternal = ({
if (environment.isRendering) {
const timeoutToUse =
(options?.timeoutInMilliseconds ??
- (typeof scope === 'undefined'
- ? defaultTimeout
- : (scope.remotion_puppeteerTimeout ?? defaultTimeout))) - 2000;
- if (typeof scope !== 'undefined') {
- const retriesLeft =
- (options?.retries ?? 0) - (scope.remotion_attempt - 1);
- scope.remotion_delayRenderTimeouts[handle] = {
- label: label ?? null,
- startTime: Date.now(),
- timeout: setTimeout(() => {
- const message = [
- `A delayRender()`,
- label ? `"${label}"` : null,
- `was called but not cleared after ${timeoutToUse}ms. See https://remotion.dev/docs/timeout for help.`,
- retriesLeft > 0 ? DELAY_RENDER_RETRIES_LEFT + retriesLeft : null,
- retriesLeft > 0 ? DELAY_RENDER_RETRY_TOKEN : null,
- DELAY_RENDER_CALLSTACK_TOKEN,
- called,
- ]
- .filter(truthy)
- .join(' ');
-
- cancelRenderInternal(scope, Error(message));
- }, timeoutToUse),
- };
- }
- }
+ scope.remotion_puppeteerTimeout ??
+ defaultTimeout) - 2000;
+ const retriesLeft = (options?.retries ?? 0) - (scope.remotion_attempt - 1);
+ scope.remotion_delayRenderTimeouts[handle] = {
+ label: label ?? null,
+ startTime: Date.now(),
+ timeout: setTimeout(() => {
+ const message = [
+ `A delayRender()`,
+ label ? `"${label}"` : null,
+ `was called but not cleared after ${timeoutToUse}ms. See https://remotion.dev/docs/timeout for help.`,
+ retriesLeft > 0 ? DELAY_RENDER_RETRIES_LEFT + retriesLeft : null,
+ retriesLeft > 0 ? DELAY_RENDER_RETRY_TOKEN : null,
+ DELAY_RENDER_CALLSTACK_TOKEN,
+ called,
+ ]
+ .filter(truthy)
+ .join(' ');
- if (typeof scope !== 'undefined') {
- scope.remotion_renderReady = false;
+ cancelRenderInternal(scope, Error(message));
+ }, timeoutToUse),
+ };
}
- return handle;
-};
+ scope.remotion_renderReady = false;
-/*
- * @description Call this function to signal that a frame should not be rendered until an asynchronous task (such as data fetching) is complete. Use continueRender(handle) to proceed with rendering once the task is complete.
- * @see [Documentation](https://remotion.dev/docs/delay-render)
- */
-export const delayRender = (
- label?: string,
- options?: DelayRenderOptions,
-): number => {
- return delayRenderInternal({
- scope: typeof window !== 'undefined' ? window : undefined,
- environment: getRemotionEnvironment(),
- label: label ?? null,
- options: options ?? {},
- });
+ return handle;
};
/**
@@ -131,7 +109,7 @@ export const continueRenderInternal = ({
environment,
logLevel,
}: {
- scope: DelayRenderScope | undefined;
+ scope: DelayRenderScope;
handle: number;
environment: RemotionEnvironment;
logLevel: LogLevel;
@@ -191,13 +169,14 @@ export const continueRenderInternal = ({
* @see [Documentation](https://remotion.dev/docs/continue-render)
*/
export const continueRender = (handle: number): void => {
+ if (typeof window === 'undefined') {
+ return;
+ }
+
continueRenderInternal({
- scope: typeof window !== 'undefined' ? window : undefined,
+ scope: window,
handle,
environment: getRemotionEnvironment(),
- logLevel:
- typeof window !== 'undefined'
- ? (window.remotion_logLevel ?? 'info')
- : 'info',
+ logLevel: window.remotion_logLevel ?? 'info',
});
};