refine icon indicating copy to clipboard operation
refine copied to clipboard

`delayRender` immediately cancels render with negative timeout when `timeoutInMilliseconds <= 2000`

Open codeCraft-Ritik opened this issue 2 months ago • 2 comments

Describe the bug

Describe the bug

When a custom timeoutInMilliseconds of 2000 or less is passed to delayRender(), Remotion unconditionally subtracts 2000 from the timeout value.

In packages/core/src/delay-render.ts:

if (environment.isRendering) {
  const timeoutToUse =
    (options?.timeoutInMilliseconds ??
      scope.remotion_puppeteerTimeout ??
      defaultTimeout) - 2000;

For example, if timeoutInMilliseconds: 1000 is specified: timeoutToUse = 1000 - 2000 = -1000ms. In JavaScript, setTimeout(callback, -1000) executes immediately on the next tick. The render is instantly aborted with an erroneous error message:

A delayRender() "my-fetch" was called but not cleared after -1000ms.

Steps To Reproduce

Steps To Reproduce

  1. In a Remotion composition, call delayRender with a 1.5s timeout:
import { delayRender, continueRender } from 'remotion';

export const MyComp = () => {
  const [handle] = useState(() =>
    delayRender('fast-api', { timeoutInMilliseconds: 1500 }),
  );

  useEffect(() => {
    setTimeout(() => {
      continueRender(handle);
    }, 200);
  }, [handle]);

  return <div>Hello</div>;
};
  1. Render the video with @remotion/renderer.
  2. The render immediately fails after 1ms before the 200ms task can finish, with: A delayRender() "fast-api" was called but not cleared after -500ms.

Expected behavior

Expected behavior

Remotion should respect explicit timeoutInMilliseconds passed by the developer without subtracting the 2,000ms Puppeteer safety buffer, and ensure the timeout is at least 1ms.

Suggested Fix

--- a/packages/core/src/delay-render.ts
+++ b/packages/core/src/delay-render.ts
@@ -83,9 +83,12 @@ export const delayRenderInternal = ({
 	const called = Error().stack?.replace(/^Error/g, '') ?? '';
 
 	if (environment.isRendering) {
+		const explicitTimeout = options?.timeoutInMilliseconds;
 		const timeoutToUse =
-			(options?.timeoutInMilliseconds ??
-				scope.remotion_puppeteerTimeout ??
-				defaultTimeout) - 2000;
+			explicitTimeout !== undefined
+				? Math.max(1, explicitTimeout)
+				: Math.max(
+						1,
+						(scope.remotion_puppeteerTimeout ?? defaultTimeout) - 2000,
+				  );
 		const retriesLeft = (options?.retries ?? 0) - (scope.remotion_attempt - 1);
 		scope.remotion_delayRenderTimeouts[handle] = {

Packages

@remotion/core

Additional Context

No response

codeCraft-Ritik avatar Sep 16 '26 04:09 codeCraft-Ritik

Hi, I'd like to work on this issue. I can reproduce the problem and would like to submit a fix with a regression test. Could you assign the issue to me?

Hirak-abc avatar Sep 26 '26 04:09 Hirak-abc

hey , if this bug is not resolved , i can pick this , I can reproduce the problem

Mohitskilljourney avatar Oct 08 '26 06:10 Mohitskilljourney