Skip to content

🎥 Make videos programmatically with React

Web Renderer: Wait for HtmlInCanvas pixels before still capture

Jonny Burgerfef244ede109
diff --git a/packages/web-renderer/src/render-still-on-web.tsx b/packages/web-renderer/src/render-still-on-web.tsx
index 6e346ef3e3..06506cfb99 100644
--- a/packages/web-renderer/src/render-still-on-web.tsx
+++ b/packages/web-renderer/src/render-still-on-web.tsx
@@ -7,7 +7,10 @@ import type {$ZodObject} from 'zod/v4/core';
import type {WebRendererOnArtifact} from './artifact';
import {handleArtifacts} from './artifact';
import {checkForError, createScaffold} from './create-scaffold';
-import {supportsNativeHtmlInCanvas} from './html-in-canvas';
+import {
+ containsLayoutSubtreeCanvas,
+ supportsNativeHtmlInCanvas,
+} from './html-in-canvas';
import {makeInternalState} from './internal-state';
import type {CompositionCalculateMetadataOrExplicit} from './props-if-has-props';
import type {InputPropsIfHasProps} from './render-media-on-web';
@@ -195,6 +198,15 @@ async function internalRenderStillOnWeb<
await waitForRenderReady();
+ if (containsLayoutSubtreeCanvas(div)) {
+ // The paint callback can finish before its transferred OffscreenCanvas
+ // is presented on the layout canvas. Capture after a full paint cycle.
+ await new Promise<void>((resolve) => {
+ requestAnimationFrame(() => requestAnimationFrame(() => resolve()));
+ });
+ await waitForRenderReady();
+ }
+
if (signal?.aborted) {
throw new Error('renderStillOnWeb() was cancelled');
}