🎥 Make videos programmatically with React
`remotion`: Fix Chrome 157 crashes with nested `<HtmlInCanvas>`
JonnyBurger621442100618
diff --git a/packages/core/src/HtmlInCanvas.tsx b/packages/core/src/HtmlInCanvas.tsxindex 53f000a711..a076923253 100644--- a/packages/core/src/HtmlInCanvas.tsx+++ b/packages/core/src/HtmlInCanvas.tsx@@ -521,11 +521,15 @@ const HtmlInCanvasContent = forwardRef<const canRetryMissingPaintRecord = !isRendering || isClientSideRendering;const usesDirectLayoutCanvas =onPaint === undefined && onInit === undefined;- const paintTargetMode = usesDirectLayoutCanvas- ? 'direct'- : isRendering- ? 'copied'- : 'transferred';+ // Keep a nested drawable canvas separate from the bitmap captured by its+ // parent. Reusing it for both can crash Chromium during raster invalidation.+ const paintTargetMode = ancestorPaintState+ ? 'copied'+ : usesDirectLayoutCanvas+ ? 'direct'+ : isRendering+ ? 'copied'+ : 'transferred';if (!isHtmlInCanvasSupported()) {cancelRender(new Error(getHtmlInCanvasUnsupportedMessage()));@@ -852,10 +856,11 @@ const HtmlInCanvasContent = forwardRef<};}, [paintState]);- // Default paint handlers draw synchronously on the layout canvas itself.- // ElementImage can only be drawn into its associated canvas, so custom- // handlers retain a transferred target. Rendering copies it to a separate- // visible canvas without waiting for the transferred canvas to present.+ // Non-nested default handlers paint directly on the layout canvas. Nested+ // canvases and custom handlers retain a transferred target because an+ // ElementImage can only be drawn into its associated canvas. Nested canvases+ // and rendering copy it to a separate visible canvas without waiting for+ // the transferred canvas to present.useLayoutEffect(() => {const placeholder = canvas2dRef.current;if (!placeholder) {diff --git a/packages/jonnys-videos/src/disco-light-show/MasterWithEffect.tsx b/packages/jonnys-videos/src/disco-light-show/MasterWithEffect.tsxindex 51ad3db0f5..de2f18934a 100644--- a/packages/jonnys-videos/src/disco-light-show/MasterWithEffect.tsx+++ b/packages/jonnys-videos/src/disco-light-show/MasterWithEffect.tsx@@ -3,6 +3,7 @@ import {noise} from '@remotion/effects/noise';import {scanlines} from '@remotion/effects/scanlines';import {Interactive,+ Internals,AbsoluteFill,Easing,HtmlInCanvas,@@ -133,7 +134,10 @@ const MasterWithEffectInner: React.FC = () => {transformOrigin: 'center center',}}>- <MyComponent />+ {/* Chrome 157 can crash when premounted layers enter a drawable canvas. */}+ <Internals.DefaultPremountContext.Provider value={0}>+ <MyComponent />+ </Internals.DefaultPremountContext.Provider></HtmlInCanvas><AbsoluteFillstyle={{diff --git a/packages/jonnys-videos/src/paper-disco/PaperDiscoSting.tsx b/packages/jonnys-videos/src/paper-disco/PaperDiscoSting.tsxindex 6d63f7c193..6b60eb504d 100644--- a/packages/jonnys-videos/src/paper-disco/PaperDiscoSting.tsx+++ b/packages/jonnys-videos/src/paper-disco/PaperDiscoSting.tsx@@ -63,7 +63,8 @@ const PaperDiscoStingInner: React.FC = () => {height: 900,overflow: 'visible',transformOrigin: '50% 50%',- scale: interpolate(frame, [0, 8], [0, 1], {+ // Keep the transform invertible for Chrome 157 canvas capture.+ scale: interpolate(frame, [0, 8], [0.0001, 1], {extrapolateLeft: 'clamp',extrapolateRight: 'clamp',posterize: 2,