🎥 Make videos programmatically with React
`remotion`: Allow empty sequences (#7321)
Jonny Burger13e871b40e7e
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsxindex 0d901b98aa..6d035a4e0c 100644--- a/packages/core/src/Sequence.tsx+++ b/packages/core/src/Sequence.tsx@@ -49,7 +49,7 @@ export type LayoutAndStyle =};export type SequencePropsWithoutDuration = {- readonly children: React.ReactNode;+ readonly children?: React.ReactNode;readonly width?: number;readonly height?: number;readonly from?: number;diff --git a/packages/core/src/series/index.tsx b/packages/core/src/series/index.tsxindex 5dead857af..e4dd2625c8 100644--- a/packages/core/src/series/index.tsx+++ b/packages/core/src/series/index.tsx@@ -67,12 +67,6 @@ const SeriesInner: FC<SeriesProps> = (props) => {const debugInfo = `index = ${i}, duration = ${castedChild.props.durationInFrames}`;- if (!castedChild?.props.children) {- throw new TypeError(- `A <Series.Sequence /> component (${debugInfo}) was detected to not have any children. Delete it to fix this error.`,- );- }-const durationInFramesProp = castedChild.props.durationInFrames;const {durationInFrames,diff --git a/packages/core/src/test/sequence-validation.test.tsx b/packages/core/src/test/sequence-validation.test.tsxindex 5c1ed55c3c..e8b348b13b 100644--- a/packages/core/src/test/sequence-validation.test.tsx+++ b/packages/core/src/test/sequence-validation.test.tsx@@ -94,4 +94,13 @@ describe('Composition-validation render should NOT throw with valid props', () =),).not.toThrow();});+ test('It should allow no children', () => {+ expect(() =>+ render(+ <WrapSequenceContext>+ <Sequence durationInFrames={100} from={0} />+ </WrapSequenceContext>,+ ),+ ).not.toThrow();+ });});diff --git a/packages/core/src/test/series.test.tsx b/packages/core/src/test/series.test.tsxindex f57f44fa83..9286a80890 100644--- a/packages/core/src/test/series.test.tsx+++ b/packages/core/src/test/series.test.tsx@@ -200,19 +200,22 @@ test('Should allow whitespace', () => {expect(outerHtml).toBe(`${ABS_FILL}<div>second 1</div></div>`);});test('Handle empty Series.Sequence', () => {- expect(() =>- renderForFrame(- 11,+ const outerHTML = renderForFrame(+ 11,+ <WrapSequenceContext><Series><Series.Sequence durationInFrames={10}><First /></Series.Sequence><Series.Sequence durationInFrames={10} />- </Series>,- ),- ).toThrow(- /A <Series.Sequence \/> component \(index = 1, duration = 10\) was detected to not have any children\. Delete it to fix this error\./,+ <Series.Sequence durationInFrames={10}>+ <Second />+ </Series.Sequence>+ </Series>+ </WrapSequenceContext>,);++ expect(outerHTML).toBe(ABS_FILL + '</div>');});test('Should allow negative overlap prop', () => {diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsxindex b6dd561958..49b72dda72 100644--- a/packages/transitions/src/TransitionSeries.tsx+++ b/packages/transitions/src/TransitionSeries.tsx@@ -340,12 +340,6 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({const debugInfo = `index = ${i}, duration = ${castedChildAgain.props.durationInFrames}`;- if (!castedChildAgain?.props.children) {- throw new TypeError(- `A <TransitionSeries.Sequence /> component (${debugInfo}) was detected to not have any children. Delete it to fix this error.`,- );- }-const durationInFramesProp = castedChildAgain.props.durationInFrames;const {durationInFrames,diff --git a/packages/transitions/src/test/transitions.test.tsx b/packages/transitions/src/test/transitions.test.tsxindex f7d42afc3d..d3ae752434 100644--- a/packages/transitions/src/test/transitions.test.tsx+++ b/packages/transitions/src/test/transitions.test.tsx@@ -5,6 +5,9 @@ import {linearTiming} from '../timings/linear-timing.js';import {TransitionSeries} from '../TransitionSeries.js';import {renderForFrame} from './render-for-frame.js';+const ABS_FILL =+ '<div style="position:absolute;top:0;left:0;right:0;bottom:0;width:100%;height:100%;display:flex">';+const Letter: React.FC<{children: React.ReactNode;color: string;@@ -51,3 +54,20 @@ test('Should throw if two transitions in a row', () => {'A <TransitionSeries.Transition /> component must not be followed by another <TransitionSeries.Transition /> component (nth children = 1 and 2)',);});++test('Should allow empty TransitionSeries.Sequence', () => {+ const outerHTML = renderForFrame(+ 70,+ <TransitionSeries>+ <TransitionSeries.Sequence durationInFrames={60}>+ <Letter color="green">C</Letter>+ </TransitionSeries.Sequence>+ <TransitionSeries.Sequence durationInFrames={60} />+ <TransitionSeries.Sequence durationInFrames={60}>+ <Letter color="blue">D</Letter>+ </TransitionSeries.Sequence>+ </TransitionSeries>,+ );++ expect(outerHTML).toBe(`${ABS_FILL}${ABS_FILL}</div></div>`);+});