🎥 Make videos programmatically with React
Serialize things correctly when using getCompositions()
Jonny Burger04186bf68e06
diff --git a/packages/bundler/src/renderEntry.tsx b/packages/bundler/src/renderEntry.tsxindex 52af0e1bd6..f6d9809ea6 100644--- a/packages/bundler/src/renderEntry.tsx+++ b/packages/bundler/src/renderEntry.tsx@@ -5,7 +5,7 @@ import type {render, unmountComponentAtNode} from 'react-dom';// We support both, but Webpack chooses both of them and normalizes them to "react-dom/client",// hence why we import the right thing all the time but need to differentiate hereimport ReactDOM from 'react-dom/client';-import type {AnyComposition, BundleState, VideoConfig} from 'remotion';+import type {AnyComposition, BundleState} from 'remotion';import {continueRender,delayRender,@@ -272,7 +272,7 @@ if (typeof window !== 'undefined') {return compositions;};- window.getStaticCompositions = (): Promise<VideoConfig[]> => {+ window.getStaticCompositions = () => {const compositions = getUnevaluatedComps();const inputProps =@@ -283,7 +283,7 @@ if (typeof window !== 'undefined') {: getInputProps() ?? {};return Promise.all(- compositions.map(async (c): Promise<VideoConfig> => {+ compositions.map(async (c) => {const handle = delayRender(`Running calculateMetadata() for composition ${c.id}. If you didn't want to evaluate this composition, use "selectComposition()" instead of "getCompositions()"`);@@ -297,7 +297,23 @@ if (typeof window !== 'undefined') {const resolved = await Promise.resolve(comp);continueRender(handle);- return resolved;+ const {props, defaultProps, ...data} = resolved;++ return {+ ...data,+ serializedResolvedPropsWithCustomSchema:+ Internals.serializeJSONWithDate({+ data: props,+ indent: undefined,+ staticBase: null,+ }).serializedString,+ serializedDefaultPropsWithCustomSchema:+ Internals.serializeJSONWithDate({+ data: defaultProps,+ indent: undefined,+ staticBase: null,+ }).serializedString,+ };}));};@@ -351,7 +367,7 @@ if (typeof window !== 'undefined') {};};- window.siteVersion = '9';+ window.siteVersion = '10';window.remotion_version = VERSION;window.remotion_setBundleMode = setBundleModeAndUpdate;}diff --git a/packages/core/src/index.ts b/packages/core/src/index.tsindex 04f9df51c1..1d29938e34 100644--- a/packages/core/src/index.ts+++ b/packages/core/src/index.ts@@ -16,7 +16,12 @@ declare global {};remotion_cancelledError: string | undefined;remotion_getCompositionNames: () => string[];- getStaticCompositions: () => Promise<VideoConfig[]>;+ getStaticCompositions: () => Promise<+ (Omit<VideoConfig, 'defaultProps' | 'props'> & {+ serializedDefaultPropsWithCustomSchema: string;+ serializedResolvedPropsWithCustomSchema: string;+ })[]+ >;remotion_calculateComposition: (compId: string) => Promise<Omit<VideoConfig, 'defaultProps' | 'props'> & {serializedDefaultPropsWithCustomSchema: string;@@ -45,7 +50,7 @@ declare global {remotion_isPlayer: boolean;remotion_isBuilding: undefined | (() => void);remotion_finishedBuilding: undefined | (() => void);- siteVersion: '9';+ siteVersion: '10';remotion_version: string;remotion_imported: string | boolean;}diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.tsindex ddcd7d8d2f..b164a6c006 100644--- a/packages/renderer/src/get-compositions.ts+++ b/packages/renderer/src/get-compositions.ts@@ -115,7 +115,27 @@ const innerGetCompositions = async ({args: [],});- return result as VideoConfig[];+ const res = result as Awaited<+ ReturnType<typeof window.getStaticCompositions>+ >;++ return res.map((r) => {+ const {width, durationInFrames, fps, height, id} = r;++ return {+ id,+ width,+ height,+ fps,+ durationInFrames,+ props: Internals.deserializeJSONWithCustomFields(+ r.serializedResolvedPropsWithCustomSchema+ ),+ defaultProps: Internals.deserializeJSONWithCustomFields(+ r.serializedDefaultPropsWithCustomSchema+ ),+ };+ });};type CleanupFn = () => void;diff --git a/packages/renderer/src/set-props-and-env.ts b/packages/renderer/src/set-props-and-env.tsindex 6cae35b6e9..cd86d12cd7 100644--- a/packages/renderer/src/set-props-and-env.ts+++ b/packages/renderer/src/set-props-and-env.ts@@ -167,7 +167,7 @@ const innerSetPropsAndEnv = async ({page,});- const requiredVersion: typeof window.siteVersion = '9';+ const requiredVersion: typeof window.siteVersion = '10';if (siteVersion !== requiredVersion) {throw new Error(