🎥 Make videos programmatically with React
remotion: Simplify Series.Sequence schema fix
Jonny Burger683d88d37edf
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsxindex ff13c98083..c6d56d1f8f 100644--- a/packages/core/src/Sequence.tsx+++ b/packages/core/src/Sequence.tsx@@ -13,7 +13,10 @@ import type {EffectDefinition} from './effects/effect-types.js';import {Freeze} from './freeze.js';import {useNonce} from './nonce.js';import {PremountContext} from './PremountContext.js';-import {sequenceSchema, type SequenceSchema} from './sequence-field-schema.js';+import {+ sequenceSchema,+ sequenceSchemaWithoutFrom,+} from './sequence-field-schema.js';import type {SequenceContextType} from './SequenceContext.js';import {SequenceContext} from './SequenceContext.js';import {SequenceManager} from './SequenceManager.js';@@ -77,10 +80,6 @@ export type SequencePropsWithoutDuration = {* @deprecated For internal use only.*/readonly _remotionInternalDocumentationLink?: string;- /**- * @deprecated For internal use only.- */- readonly _remotionInternalSchema?: SequenceSchema;/*** @deprecated For internal use only.*/@@ -129,7 +128,6 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<_remotionInternalLoopDisplay: loopDisplay,_remotionInternalStack: stack,_remotionInternalDocumentationLink: documentationLink,- _remotionInternalSchema: _schema,_remotionInternalPremountDisplay: premountDisplay,_remotionInternalPostmountDisplay: postmountDisplay,_remotionInternalIsMedia: isMedia,@@ -555,7 +553,12 @@ const SequenceInner = forwardRef(SequenceRefForwardingFunction);*/export const Sequence = wrapInSchema({Component: SequenceInner,- schema: (props: SequenceProps) =>- props._remotionInternalSchema ?? sequenceSchema,+ schema: sequenceSchema,+ supportsEffects: false,+});++export const SequenceWithoutFrom = wrapInSchema({+ Component: SequenceInner,+ schema: sequenceSchemaWithoutFrom,supportsEffects: false,});diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.tsindex 3b44e378b6..a9c2f61232 100644--- a/packages/core/src/internals.ts+++ b/packages/core/src/internals.ts@@ -142,6 +142,7 @@ import {} from './sequence-node-path.js';import type {ResolvedStackLocation} from './sequence-stack-traces.js';import {SequenceStackTracesUpdateContext} from './sequence-stack-traces.js';+import {SequenceWithoutFrom} from './Sequence.js';import {SequenceContext} from './SequenceContext.js';import type {CannotUpdateSequenceReason} from './SequenceManager.js';import {@@ -283,6 +284,7 @@ export const Internals = {SequenceStackTracesUpdateContext,wrapInSchema,sequenceSchema,+ SequenceWithoutFrom,sequenceStyleSchema,sequenceVisualStyleSchema,sequencePremountSchema,diff --git a/packages/core/src/no-react.ts b/packages/core/src/no-react.tsindex 2d9fc66d96..a27728ed57 100644--- a/packages/core/src/no-react.ts+++ b/packages/core/src/no-react.ts@@ -34,10 +34,7 @@ import {DATE_TOKEN, FILE_TOKEN} from './input-props-serialization.js';import {colorNames, processColor} from './interpolate-colors';import {proResProfileOptions} from './prores-profile';import {parseScaleValue, serializeScaleValue} from './scale-value';-import {- sequenceSchema,- sequenceSchemaWithoutFrom,-} from './sequence-field-schema';+import {sequenceSchema} from './sequence-field-schema';import {truthy} from './truthy';import {ENABLE_V5_BREAKING_CHANGES} from './v5-flag';import {validateFrame} from './validate-frame';@@ -77,7 +74,6 @@ export const NoReactInternals = {proResProfileOptions,findPropsToDelete,sequenceSchema,- sequenceSchemaWithoutFrom,parseScaleValue,serializeScaleValue,};diff --git a/packages/core/src/series/index.tsx b/packages/core/src/series/index.tsxindex 57fed31702..b21c042614 100644--- a/packages/core/src/series/index.tsx+++ b/packages/core/src/series/index.tsx@@ -6,12 +6,9 @@ import React, {type PropsWithChildren,} from 'react';import {addSequenceStackTraces} from '../enable-sequence-stack-traces.js';-import {- sequenceSchemaDefaultLayoutNone,- sequenceSchemaWithoutFrom,-} from '../sequence-field-schema.js';+import {sequenceSchemaDefaultLayoutNone} from '../sequence-field-schema.js';import type {LayoutAndStyle, SequenceProps} from '../Sequence.js';-import {Sequence} from '../Sequence.js';+import {Sequence, SequenceWithoutFrom} from '../Sequence.js';import {validateDurationInFrames} from '../validation/validate-duration-in-frames.js';import {wrapInSchema} from '../wrap-in-schema.js';import {flattenChildren} from './flatten-children.js';@@ -43,7 +40,7 @@ const SeriesSequenceRefForwardingFunction: React.ForwardRefRenderFunction<const SeriesSequence = forwardRef(SeriesSequenceRefForwardingFunction);type SeriesProps = SequenceProps;-const SequenceWithRef = Sequence as React.ComponentType<+const SequenceWithoutFromWithRef = SequenceWithoutFrom as React.ComponentType<SequenceProps & {readonly ref?: React.Ref<HTMLDivElement>}>;@@ -120,7 +117,7 @@ const SeriesInner: FC<SeriesProps> = (props) => {startFrame += durationInFramesProp + offset;return (- <SequenceWithRef+ <SequenceWithoutFromWithRefref={castedChild.ref}name={name || '<Series.Sequence>'}_remotionInternalDocumentationLink={@@ -129,10 +126,9 @@ const SeriesInner: FC<SeriesProps> = (props) => {from={currentStartFrame}durationInFrames={durationInFramesProp}{...passedProps}- _remotionInternalSchema={sequenceSchemaWithoutFrom}>{child}- </SequenceWithRef>+ </SequenceWithoutFromWithRef>);});}, [props.children]);diff --git a/packages/core/src/wrap-in-schema.ts b/packages/core/src/wrap-in-schema.tsindex d25dc0d05d..c1d009b6c4 100644--- a/packages/core/src/wrap-in-schema.ts+++ b/packages/core/src/wrap-in-schema.ts@@ -109,9 +109,13 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>({Component: React.ComponentType<Props & {readonly _experimentalControls: SequenceControls | undefined}>;- schema: S | ((props: Props) => S);+ schema: S;supportsEffects: boolean;}): React.ComponentType<Props> => {+ // Schema is static for a component, so we move this outside+ const flatSchema = getFlatSchemaWithAllKeys(schema);+ const flatKeys = Object.keys(flatSchema);+const Wrapped = forwardRef<unknown, Props>((props, ref) => {const env = useRemotionEnvironment();@@ -147,14 +151,6 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>({});}- const resolvedSchema =- typeof schema === 'function' ? schema(props as Props) : schema;- // eslint-disable-next-line react-hooks/rules-of-hooks- const flatKeys = useMemo(- () => Object.keys(getFlatSchemaWithAllKeys(resolvedSchema)),- [resolvedSchema],- );-// eslint-disable-next-line react-hooks/rules-of-hooksconst [overrideId] = useState(() => {const {stack} = props as {stack?: string};@@ -191,18 +187,18 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>({// eslint-disable-next-line react-hooks/rules-of-hooksconst controls = useMemo((): SequenceControls => {return {- schema: resolvedSchema,+ schema,currentRuntimeValueDotNotation,overrideId,supportsEffects,};- }, [currentRuntimeValueDotNotation, overrideId, resolvedSchema]);+ }, [currentRuntimeValueDotNotation, overrideId]);// 3. Apply drag/code overrides on top of the runtime values.// eslint-disable-next-line react-hooks/rules-of-hooksconst {merged: valuesDotNotation, propsToDelete} = useMemo(() => {return computeEffectiveSchemaValuesDotNotation({- schema: resolvedSchema,+ schema,currentValue: currentRuntimeValueDotNotation,overrideValues: nodePath === null ? {} : getDragOverrides(nodePath),propStatus:@@ -217,11 +213,10 @@ export const wrapInSchema = <S extends SequenceSchema, Props extends object>({nodePath,codeValues,frame,- resolvedSchema,]);// 4. Eliminate values forbidden by the resolved discriminated union.- const activeKeys = selectActiveKeys(resolvedSchema, valuesDotNotation);+ const activeKeys = selectActiveKeys(schema, valuesDotNotation);// 5. Apply the active values back onto the props.const mergedProps = mergeValues({diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsxindex 9360c135e4..a7fbaf8f55 100644--- a/packages/transitions/src/TransitionSeries.tsx+++ b/packages/transitions/src/TransitionSeries.tsx@@ -19,6 +19,8 @@ import type {} from './types.js';import {validateDurationInFrames} from './validate.js';+const {SequenceWithoutFrom} = Internals;+const TransitionSeriesTransition = function <PresentationProps extends Record<string, unknown>,>(_props: TransitionSeriesTransitionProps<PresentationProps>) {@@ -461,13 +463,12 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({const UppercasePrevPresentation = prevPresentation.component;return (- <Sequence+ <SequenceWithoutFrom// eslint-disable-next-line react/no-array-index-keykey={i}from={actualStartFrame}durationInFrames={durationInFramesProp}{...passedProps}- _remotionInternalSchema={NoReactInternals.sequenceSchemaWithoutFrom}name={passedProps.name || '<TS.Sequence>'}_remotionInternalDocumentationLink={passedProps.name@@ -516,7 +517,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({</UppercasePrevPresentation></WrapInExitingProgressContext></UppercaseNextPresentation>- </Sequence>+ </SequenceWithoutFrom>);}@@ -526,13 +527,12 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({const UppercasePrevPresentation = prevPresentation.component;return (- <Sequence+ <SequenceWithoutFrom// eslint-disable-next-line react/no-array-index-keykey={i}from={actualStartFrame}durationInFrames={durationInFramesProp}{...passedProps}- _remotionInternalSchema={NoReactInternals.sequenceSchemaWithoutFrom}name={passedProps.name || '<TS.Sequence>'}_remotionInternalDocumentationLink={passedProps.name@@ -561,7 +561,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({{child}</WrapInEnteringProgressContext></UppercasePrevPresentation>- </Sequence>+ </SequenceWithoutFrom>);}@@ -571,13 +571,12 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({const UppercaseNextPresentation = nextPresentation.component;return (- <Sequence+ <SequenceWithoutFrom// eslint-disable-next-line react/no-array-index-keykey={i}from={actualStartFrame}durationInFrames={durationInFramesProp}{...passedProps}- _remotionInternalSchema={NoReactInternals.sequenceSchemaWithoutFrom}name={passedProps.name || '<TS.Sequence>'}_remotionInternalDocumentationLink={passedProps.name@@ -604,18 +603,17 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({{child}</WrapInExitingProgressContext></UppercaseNextPresentation>- </Sequence>+ </SequenceWithoutFrom>);}return (- <Sequence+ <SequenceWithoutFrom// eslint-disable-next-line react/no-array-index-keykey={i}from={actualStartFrame}durationInFrames={durationInFramesProp}{...passedProps}- _remotionInternalSchema={NoReactInternals.sequenceSchemaWithoutFrom}name={passedProps.name || '<TS.Sequence>'}_remotionInternalDocumentationLink={passedProps.name@@ -624,7 +622,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({}>{child}- </Sequence>+ </SequenceWithoutFrom>);});