🎥 Make videos programmatically with React
only allow objects as input props
Jonny Burger6fc43067e3e8
diff --git a/packages/cli/src/codemods/update-default-props.ts b/packages/cli/src/codemods/update-default-props.tsindex 538a17c856..420d53a1a7 100644--- a/packages/cli/src/codemods/update-default-props.ts+++ b/packages/cli/src/codemods/update-default-props.ts@@ -104,7 +104,7 @@ export const updateDefaultProps = async ({}: {input: string;compositionId: string;- newDefaultProps: unknown;+ newDefaultProps: Record<string, unknown>;enumPaths: EnumPath[];}): Promise<string> => {const starter = findStarter({input, compositionId});diff --git a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx b/packages/cli/src/editor/components/RenderModal/RenderModal.tsxindex 199ff11120..58001c4f02 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModal.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModal.tsx@@ -208,7 +208,7 @@ export const RenderModal: React.FC<{initialGl: OpenGlRenderer | null;initialIgnoreCertificateErrors: boolean;initialHeadless: boolean;- defaultProps: unknown;+ defaultProps: Record<string, unknown>;inFrameMark: number | null;outFrameMark: number | null;}> = ({diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsxindex 64830b0b3a..52f801d45f 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx@@ -49,7 +49,7 @@ type AllCompStates = {export type State =| {str: string;- value: unknown;+ value: Record<string, unknown>;validJSON: true;}| {@@ -124,8 +124,8 @@ const setPersistedShowWarningState = (val: boolean) => {export const RenderModalData: React.FC<{composition: AnyComposition;- inputProps: unknown;- setInputProps: React.Dispatch<React.SetStateAction<unknown>>;+ inputProps: Record<string, unknown>;+ setInputProps: React.Dispatch<React.SetStateAction<Record<string, unknown>>>;compact: boolean;mayShowSaveButton: boolean;propsEditType: PropsEditType;@@ -150,7 +150,7 @@ export const RenderModalData: React.FC<{return null;}- const value = inputProps ?? {};+ const value = inputProps;return serializeJSONWithDate({data: value,indent: 2,@@ -172,7 +172,7 @@ export const RenderModalData: React.FC<{}if (!composition.schema) {- return z.any();+ return z.object({});}if (!(typeof composition.schema.safeParse === 'function')) {diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsxindex eefca47b76..654a361fa4 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx@@ -31,7 +31,7 @@ export type EditType = 'inputProps' | 'defaultProps';export const RenderModalJSONPropsEditor: React.FC<{value: unknown;- setValue: React.Dispatch<React.SetStateAction<unknown>>;+ setValue: React.Dispatch<React.SetStateAction<Record<string, unknown>>>;zodValidationResult: Zod.SafeParseReturnType<unknown, unknown>;switchToSchema: () => void;onSave: () => void;diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsxindex d085d8d2db..b55032616c 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx@@ -1,8 +1,12 @@import React, {useCallback} from 'react';-import type {z} from 'zod';+import type {AnyZodObject, z} from 'zod';import {useZodIfPossible} from '../../get-zod-if-possible';import {VERTICAL_SCROLLBAR_CLASSNAME} from '../../Menu/is-menu-item';-import {InvalidDefaultProps, InvalidSchema} from './SchemaErrorMessages';+import {+ InvalidDefaultProps,+ InvalidSchema,+ TopLevelZodValue,+} from './SchemaErrorMessages';import {ZodObjectEditor} from './ZodObjectEditor';const scrollable: React.CSSProperties = {@@ -13,12 +17,12 @@ const scrollable: React.CSSProperties = {};export const SchemaEditor: React.FC<{- schema: z.ZodTypeAny;+ schema: AnyZodObject;value: unknown;- setValue: React.Dispatch<React.SetStateAction<unknown>>;+ setValue: React.Dispatch<React.SetStateAction<Record<string, unknown>>>;zodValidationResult: z.SafeParseReturnType<unknown, unknown>;compact: boolean;- defaultProps: unknown;+ defaultProps: Record<string, unknown>;onSave: (updater: (oldState: unknown) => unknown) => void;showSaveButton: boolean;saving: boolean;@@ -60,31 +64,31 @@ export const SchemaEditor: React.FC<{);}- if (typeName === z.ZodFirstPartyTypeKind.ZodObject) {- return (- <div style={scrollable} className={VERTICAL_SCROLLBAR_CLASSNAME}>- <ZodObjectEditor- value={value as Record<string, unknown>}- setValue={setValue}- jsonPath={[]}- schema={schema}- compact={compact}- defaultValue={defaultProps as Record<string, unknown>}- onSave={- onSave as (- newValue: (- oldVal: Record<string, unknown>- ) => Record<string, unknown>- ) => void- }- showSaveButton={showSaveButton}- onRemove={null}- saving={saving}- saveDisabledByParent={saveDisabledByParent}- />- </div>- );+ if (typeName !== z.ZodFirstPartyTypeKind.ZodObject) {+ return <TopLevelZodValue typeReceived={typeName} />;}- return null;+ return (+ <div style={scrollable} className={VERTICAL_SCROLLBAR_CLASSNAME}>+ <ZodObjectEditor+ value={value as Record<string, unknown>}+ setValue={setValue}+ jsonPath={[]}+ schema={schema}+ compact={compact}+ defaultValue={defaultProps as Record<string, unknown>}+ onSave={+ onSave as (+ newValue: (+ oldVal: Record<string, unknown>+ ) => Record<string, unknown>+ ) => void+ }+ showSaveButton={showSaveButton}+ onRemove={null}+ saving={saving}+ saveDisabledByParent={saveDisabledByParent}+ />+ </div>+ );};diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.tsxindex 55380f5e6f..6e3505f3cb 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.tsx@@ -133,3 +133,23 @@ export const InvalidSchema: React.FC<{</div>);};++export const TopLevelZodValue: React.FC<{+ typeReceived: string;+}> = ({typeReceived}) => {+ return (+ <div style={explainer}>+ <div style={errorExplanation}>+ The top-level type of the schema must be a pure{' '}+ <code style={codeSnippet}>z.object</code>. Instead got a schema of type{' '}+ <code style={codeSnippet}>{typeReceived}</code>+ </div>+ <Spacing y={1} />+ <div style={errorExplanation}>+ Fix the schema by changing the top-level Zod type to an object.+ </div>+ <Spacing y={2} block />+ <Button onClick={openDocs}>Learn more</Button>+ </div>+ );+};diff --git a/packages/cli/src/editor/components/RenderQueue/actions.ts b/packages/cli/src/editor/components/RenderQueue/actions.tsindex b56071f820..6acf3360a5 100644--- a/packages/cli/src/editor/components/RenderQueue/actions.ts+++ b/packages/cli/src/editor/components/RenderQueue/actions.ts@@ -70,7 +70,7 @@ export const addStillRenderJob = ({chromiumOptions: RequiredChromiumOptions;delayRenderTimeout: number;envVariables: Record<string, string>;- inputProps: unknown;+ inputProps: Record<string, unknown>;}) => {return callApi('/api/render', {compositionId,@@ -139,7 +139,7 @@ export const addVideoRenderJob = ({disallowParallelEncoding: boolean;chromiumOptions: RequiredChromiumOptions;envVariables: Record<string, string>;- inputProps: unknown;+ inputProps: Record<string, unknown>;}) => {return callApi('/api/render', {compositionId,diff --git a/packages/cli/src/editor/components/RightPanel.tsx b/packages/cli/src/editor/components/RightPanel.tsxindex cb0c950a78..84aaa50f3f 100644--- a/packages/cli/src/editor/components/RightPanel.tsx+++ b/packages/cli/src/editor/components/RightPanel.tsx@@ -27,20 +27,29 @@ const PropsEditor: React.FC<{const {props, updateProps} = useContext(Internals.EditorPropsContext);const setInputProps = useCallback(- (newProps: unknown | ((oldProps: unknown) => unknown)) => {+ (+ newProps:+ | Record<string, unknown>+ | ((oldProps: Record<string, unknown>) => Record<string, unknown>)+ ) => {updateProps({id: composition.id,- defaultProps: composition.defaultProps as object,- newProps: newProps as object,+ defaultProps: composition.defaultProps as Record<string, unknown>,+ newProps,});},[composition.defaultProps, composition.id, updateProps]);+ const actualProps = useMemo(+ () => props[composition.id] ?? composition.defaultProps ?? {},+ [composition.defaultProps, composition.id, props]+ );+return (<RenderModalDatacomposition={composition}- inputProps={props[composition.id] ?? composition.defaultProps}+ inputProps={actualProps}setInputProps={setInputProps}compactmayShowSaveButtondiff --git a/packages/cli/src/editor/state/modals.ts b/packages/cli/src/editor/state/modals.tsindex ed11b9db3b..2d114d6da1 100644--- a/packages/cli/src/editor/state/modals.ts+++ b/packages/cli/src/editor/state/modals.ts@@ -46,7 +46,7 @@ export type RenderModalState = {initialHeadless: boolean;minConcurrency: number;maxConcurrency: number;- defaultProps: unknown;+ defaultProps: Record<string, unknown>;inFrameMark: number | null;outFrameMark: number | null;};diff --git a/packages/cli/src/get-input-props.ts b/packages/cli/src/get-input-props.tsindex 22781544e3..1d97107968 100644--- a/packages/cli/src/get-input-props.ts+++ b/packages/cli/src/get-input-props.ts@@ -5,8 +5,8 @@ import {Log} from './log';import {parsedCli} from './parse-command-line';export const getInputProps = (- onUpdate: ((newProps: object) => void) | null-): object => {+ onUpdate: ((newProps: Record<string, unknown>) => void) | null+): Record<string, unknown> => {if (!parsedCli.props) {return {};}diff --git a/packages/cli/src/preview-server/render-queue/job.ts b/packages/cli/src/preview-server/render-queue/job.tsindex c2399e15b9..c69eac9118 100644--- a/packages/cli/src/preview-server/render-queue/job.ts+++ b/packages/cli/src/preview-server/render-queue/job.ts@@ -81,7 +81,7 @@ export type RenderJob = {cancelToken: ReturnType<typeof makeCancelSignal>;chromiumOptions: RequiredChromiumOptions;envVariables: Record<string, string>;- inputProps: unknown;+ inputProps: Record<string, unknown>;} & RenderJobDynamicFields;export type RenderJobWithCleanup = RenderJob & {@@ -131,7 +131,7 @@ export type AddRenderRequest = {chromiumOptions: RequiredChromiumOptions;delayRenderTimeout: number;envVariables: Record<string, string>;- inputProps: unknown;+ inputProps: Record<string, unknown>;} & AddRenderRequestDynamicFields;export type RemoveRenderRequest = {diff --git a/packages/cli/src/preview-server/render-queue/process-still.ts b/packages/cli/src/preview-server/render-queue/process-still.tsindex 88d68f8718..0dffc00d21 100644--- a/packages/cli/src/preview-server/render-queue/process-still.ts+++ b/packages/cli/src/preview-server/render-queue/process-still.ts@@ -38,7 +38,7 @@ export const processStill = async ({envVariables: job.envVariables,height: null,fullEntryPoint,- inputProps: job.inputProps as object,+ inputProps: job.inputProps,overwrite: true,port,publicDir,diff --git a/packages/cli/src/preview-server/render-queue/process-video.ts b/packages/cli/src/preview-server/render-queue/process-video.tsindex df917036f4..cd767fe415 100644--- a/packages/cli/src/preview-server/render-queue/process-video.ts+++ b/packages/cli/src/preview-server/render-queue/process-video.ts@@ -37,7 +37,7 @@ export const processVideoJob = async ({envVariables: job.envVariables,height: null,fullEntryPoint,- inputProps: job.inputProps as object,+ inputProps: job.inputProps,overwrite: true,port,publicDir,diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.tsindex 301c485f94..48cdef644a 100644--- a/packages/cli/src/render-flows/render.ts+++ b/packages/cli/src/render-flows/render.ts@@ -107,7 +107,7 @@ export const renderVideoFlow = async ({indent: boolean;shouldOutputImageSequence: boolean;publicDir: string | null;- inputProps: object;+ inputProps: Record<string, unknown>;envVariables: Record<string, string>;puppeteerTimeout: number;port: number | null;diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.tsindex 23de46bd80..613719025f 100644--- a/packages/cli/src/render-flows/still.ts+++ b/packages/cli/src/render-flows/still.ts@@ -76,7 +76,7 @@ export const renderStillFlow = async ({fullEntryPoint: string;entryPointReason: string;remainingArgs: string[];- inputProps: object;+ inputProps: Record<string, unknown>;envVariables: Record<string, string>;jpegQuality: number | undefined;browser: Browser;diff --git a/packages/cli/src/test/folder-tree.test.ts b/packages/cli/src/test/folder-tree.test.tsindex e34fc75b13..f7ff173941 100644--- a/packages/cli/src/test/folder-tree.test.ts+++ b/packages/cli/src/test/folder-tree.test.ts@@ -21,7 +21,7 @@ const getZ = async () => {test('Should create a good folder tree with 1 item inside and 1 item outside', async () => {const z = await getZ();- const any = z.any();+ const obj = z.object({});const tree = createFolderTree([{@@ -35,7 +35,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', anonce: 0,width: 1080,parentFolderName: null,- schema: any,+ schema: obj,},{component,@@ -48,7 +48,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', anonce: 0,width: 1080,parentFolderName: null,- schema: any,+ schema: obj,},],[@@ -76,7 +76,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', aid: 'my-comp',nonce: 0,width: 1080,- schema: any,+ schema: obj,},key: 'my-comp',type: 'composition',@@ -99,7 +99,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', aid: 'second-comp',nonce: 0,width: 1080,- schema: any,+ schema: obj,},key: 'second-comp',type: 'composition',@@ -109,7 +109,7 @@ test('Should create a good folder tree with 1 item inside and 1 item outside', atest('Should handle nested folders well', async () => {const z = await getZ();- const any = z.any();+ const obj = z.object({});const tree = createFolderTree([@@ -124,7 +124,7 @@ test('Should handle nested folders well', async () => {nonce: 0,width: 1080,parentFolderName: 'my-third-folder/my-second-folder',- schema: any,+ schema: obj,},],[@@ -177,7 +177,7 @@ test('Should handle nested folders well', async () => {id: 'my-comp',nonce: 0,width: 1080,- schema: any,+ schema: obj,},key: 'my-comp',type: 'composition',diff --git a/packages/compositor-darwin-arm64/compositor b/packages/compositor-darwin-arm64/compositorindex a0f3a66e9f..33736c5d76 100755Binary files a/packages/compositor-darwin-arm64/compositor and b/packages/compositor-darwin-arm64/compositor differdiff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsxindex 19575c5187..50f689fd6a 100644--- a/packages/core/src/Composition.tsx+++ b/packages/core/src/Composition.tsx@@ -1,7 +1,7 @@import type {ComponentType, PropsWithChildren} from 'react';import React, {Suspense, useContext, useEffect, useMemo} from 'react';import {createPortal} from 'react-dom';-import type {z} from 'zod';+import type {AnyZodObject, z} from 'zod';import {AbsoluteFill} from './AbsoluteFill.js';import {CanUseRemotionHooks,@@ -35,7 +35,10 @@ export type CompProps<Props> =component: LooseComponentType<Props>;};-export type StillProps<Schema extends z.ZodTypeAny, Props> = {+export type StillProps<+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+> = {width: number;height: number;id: string;@@ -43,10 +46,10 @@ export type StillProps<Schema extends z.ZodTypeAny, Props> = {} & CompProps<Props> &PropsIfHasProps<Schema, Props>;-export type CompositionProps<Schema extends z.ZodTypeAny, Props> = StillProps<- Schema,- Props-> & {+export type CompositionProps<+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+> = StillProps<Schema, Props> & {fps: number;durationInFrames: number;};@@ -64,7 +67,10 @@ const Fallback: React.FC = () => {* @see [Documentation](https://www.remotion.dev/docs/composition)*/-export const Composition = <Schema extends z.ZodTypeAny, Props>({+export const Composition = <+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+>({width,height,fps,diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsxindex fb13f9d786..690c771c51 100644--- a/packages/core/src/CompositionManager.tsx+++ b/packages/core/src/CompositionManager.tsx@@ -8,12 +8,15 @@ import React, {useRef,useState,} from 'react';-import type {z} from 'zod';+import type {AnyZodObject} from 'zod';import {SharedAudioContextProvider} from './audio/shared-audio-tags.js';import type {TFolder} from './Folder.js';import type {PropsIfHasProps} from './props-if-has-props.js';-export type TComposition<Schema extends z.ZodTypeAny, Props> = {+export type TComposition<+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+> = {width: number;height: number;fps: number;@@ -26,22 +29,37 @@ export type TComposition<Schema extends z.ZodTypeAny, Props> = {schema: Schema | null;} & PropsIfHasProps<Schema, Props>;-export type AnyComposition = TComposition<z.ZodTypeAny, unknown>;+export type AnyComposition = TComposition<+ AnyZodObject,+ Record<string, unknown> | undefined+>;-export type TCompMetadata<Schema extends z.ZodTypeAny, Props> = Pick<+export type TCompMetadata<+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+> = Pick<TComposition<Schema, Props>,'id' | 'height' | 'width' | 'fps' | 'durationInFrames' | 'defaultProps'>;-export type AnyCompMetadata = TCompMetadata<z.ZodTypeAny, unknown>;+export type AnyCompMetadata = TCompMetadata<+ AnyZodObject,+ Record<string, unknown> | undefined+>;-export type SmallTCompMetadata<T extends z.ZodTypeAny, Props> = Pick<+export type SmallTCompMetadata<+ T extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+> = Pick<TComposition<T, Props>,'id' | 'height' | 'width' | 'fps' | 'durationInFrames'> &Partial<Pick<TComposition<T, Props>, 'defaultProps'>>;-export type AnySmallCompMetadata = SmallTCompMetadata<z.ZodTypeAny, unknown>;+export type AnySmallCompMetadata = SmallTCompMetadata<+ AnyZodObject,+ Record<string, unknown> | undefined+>;type EnhancedTSequenceData =| {@@ -104,7 +122,10 @@ type BaseMetadata = Pick<export type CompositionManagerContext = {compositions: AnyComposition[];- registerComposition: <Schema extends z.ZodTypeAny, Props>(+ registerComposition: <+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+ >(comp: TComposition<Schema, Props>) => void;unregisterComposition: (name: string) => void;@@ -143,7 +164,10 @@ export const CompositionManager = createContext<CompositionManagerContext>({});export const compositionsRef = React.createRef<{- getCompositions: () => TCompMetadata<z.ZodTypeAny, unknown>[];+ getCompositions: () => TCompMetadata<+ AnyZodObject,+ Record<string, unknown> | undefined+ >[];}>();export const CompositionManagerProvider: React.FC<{@@ -182,7 +206,12 @@ export const CompositionManagerProvider: React.FC<{);const registerComposition = useCallback(- <Schema extends z.ZodTypeAny, Props>(comp: TComposition<Schema, Props>) => {+ <+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+ >(+ comp: TComposition<Schema, Props>+ ) => {updateCompositions((comps) => {if (comps.find((c) => c.id === comp.id)) {throw new Error(diff --git a/packages/core/src/EditorProps.tsx b/packages/core/src/EditorProps.tsxindex e75581eb18..ec34103423 100644--- a/packages/core/src/EditorProps.tsx+++ b/packages/core/src/EditorProps.tsx@@ -1,14 +1,16 @@import React, {createContext, useCallback, useMemo} from 'react';// Key: Composition ID, Value: initialized defaultProps-type Props = Record<string, object>;+type Props = Record<string, Record<string, unknown>>;export type EditorPropsContextType = {props: Props;updateProps: (options: {id: string;- defaultProps: object;- newProps: object;+ defaultProps: Record<string, unknown>;+ newProps:+ | Record<string, unknown>+ | ((oldProps: Record<string, unknown>) => Record<string, unknown>);}) => void;};diff --git a/packages/core/src/Still.tsx b/packages/core/src/Still.tsxindex 13fd152383..41993f56f3 100644--- a/packages/core/src/Still.tsx+++ b/packages/core/src/Still.tsx@@ -1,5 +1,5 @@import React from 'react';-import type {z} from 'zod';+import type {AnyZodObject} from 'zod';import type {CompositionProps, StillProps} from './Composition.js';import {Composition} from './Composition.js';@@ -8,7 +8,10 @@ import {Composition} from './Composition.js';* @see [Documentation](https://www.remotion.dev/docs/still)*/-export const Still = <Schema extends z.ZodTypeAny, Props>(+export const Still = <+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+>(props: StillProps<Schema, Props>) => {const newProps: CompositionProps<Schema, Props> = {diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 78f95124b8..4367eaf2f3 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -49,7 +49,7 @@ export type BundleState =| {type: 'composition';compositionName: string;- compositionDefaultProps: unknown;+ compositionDefaultProps: Record<string, unknown>;compositionHeight: number;compositionDurationInFrames: number;compositionWidth: number;diff --git a/packages/core/src/props-if-has-props.ts b/packages/core/src/props-if-has-props.tsindex af9a982fce..336693d97c 100644--- a/packages/core/src/props-if-has-props.ts+++ b/packages/core/src/props-if-has-props.ts@@ -1,9 +1,9 @@-import type {z} from 'zod';+import type {AnyZodObject, z} from 'zod';export type PropsIfHasProps<- Schema extends z.ZodTypeAny,- Props-> = z.ZodTypeAny extends Schema+ Schema extends AnyZodObject,+ Props extends Record<string, unknown> | undefined+> = AnyZodObject extends Schema? {} extends Props? {// Neither props nor schema specifieddiff --git a/packages/core/src/test/audio.test.tsx b/packages/core/src/test/audio.test.tsxindex 1f9a421e8f..240dd88b9d 100644--- a/packages/core/src/test/audio.test.tsx+++ b/packages/core/src/test/audio.test.tsx@@ -38,7 +38,7 @@ const Wrapper: React.FC<{defaultProps: undefined,folderName: null,parentFolderName: null,- schema: z.any(),+ schema: z.object({}),},],currentComposition: 'markup',diff --git a/packages/core/src/test/loop-validation.test.tsx b/packages/core/src/test/loop-validation.test.tsxindex 1e1a45bdc3..355c97220e 100644--- a/packages/core/src/test/loop-validation.test.tsx+++ b/packages/core/src/test/loop-validation.test.tsx@@ -41,7 +41,7 @@ const Wrapper: React.FC<{defaultProps: undefined,folderName: null,parentFolderName: null,- schema: z.any(),+ schema: z.object({}),},],currentComposition: 'markup',diff --git a/packages/core/src/test/video.test.tsx b/packages/core/src/test/video.test.tsxindex 621f0ea708..3a7a298c72 100644--- a/packages/core/src/test/video.test.tsx+++ b/packages/core/src/test/video.test.tsx@@ -39,7 +39,7 @@ const Wrapper: React.FC<{defaultProps: undefined,folderName: null,parentFolderName: null,- schema: z.any(),+ schema: z.object({}),},],currentComposition: 'markup',diff --git a/packages/docs/docs/4-0-migration.md b/packages/docs/docs/4-0-migration.mdindex abda444859..b0a12c5754 100644--- a/packages/docs/docs/4-0-migration.md+++ b/packages/docs/docs/4-0-migration.md@@ -223,7 +223,7 @@ This is automatically applied in [`@remotion/skia`](/docs/skia).The `TComposition` type now has two generic arguments:```ts-export type TComposition<Schema extends z.ZodTypeAny, Props> = {};+export type TComposition<Schema extends AnyZodObject, Props> = {};```If you need a type for a generic composition, you can use the new `AnyComposition` type:@@ -245,3 +245,11 @@ The [`getCanExtractFramesFast()`](/docs/renderer/get-can-extract-frames-fast) fu**How to upgrade:**You can now remove your re-encoding logic!++## Input props must be an object++Since the input props are passed to a React component, they must not explicitly be objects (`{}`). You can still use other data structures such as arrays, but they must be wrapped in an object.++## `defaultProps` is required if the component has props++If you register a composition with a component that requires some props, you now are required to provide a `defaultProps` object.diff --git a/packages/docs/docs/parametrized-rendering.md b/packages/docs/docs/parametrized-rendering.mdindex b842dd1ae4..c3dd62ee03 100644--- a/packages/docs/docs/parametrized-rendering.md+++ b/packages/docs/docs/parametrized-rendering.md@@ -187,9 +187,17 @@ export const RemotionRoot: React.FC = () => {If you define a schema, you will be able to visually manipulate the props in the Remotion Preview and render a parametrized video by filling out a form.+:::note+The schema must use an object `{}` as the top-level type because React props are passed as an object.+:::+## Input props-Input props are props that are passed in externally while rendering that can replace or override the default props+Input props are props that are passed in externally while rendering that can replace or override the default props.++:::note+Input props must be an object and serializable.+:::### Passing input props in the CLIdiff --git a/packages/example/src/SchemaTest/index.tsx b/packages/example/src/SchemaTest/index.tsxindex ad7be383a3..c45fde8574 100644--- a/packages/example/src/SchemaTest/index.tsx+++ b/packages/example/src/SchemaTest/index.tsx@@ -7,6 +7,20 @@ export const schemaTestSchema = z.object({delay: z.number().min(0).max(1000).step(0.1),});+export const schemaArrayTestSchema = z.array(z.number());++export const ArrayTest: React.FC = () => {+ return (+ <AbsoluteFill+ style={{+ justifyContent: 'center',+ alignItems: 'center',+ fontSize: 80,+ }}+ />+ );+};+export const SchemaTest: React.FC<z.infer<typeof schemaTestSchema>> = ({delay,title,diff --git a/packages/example/src/Video.tsx b/packages/example/src/Video.tsxindex a0baf5b997..ced98bf196 100644--- a/packages/example/src/Video.tsx+++ b/packages/example/src/Video.tsx@@ -24,7 +24,12 @@ import InfinityVideo from './ReallyLongVideo';import RemoteVideo from './RemoteVideo';import RiveVehicle from './Rive/RiveExample';import {ScalePath} from './ScalePath';-import {SchemaTest, schemaTestSchema} from './SchemaTest';+import {+ ArrayTest,+ schemaArrayTestSchema,+ SchemaTest,+ schemaTestSchema,+} from './SchemaTest';import {Scripts} from './Scripts';import CircleTest from './Shapes/CircleTest';import EllipseTest from './Shapes/EllipseTest';@@ -813,6 +818,17 @@ export const Index: React.FC = () => {durationInFrames={150}schema={schemaTestSchema}/>+ <Composition+ id="array-schem"+ component={ArrayTest}+ width={1200}+ height={630}+ fps={30}+ durationInFrames={150}+ // @ts-expect-error Needs an object+ schema={schemaArrayTestSchema}+ defaultProps={[1] as number[]}+ /></Folder><Folder name="TailwindCSS"><Compositiondiff --git a/packages/lambda/src/api/get-compositions-on-lambda.ts b/packages/lambda/src/api/get-compositions-on-lambda.tsindex 5965324261..943a356109 100644--- a/packages/lambda/src/api/get-compositions-on-lambda.ts+++ b/packages/lambda/src/api/get-compositions-on-lambda.ts@@ -9,7 +9,7 @@ import {serializeInputProps} from '../shared/serialize-input-props';export type GetCompositionsOnLambdaInput = {chromiumOptions?: ChromiumOptions;region: AwsRegion;- inputProps: unknown;+ inputProps: Record<string, unknown>;functionName: string;serveUrl: string;envVariables?: Record<string, string>;diff --git a/packages/lambda/src/api/make-lambda-payload.ts b/packages/lambda/src/api/make-lambda-payload.tsindex f673144767..7d5f881a7e 100644--- a/packages/lambda/src/api/make-lambda-payload.ts+++ b/packages/lambda/src/api/make-lambda-payload.ts@@ -59,7 +59,7 @@ export const makeLambdaPayload = async ({validateDownloadBehavior(downloadBehavior);const serializedInputProps = await serializeInputProps({- inputProps,+ inputProps: inputProps ?? {},region,type: 'video-or-audio',userSpecifiedBucketName: bucketName ?? null,diff --git a/packages/lambda/src/api/render-media-on-lambda.ts b/packages/lambda/src/api/render-media-on-lambda.tsindex 5505b78e0a..b385f5c594 100644--- a/packages/lambda/src/api/render-media-on-lambda.ts+++ b/packages/lambda/src/api/render-media-on-lambda.ts@@ -21,7 +21,7 @@ export type RenderMediaOnLambdaInput = {functionName: string;serveUrl: string;composition: string;- inputProps?: unknown;+ inputProps?: Record<string, unknown>;codec: LambdaCodec;imageFormat?: VideoImageFormat;crf?: number | undefined;diff --git a/packages/lambda/src/api/render-still-on-lambda.ts b/packages/lambda/src/api/render-still-on-lambda.tsindex c002e6aa72..eadd6f54bf 100644--- a/packages/lambda/src/api/render-still-on-lambda.ts+++ b/packages/lambda/src/api/render-still-on-lambda.ts@@ -17,7 +17,7 @@ export type RenderStillOnLambdaInput = {functionName: string;serveUrl: string;composition: string;- inputProps: unknown;+ inputProps: Record<string, unknown>;imageFormat: StillImageFormat;privacy: Privacy;maxRetries?: number;diff --git a/packages/lambda/src/functions/helpers/validate-composition.ts b/packages/lambda/src/functions/helpers/validate-composition.tsindex 7ff83bf351..aa1fb99569 100644--- a/packages/lambda/src/functions/helpers/validate-composition.ts+++ b/packages/lambda/src/functions/helpers/validate-composition.ts@@ -12,7 +12,7 @@ type ValidateCompositionOptions = {serveUrl: string;composition: string;browserInstance: Await<ReturnType<typeof openBrowser>>;- inputProps: unknown;+ inputProps: Record<string, unknown>;envVariables: Record<string, string> | undefined;timeoutInMilliseconds: number;chromiumOptions: ChromiumOptions;@@ -37,7 +37,7 @@ export const validateComposition = async ({}: ValidateCompositionOptions): Promise<AnyCompMetadata> => {const compositions = await getCompositions(serveUrl, {puppeteerInstance: browserInstance,- inputProps: inputProps as object,+ inputProps,envVariables,timeoutInMilliseconds,chromiumOptions,diff --git a/packages/lambda/src/shared/deserialize-input-props.ts b/packages/lambda/src/shared/deserialize-input-props.tsindex a69242d61f..06ce251ef4 100644--- a/packages/lambda/src/shared/deserialize-input-props.ts+++ b/packages/lambda/src/shared/deserialize-input-props.ts@@ -14,7 +14,7 @@ export const deserializeInputProps = async ({region: AwsRegion;bucketName: string;expectedBucketOwner: string;-}): Promise<object> => {+}): Promise<Record<string, unknown>> => {if (serialized.type === 'payload') {return JSON.parse(serialized.payload as string);}diff --git a/packages/lambda/src/shared/serialize-input-props.ts b/packages/lambda/src/shared/serialize-input-props.tsindex 95467cc0dc..9a40c503e4 100644--- a/packages/lambda/src/shared/serialize-input-props.ts+++ b/packages/lambda/src/shared/serialize-input-props.ts@@ -11,7 +11,7 @@ export const serializeInputProps = async ({type,userSpecifiedBucketName,}: {- inputProps: unknown;+ inputProps: Record<string, unknown>;region: AwsRegion;type: 'still' | 'video-or-audio';userSpecifiedBucketName: string | null;diff --git a/packages/player-example/src/App.tsx b/packages/player-example/src/App.tsxindex 7b9da9ccd7..3dbf1886d6 100644--- a/packages/player-example/src/App.tsx+++ b/packages/player-example/src/App.tsx@@ -459,7 +459,7 @@ const ControlsOnly: React.FC<{const PlayerOnly: React.FC<{playerRef: React.RefObject<PlayerRef>;- inputProps: object;+ inputProps: Record<string, unknown>;clickToPlay: boolean;loop: boolean;durationInFrames: number;diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsxindex 522b1c0a5b..d940414f43 100644--- a/packages/player/src/Player.tsx+++ b/packages/player/src/Player.tsx@@ -15,7 +15,7 @@ import type {TimelineContextValue,} from 'remotion';import {Composition, Internals} from 'remotion';-import type {z} from 'zod';+import type {AnyZodObject} from 'zod';import {PlayerEventEmitterContext} from './emitter-context.js';import {PlayerEmitter} from './event-emitter.js';import {PLAYER_CSS_CLASSNAME} from './player-css-classname.js';@@ -34,7 +34,7 @@ import {validatePlaybackRate} from './utils/validate-playbackrate.js';export type ErrorFallback = (info: {error: Error}) => React.ReactNode;-export type PlayerProps<Schema extends z.ZodTypeAny, Props> = {+export type PlayerProps<Schema extends AnyZodObject, Props> = {durationInFrames: number;compositionWidth: number;compositionHeight: number;@@ -80,7 +80,7 @@ export const componentOrNullIfLazy = <Props,>(return null;};-const PlayerFn = <Schema extends z.ZodTypeAny, Props>(+const PlayerFn = <Schema extends AnyZodObject, Props>({durationInFrames,compositionHeight,@@ -316,6 +316,8 @@ const PlayerFn = <Schema extends z.ZodTypeAny, Props>(}, []);}+ const actualInputProps = useMemo(() => inputProps ?? {}, [inputProps]);+return (<Internals.IsPlayerContextProvider><SharedPlayerContexts@@ -325,7 +327,7 @@ const PlayerFn = <Schema extends z.ZodTypeAny, Props>(compositionWidth={compositionWidth}durationInFrames={durationInFrames}fps={fps}- inputProps={inputProps}+ inputProps={actualInputProps}numberOfSharedAudioTags={numberOfSharedAudioTags}initiallyMuted={initiallyMuted}>diff --git a/packages/player/src/PlayerUI.tsx b/packages/player/src/PlayerUI.tsxindex 4ae4a170ab..6254735e65 100644--- a/packages/player/src/PlayerUI.tsx+++ b/packages/player/src/PlayerUI.tsx@@ -11,7 +11,6 @@ import React, {useState,} from 'react';import {Internals} from 'remotion';-import type {z} from 'zod';import {calculateCanvasTransformation,calculateContainerStyle,@@ -55,7 +54,7 @@ const PlayerUI: React.ForwardRefRenderFunction<loop: boolean;autoPlay: boolean;allowFullscreen: boolean;- inputProps: unknown;+ inputProps: Record<string, unknown>;showVolumeControls: boolean;style?: React.CSSProperties;clickToPlay: boolean;@@ -472,9 +471,8 @@ const PlayerUI: React.ForwardRefRenderFunction<{VideoComponent ? (<ErrorBoundary onError={onError} errorFallback={errorFallback}><VideoComponent- {...((video?.defaultProps as unknown as z.infer<z.ZodTypeAny>) ??- {})}- {...((inputProps as unknown as z.infer<z.ZodTypeAny>) ?? {})}+ {...(video?.defaultProps ?? {})}+ {...(inputProps ?? {})}/></ErrorBoundary>) : null}diff --git a/packages/player/src/SharedPlayerContext.tsx b/packages/player/src/SharedPlayerContext.tsxindex 025da72951..b07c13483e 100644--- a/packages/player/src/SharedPlayerContext.tsx+++ b/packages/player/src/SharedPlayerContext.tsx@@ -14,7 +14,7 @@ import {getPreferredVolume, persistVolume} from './volume-persistance.js';export const SharedPlayerContexts: React.FC<{children: React.ReactNode;timelineContext: TimelineContextValue;- inputProps?: unknown;+ inputProps?: Record<string, unknown>;fps: number;compositionWidth: number;compositionHeight: number;diff --git a/packages/player/src/Thumbnail.tsx b/packages/player/src/Thumbnail.tsxindex ac1e9f2a00..529334501e 100644--- a/packages/player/src/Thumbnail.tsx+++ b/packages/player/src/Thumbnail.tsx@@ -13,7 +13,7 @@ import {} from 'react';import type {CompProps, TimelineContextValue} from 'remotion';import {Internals, random} from 'remotion';-import type {z} from 'zod';+import type {AnyZodObject} from 'zod';import {ThumbnailEmitterContext} from './emitter-context.js';import {ThumbnailEmitter} from './event-emitter.js';import type {ThumbnailMethods} from './player-methods.js';@@ -22,7 +22,7 @@ import {SharedPlayerContexts} from './SharedPlayerContext.js';import ThumbnailUI from './ThumbnailUI.js';import type {PropsIfHasProps} from './utils/props-if-has-props.js';-type ThumbnailProps<Schema extends z.ZodTypeAny, Props> = PropsIfHasProps<+type ThumbnailProps<Schema extends AnyZodObject, Props> = PropsIfHasProps<Schema,Props> &@@ -38,7 +38,7 @@ type ThumbnailProps<Schema extends z.ZodTypeAny, Props> = PropsIfHasProps<className?: string;};-export const ThumbnailFn = <Schema extends z.ZodTypeAny, Props>(+export const ThumbnailFn = <Schema extends AnyZodObject, Props>({frameToDisplay,style,@@ -94,7 +94,7 @@ export const ThumbnailFn = <Schema extends z.ZodTypeAny, Props>(compositionWidth={compositionWidth}durationInFrames={durationInFrames}fps={fps}- inputProps={inputProps}+ inputProps={passedInputProps}numberOfSharedAudioTags={0}initiallyMuted>diff --git a/packages/player/src/ThumbnailUI.tsx b/packages/player/src/ThumbnailUI.tsxindex d828fa781f..68f430313a 100644--- a/packages/player/src/ThumbnailUI.tsx+++ b/packages/player/src/ThumbnailUI.tsx@@ -7,7 +7,6 @@ import React, {useRef,} from 'react';import {Internals} from 'remotion';-import type {z} from 'zod';import {calculateCanvasTransformation,calculateContainerStyle,@@ -34,7 +33,7 @@ const doesReactVersionSupportSuspense = parseInt(reactVersion, 10) >= 18;const ThumbnailUI: React.ForwardRefRenderFunction<ThumbnailMethods,{- inputProps: unknown;+ inputProps: Record<string, unknown>;style?: React.CSSProperties;errorFallback: ErrorFallback;renderLoading: RenderLoading | undefined;@@ -126,9 +125,8 @@ const ThumbnailUI: React.ForwardRefRenderFunction<{VideoComponent ? (<ErrorBoundary onError={onError} errorFallback={errorFallback}><VideoComponent- {...((video?.defaultProps as unknown as z.infer<z.ZodTypeAny>) ??- {})}- {...((inputProps as unknown as z.infer<z.ZodTypeAny>) ?? {})}+ {...(video?.defaultProps ?? {})}+ {...(inputProps ?? {})}/></ErrorBoundary>) : null}diff --git a/packages/player/src/utils/props-if-has-props.ts b/packages/player/src/utils/props-if-has-props.tsindex 18dbb1be0a..4ef55b0a1b 100644--- a/packages/player/src/utils/props-if-has-props.ts+++ b/packages/player/src/utils/props-if-has-props.ts@@ -1,9 +1,9 @@-import type {z} from 'zod';+import type {AnyZodObject, z} from 'zod';export type PropsIfHasProps<- Schema extends z.ZodTypeAny,+ Schema extends AnyZodObject,Props-> = z.ZodTypeAny extends Schema+> = AnyZodObject extends Schema? {} extends Props? {// Neither props nor schema specifieddiff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.tsindex 9dc6a300d8..a453c49c0e 100644--- a/packages/renderer/src/get-compositions.ts+++ b/packages/renderer/src/get-compositions.ts@@ -16,7 +16,7 @@ import {setPropsAndEnv} from './set-props-and-env';import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';type GetCompositionsConfig = {- inputProps?: object | null;+ inputProps?: Record<string, unknown> | null;envVariables?: Record<string, string>;puppeteerInstance?: Browser;onBrowserLog?: (log: BrowserLog) => void;@@ -54,7 +54,7 @@ const innerGetCompositions = async (validatePuppeteerTimeout(config?.timeoutInMilliseconds);await setPropsAndEnv({- inputProps: config?.inputProps,+ inputProps: config?.inputProps ?? {},envVariables: config?.envVariables,page,serveUrl,diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.tsindex db3528571e..b52f6bb4b7 100644--- a/packages/renderer/src/render-frames.ts+++ b/packages/renderer/src/render-frames.ts@@ -57,7 +57,7 @@ type RenderFramesOptions = {timeToRenderInMilliseconds: number) => void;outputDir: string | null;- inputProps: unknown;+ inputProps: Record<string, unknown>;envVariables?: Record<string, string>;imageFormat?: VideoImageFormat;/**@@ -196,7 +196,7 @@ const innerRenderFrames = ({// eslint-disable-next-line max-paramspageFunction: (id: string,- defaultProps: unknown,+ defaultProps: Record<string, unknown>,durationInFrames: number,fps: number,height: number,diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex f176947667..7ac9be1ca0 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -70,7 +70,7 @@ export type RenderMediaOptions = {outputLocation?: string | null;codec: Codec;composition: AnySmallCompMetadata;- inputProps?: unknown;+ inputProps?: Record<string, unknown>;crf?: number | null;imageFormat?: VideoImageFormat;pixelFormat?: PixelFormat;@@ -434,7 +434,7 @@ export const renderMedia = ({callUpdate();onStart?.(data);},- inputProps,+ inputProps: inputProps ?? {},envVariables,imageFormat,jpegQuality,diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.tsindex 09de8a3c97..d059c9cb4a 100644--- a/packages/renderer/src/render-still.ts+++ b/packages/renderer/src/render-still.ts@@ -36,7 +36,7 @@ type InnerStillOptions = {composition: AnySmallCompMetadata;output?: string | null;frame?: number;- inputProps?: unknown;+ inputProps?: Record<string, unknown>;imageFormat?: StillImageFormat;/*** @deprecated Renamed to `jpegQuality`@@ -227,7 +227,7 @@ const innerRenderStill = async ({}await setPropsAndEnv({- inputProps,+ inputProps: inputProps ?? {},envVariables,page,serveUrl,@@ -243,7 +243,7 @@ const innerRenderStill = async ({// eslint-disable-next-line max-paramspageFunction: (id: string,- defaultProps: unknown,+ defaultProps: Record<string, unknown>,durationInFrames: number,fps: number,height: number,diff --git a/packages/renderer/src/set-props-and-env.ts b/packages/renderer/src/set-props-and-env.tsindex f957a7457d..f16d5d703c 100644--- a/packages/renderer/src/set-props-and-env.ts+++ b/packages/renderer/src/set-props-and-env.ts@@ -7,7 +7,7 @@ import {redirectStatusCodes} from './redirect-status-codes';import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';type SetPropsAndEnv = {- inputProps: unknown;+ inputProps: Record<string, unknown>;envVariables: Record<string, string> | undefined;page: Page;serveUrl: string;