🎥 Make videos programmatically with React
docs and serialize also in studio
Jonny Burgeraba96a87f834
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsxindex fd9e9bb79f..1c46733564 100644--- a/packages/core/src/Composition.tsx+++ b/packages/core/src/Composition.tsx@@ -14,6 +14,7 @@ import {useResolvedVideoConfig} from './ResolveCompositionConfig.js';import type {Codec} from './codec.js';import {continueRender, delayRender} from './delay-render.js';import {getRemotionEnvironment} from './get-remotion-environment.js';+import {serializeThenDeserializeInStudio} from './input-props-serialization.js';import {useIsPlayer} from './is-player.js';import {Loading} from './loading-indicator.js';import {useNonce} from './nonce.js';@@ -194,7 +195,9 @@ export const Composition = <id,folderName,component: lazy,- defaultProps: defaultProps as z.output<Schema> & Props,+ defaultProps: serializeThenDeserializeInStudio(+ (defaultProps ?? {}) as z.output<Schema> & Props,+ ) as z.output<Schema> & Props,nonce,parentFolderName: parentName,schema: schema ?? null,diff --git a/packages/core/src/input-props-serialization.ts b/packages/core/src/input-props-serialization.tsindex 0fe363c165..428a94ded5 100644--- a/packages/core/src/input-props-serialization.ts+++ b/packages/core/src/input-props-serialization.ts@@ -1,5 +1,6 @@// Must keep this file in sync with the one in packages/lambda/src/shared/serialize-props.ts!+import {getRemotionEnvironment} from './get-remotion-environment.js';import {staticFile} from './static-file.js';export type SerializedJSONWithCustomFields = {@@ -84,3 +85,21 @@ export const deserializeJSONWithCustomFields = <T = Record<string, unknown>>(return value;});};++export const serializeThenDeserializeInStudio = (+ props: Record<string, unknown>,+) => {+ // Serializing once in the Studio, to catch potential serialization errors before+ // you only get them during rendering+ if (getRemotionEnvironment().isStudio) {+ return deserializeJSONWithCustomFields(+ serializeJSONWithDate({+ data: props,+ indent: 2,+ staticBase: window.remotion_staticBase,+ }).serializedString,+ );+ }++ return props;+};diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.tsindex 2d2ba73d67..e31b26d1f0 100644--- a/packages/core/src/resolve-video-config.ts+++ b/packages/core/src/resolve-video-config.ts@@ -3,11 +3,7 @@ import type {CalcMetadataReturnType,CalculateMetadataFunction,} from './Composition.js';-import {getRemotionEnvironment} from './get-remotion-environment.js';-import {- deserializeJSONWithCustomFields,- serializeJSONWithDate,-} from './input-props-serialization.js';+import {serializeThenDeserializeInStudio} from './input-props-serialization.js';import type {InferProps} from './props-if-has-props.js';import {validateDefaultCodec} from './validation/validate-default-codec.js';import {validateDimension} from './validation/validate-dimensions.js';@@ -71,22 +67,6 @@ const validateCalculated = ({return {width, height, fps, durationInFrames, defaultCodec};};-const serializeThenDeserializeInStudio = (props: Record<string, unknown>) => {- // Serializing once in the Studio, to catch potential serialization errors before- // you only get them during rendering- if (getRemotionEnvironment().isStudio) {- return deserializeJSONWithCustomFields(- serializeJSONWithDate({- data: props,- indent: 2,- staticBase: window.remotion_staticBase,- }).serializedString,- );- }-- return props;-};-type ResolveVideoConfigParams = {compositionId: string;compositionWidth: number | null;diff --git a/packages/docs/docs/composition.mdx b/packages/docs/docs/composition.mdxindex 5517b844ff..1e1314f5d4 100644--- a/packages/docs/docs/composition.mdx+++ b/packages/docs/docs/composition.mdx@@ -71,7 +71,13 @@ If you use `lazyComponent`, Remotion will use React Suspense to load the compone_optional_-Give your component default props. Default props can be overriden using the [Props editor](/docs/visual-editing) and with [Input Props](/docs/props-resolution)+Give your component default props. Default props can be overriden using the [Props editor](/docs/visual-editing) and with [Input Props](/docs/props-resolution).++Props must be an object that contains only pure JSON-serializable values.+Functions, classes, and other non-serializable values will be lost while rendering.+(This restriction does not apply to the [`<Player>`](/docs/player/api), where you are allowed to pass functions as props.)++You may in addition use `Date`, `Map`, `Set` and [`staticFile()`](/docs/staticfile) in your default props and Remotion will guarantee the proper serialization.:::noteType your components using the `React.FC<{}>` type and the `defaultProps` prop will be typesafe.diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsxindex f936413376..864234805b 100644--- a/packages/example/src/Root.tsx+++ b/packages/example/src/Root.tsx@@ -483,14 +483,7 @@ export const Index: React.FC = () => {durationInFrames={30}fps={30}defaultProps={{- calculated: new Vector2(10, 10),- }}- calculateMetadata={() => {- return {- props: {- calculated: new Vector2(10, 10),- },- };+ calculated: new Vector2(15, 10),}}/></Folder>