π₯ Make videos programmatically with React
awesome
Jonny Burger29dc8c0e7460
diff --git a/packages/cli/src/benchmark.ts b/packages/cli/src/benchmark.tsindex d291a84ca0..b023c50dc3 100644--- a/packages/cli/src/benchmark.ts+++ b/packages/cli/src/benchmark.ts@@ -295,7 +295,7 @@ export const benchmarkCommand = async (const puppeteerInstance = await browserInstance;const serializedInputPropsWithCustomSchema =- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps ?? {},indent: undefined,staticBase: null,@@ -480,7 +480,7 @@ export const benchmarkCommand = async (preferLossless: false,server: undefined,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: composition.props,indent: undefined,staticBase: null,diff --git a/packages/cli/src/compositions.ts b/packages/cli/src/compositions.tsindex 71b1a07150..d555532652 100644--- a/packages/cli/src/compositions.ts+++ b/packages/cli/src/compositions.ts@@ -137,7 +137,7 @@ export const listCompositionsCommand = async (chromiumOptions,envVariables,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps,staticBase: null,indent: undefined,diff --git a/packages/cli/src/render-flows/render.ts b/packages/cli/src/render-flows/render.tsindex bc50fa9b26..06d3628ad8 100644--- a/packages/cli/src/render-flows/render.ts+++ b/packages/cli/src/render-flows/render.ts@@ -518,7 +518,7 @@ export const renderVideoFlow = async ({onFrameBuffer: null,logLevel,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: config.props,@@ -608,7 +608,7 @@ export const renderVideoFlow = async ({onBrowserLog: null,onStart: () => undefined,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: config.props,indent: undefined,staticBase: null,diff --git a/packages/cli/src/render-flows/still.ts b/packages/cli/src/render-flows/still.tsindex 5a8fabc9f5..c48b561eb8 100644--- a/packages/cli/src/render-flows/still.ts+++ b/packages/cli/src/render-flows/still.ts@@ -368,7 +368,7 @@ export const renderStillFlow = async ({onBrowserLog: null,logLevel,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: config.props,diff --git a/packages/cli/src/render.tsx b/packages/cli/src/render.tsxindex 9660452636..129404f22f 100644--- a/packages/cli/src/render.tsx+++ b/packages/cli/src/render.tsx@@ -199,7 +199,7 @@ export const render = async (publicDir,envVariables,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps,diff --git a/packages/cli/src/still.ts b/packages/cli/src/still.tsindex 6de8c7ce4f..dc0e723dd8 100644--- a/packages/cli/src/still.ts+++ b/packages/cli/src/still.ts@@ -139,7 +139,7 @@ export const still = async (envVariables,height,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps,indent: undefined,staticBase: null,diff --git a/packages/cloudrun/src/api/render-media-on-cloudrun.ts b/packages/cloudrun/src/api/render-media-on-cloudrun.tsindex c56e5fefe7..fd19bf46f2 100644--- a/packages/cloudrun/src/api/render-media-on-cloudrun.ts+++ b/packages/cloudrun/src/api/render-media-on-cloudrun.ts@@ -165,7 +165,7 @@ const internalRenderMediaOnCloudrunRaw = async ({serveUrl,codec: actualCodec,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps ?? {},diff --git a/packages/cloudrun/src/api/render-still-on-cloudrun.ts b/packages/cloudrun/src/api/render-still-on-cloudrun.tsindex d0feca84e1..1603d39fe9 100644--- a/packages/cloudrun/src/api/render-still-on-cloudrun.ts+++ b/packages/cloudrun/src/api/render-still-on-cloudrun.ts@@ -121,7 +121,7 @@ const internalRenderStillOnCloudRun = async ({composition,serveUrl,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps ?? {},diff --git a/packages/cloudrun/src/cli/commands/render/index.ts b/packages/cloudrun/src/cli/commands/render/index.tsindex 18c7c4295b..a19140420f 100644--- a/packages/cloudrun/src/cli/commands/render/index.ts+++ b/packages/cloudrun/src/cli/commands/render/index.ts@@ -166,7 +166,7 @@ export const renderCommand = async (width,server: await server,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps,indent: undefined,staticBase: null,diff --git a/packages/cloudrun/src/cli/commands/still.ts b/packages/cloudrun/src/cli/commands/still.tsindex 5509db56da..5272f37d3b 100644--- a/packages/cloudrun/src/cli/commands/still.ts+++ b/packages/cloudrun/src/cli/commands/still.ts@@ -123,7 +123,7 @@ export const stillCommand = async (chromiumOptions,envVariables,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps,indent: undefined,staticBase: null,diff --git a/packages/cloudrun/src/functions/render-media-single-thread.ts b/packages/cloudrun/src/functions/render-media-single-thread.tsindex 9450349282..132bed3a48 100644--- a/packages/cloudrun/src/functions/render-media-single-thread.ts+++ b/packages/cloudrun/src/functions/render-media-single-thread.ts@@ -140,7 +140,7 @@ export const renderMediaSingleThread = async (serializedInputPropsWithCustomSchema:body.serializedInputPropsWithCustomSchema,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: composition.props,indent: undefined,staticBase: null,diff --git a/packages/cloudrun/src/functions/render-still-single-thread.ts b/packages/cloudrun/src/functions/render-still-single-thread.tsindex 1947149f31..a24ec2513d 100644--- a/packages/cloudrun/src/functions/render-still-single-thread.ts+++ b/packages/cloudrun/src/functions/render-still-single-thread.ts@@ -71,7 +71,7 @@ export const renderStillSingleThread = async (serializedInputPropsWithCustomSchema:body.serializedInputPropsWithCustomSchema,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: composition.props,indent: undefined,staticBase: null,diff --git a/packages/core/src/config/input-props.ts b/packages/core/src/config/input-props.tsindex e869c6fd0d..9e5dbb749b 100644--- a/packages/core/src/config/input-props.ts+++ b/packages/core/src/config/input-props.ts@@ -1,5 +1,5 @@import {getRemotionEnvironment} from '../get-remotion-environment.js';-import {deserializeJSONWithCustomFields} from '../input-props-serialization.js';+import {deserializeJSONWithSpecialTypes} from '../input-props-serialization.js';let didWarnSSRImport = false;@@ -38,6 +38,6 @@ export const getInputProps = <return {} as T;}- const parsed = deserializeJSONWithCustomFields<T>(param);+ const parsed = deserializeJSONWithSpecialTypes<T>(param);return parsed;};diff --git a/packages/core/src/input-props-serialization.ts b/packages/core/src/input-props-serialization.tsindex 75e337aea7..3d0f15c226 100644--- a/packages/core/src/input-props-serialization.ts+++ b/packages/core/src/input-props-serialization.ts@@ -13,7 +13,7 @@ export type SerializedJSONWithCustomFields = {export const DATE_TOKEN = 'remotion-date:';export const FILE_TOKEN = 'remotion-file:';-export const serializeJSONWithDate = ({+export const serializeJSONWithSpecialTypes = ({data,indent,staticBase,@@ -69,7 +69,7 @@ export const serializeJSONWithDate = ({}};-export const deserializeJSONWithCustomFields = <T = Record<string, unknown>>(+export const deserializeJSONWithSpecialTypes = <T = Record<string, unknown>>(data: string,): T => {return JSON.parse(data, (_, value) => {@@ -86,8 +86,8 @@ export const deserializeJSONWithCustomFields = <T = Record<string, unknown>>(};export const serializeThenDeserialize = (props: Record<string, unknown>) => {- return deserializeJSONWithCustomFields(- serializeJSONWithDate({+ return deserializeJSONWithSpecialTypes(+ serializeJSONWithSpecialTypes({data: props,indent: 2,staticBase: window.remotion_staticBase,diff --git a/packages/core/src/no-react.ts b/packages/core/src/no-react.tsindex 00ca6017e4..af1dcdb78c 100644--- a/packages/core/src/no-react.ts+++ b/packages/core/src/no-react.ts@@ -18,8 +18,8 @@ import {DELAY_RENDER_RETRY_TOKEN,} from './delay-render';import {- deserializeJSONWithCustomFields,- serializeJSONWithDate,+ deserializeJSONWithSpecialTypes,+ serializeJSONWithSpecialTypes,} from './input-props-serialization';import {DATE_TOKEN, FILE_TOKEN} from './input-props-serialization.js';import {colorNames, processColor} from './interpolate-colors';@@ -41,10 +41,10 @@ export const NoReactInternals = {validateDurationInFrames,validateDefaultAndInputProps,validateFrame,- serializeJSONWithDate,+ serializeJSONWithSpecialTypes,bundleName: 'bundle.js',bundleMapName: 'bundle.js.map',- deserializeJSONWithCustomFields,+ deserializeJSONWithSpecialTypes,DELAY_RENDER_CALLSTACK_TOKEN,DELAY_RENDER_RETRY_TOKEN,DELAY_RENDER_CLEAR_TOKEN,diff --git a/packages/core/src/test/json-serialization.test.ts b/packages/core/src/test/json-serialization.test.tsindex 2fed6ccabb..9985affa10 100644--- a/packages/core/src/test/json-serialization.test.ts+++ b/packages/core/src/test/json-serialization.test.ts@@ -1,14 +1,14 @@import {expect, test} from 'bun:test';import {- deserializeJSONWithCustomFields,- serializeJSONWithDate,+ deserializeJSONWithSpecialTypes,+ serializeJSONWithSpecialTypes,} from '../input-props-serialization.js';test('date serialization', () => {const date = {data: new Date(), hi: 'there'};const {serializedString, customDateUsed, customFileUsed} =- serializeJSONWithDate({+ serializeJSONWithSpecialTypes({data: date,indent: 2,staticBase: '/static',@@ -16,24 +16,25 @@ test('date serialization', () => {expect(customDateUsed).toEqual(true);expect(customFileUsed).toEqual(false);- const deserialized = deserializeJSONWithCustomFields(serializedString);+ const deserialized = deserializeJSONWithSpecialTypes(serializedString);expect(deserialized.data).toBeInstanceOf(Date);});test('No date used', () => {- const {customDateUsed, customFileUsed, mapUsed} = serializeJSONWithDate({- data: {a: 'hi'},- indent: 2,- staticBase: '/static',- });+ const {customDateUsed, customFileUsed, mapUsed} =+ serializeJSONWithSpecialTypes({+ data: {a: 'hi'},+ indent: 2,+ staticBase: '/static',+ });expect(customDateUsed).toEqual(false);expect(customFileUsed).toEqual(false);expect(mapUsed).toEqual(false);});test('Map used', () => {- const {mapUsed} = serializeJSONWithDate({+ const {mapUsed} = serializeJSONWithSpecialTypes({data: {a: 'hi', map: new Map()},indent: 2,staticBase: '/static',diff --git a/packages/example/src/VisualControls/index.tsx b/packages/example/src/VisualControls/index.tsxindex e71e1b65f0..60ef86af4b 100644--- a/packages/example/src/VisualControls/index.tsx+++ b/packages/example/src/VisualControls/index.tsx@@ -1,12 +1,12 @@import {makeTransform, matrix3d} from '@remotion/animation-utils';import {visualControl} from '@remotion/studio';import {zMatrix, zTextarea} from '@remotion/zod-types';-import {AbsoluteFill} from 'remotion';+import {AbsoluteFill, staticFile} from 'remotion';export const VisualControls = () => {const matrix = visualControl('my-matrix',- [1.73,-2.64,0,0,0,1,0,0,1.26,0,1,0,0,0,0,1],+ [4.13,-1.6,0,0,0,1,0,0,1.26,0.35,1,0,0,0,0,1],zMatrix(),);@@ -19,6 +19,8 @@ export const VisualControls = () => {const val4 = visualControl(`value π`, 'hi there');const val5 = visualControl(`text π`, 'hi there', zTextarea());+ const val6 = visualControl('file', staticFile("clip001.mkv"));+return (<AbsoluteFillclassName="bg-red-300 text-7xl flex flex-1 items-center justify-center"diff --git a/packages/it-tests/src/codemods/visual-controls.test.ts b/packages/it-tests/src/codemods/visual-controls.test.tsindex 95b01ab083..b0cb98aad5 100644--- a/packages/it-tests/src/codemods/visual-controls.test.ts+++ b/packages/it-tests/src/codemods/visual-controls.test.ts@@ -23,10 +23,12 @@ test('Should be able to create visual control', () => {{id: 'my-matrix',newValueSerialized: '123',+ enumPaths: [],},{id: 'my-matrix-2',newValueSerialized: '"456" as const',+ enumPaths: [],},],},diff --git a/packages/lambda/src/cli/commands/render/render.ts b/packages/lambda/src/cli/commands/render/render.tsindex 8463e25aa0..3e3b8986b7 100644--- a/packages/lambda/src/cli/commands/render/render.ts+++ b/packages/lambda/src/cli/commands/render/render.ts@@ -228,7 +228,7 @@ export const renderCommand = async ({height,indent,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps,diff --git a/packages/lambda/src/cli/commands/still.ts b/packages/lambda/src/cli/commands/still.tsindex b952a3d061..ac252f243a 100644--- a/packages/lambda/src/cli/commands/still.ts+++ b/packages/lambda/src/cli/commands/still.ts@@ -166,7 +166,7 @@ export const stillCommand = async ({chromiumOptions,envVariables,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps,diff --git a/packages/renderer/src/get-compositions.ts b/packages/renderer/src/get-compositions.tsindex 820347db5e..08e95827e3 100644--- a/packages/renderer/src/get-compositions.ts+++ b/packages/renderer/src/get-compositions.ts@@ -131,10 +131,10 @@ const innerGetCompositions = async ({height,fps,durationInFrames,- props: NoReactInternals.deserializeJSONWithCustomFields(+ props: NoReactInternals.deserializeJSONWithSpecialTypes(r.serializedResolvedPropsWithCustomSchema,),- defaultProps: NoReactInternals.deserializeJSONWithCustomFields(+ defaultProps: NoReactInternals.deserializeJSONWithSpecialTypes(r.serializedDefaultPropsWithCustomSchema,),defaultCodec,@@ -290,7 +290,7 @@ export const getCompositions = (chromiumOptions: chromiumOptions ?? {},envVariables: envVariables ?? {},serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps ?? {},indent: undefined,staticBase: null,diff --git a/packages/renderer/src/render-frames.ts b/packages/renderer/src/render-frames.tsindex 7dab05b42a..90fb6f0d40 100644--- a/packages/renderer/src/render-frames.ts+++ b/packages/renderer/src/render-frames.ts@@ -728,13 +728,13 @@ export const renderFrames = (jpegQuality: jpegQuality ?? DEFAULT_JPEG_QUALITY,onDownload: onDownload ?? null,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps ?? {},}).serializedString,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: composition.props,diff --git a/packages/renderer/src/render-media.ts b/packages/renderer/src/render-media.tsindex 2742ed6e24..c957c9d17a 100644--- a/packages/renderer/src/render-media.ts+++ b/packages/renderer/src/render-media.ts@@ -940,7 +940,7 @@ export const renderMedia = ({frameRange: frameRange ?? null,imageFormat: imageFormat ?? DEFAULT_VIDEO_IMAGE_FORMAT,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps ?? {},@@ -968,7 +968,7 @@ export const renderMedia = ({onCtrlCExit: () => undefined,server: undefined,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: composition.props ?? {},diff --git a/packages/renderer/src/render-still.ts b/packages/renderer/src/render-still.tsindex 42661f97c0..df94b0723f 100644--- a/packages/renderer/src/render-still.ts+++ b/packages/renderer/src/render-still.ts@@ -479,7 +479,7 @@ export const renderStill = (imageFormat: imageFormat ?? DEFAULT_STILL_IMAGE_FORMAT,indent,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({staticBase: null,indent: undefined,data: inputProps ?? {},@@ -497,7 +497,7 @@ export const renderStill = (timeoutInMilliseconds: timeoutInMilliseconds ?? DEFAULT_TIMEOUT,logLevel,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: composition.props ?? {},diff --git a/packages/renderer/src/select-composition.ts b/packages/renderer/src/select-composition.tsindex 8efc46dcd5..f2fb8bad74 100644--- a/packages/renderer/src/select-composition.ts+++ b/packages/renderer/src/select-composition.ts@@ -152,10 +152,10 @@ const innerSelectComposition = async ({height,fps,durationInFrames,- props: NoReactInternals.deserializeJSONWithCustomFields(+ props: NoReactInternals.deserializeJSONWithSpecialTypes(res.serializedResolvedPropsWithCustomSchema,),- defaultProps: NoReactInternals.deserializeJSONWithCustomFields(+ defaultProps: NoReactInternals.deserializeJSONWithSpecialTypes(res.serializedDefaultPropsWithCustomSchema,),defaultCodec,@@ -322,7 +322,7 @@ export const selectComposition = async (chromiumOptions: chromiumOptions ?? {},envVariables: envVariables ?? {},serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps ?? {},diff --git a/packages/serverless-client/src/compress-props.ts b/packages/serverless-client/src/compress-props.tsindex fe665d6190..6309b88531 100644--- a/packages/serverless-client/src/compress-props.ts+++ b/packages/serverless-client/src/compress-props.ts@@ -22,7 +22,7 @@ export const serializeOrThrow = (propsType: PropsType,) => {try {- const payload = NoReactInternals.serializeJSONWithDate({+ const payload = NoReactInternals.serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: inputProps,diff --git a/packages/serverless-client/src/index.ts b/packages/serverless-client/src/index.tsindex c209739435..05571e7a2f 100644--- a/packages/serverless-client/src/index.ts+++ b/packages/serverless-client/src/index.ts@@ -118,7 +118,7 @@ export {interpolate, random};export const {ENABLE_V5_BREAKING_CHANGES,- serializeJSONWithDate,+ serializeJSONWithSpecialTypes,validateFps,validateDimension,validateDurationInFrames,diff --git a/packages/serverless/src/handlers/still.ts b/packages/serverless/src/handlers/still.tsindex 3a22307753..0bf61436f4 100644--- a/packages/serverless/src/handlers/still.ts+++ b/packages/serverless/src/handlers/still.ts@@ -18,7 +18,7 @@ import {getExpectedOutName,internalGetOrCreateBucket,overallProgressKey,- serializeJSONWithDate,+ serializeJSONWithSpecialTypes,ServerlessRoutines,validateDownloadBehavior,validateOutname,@@ -312,7 +312,7 @@ const innerStillHandler = async <Provider extends CloudProvider>(port: null,server,logLevel: params.logLevel,- serializedResolvedPropsWithCustomSchema: serializeJSONWithDate({+ serializedResolvedPropsWithCustomSchema: serializeJSONWithSpecialTypes({indent: undefined,staticBase: null,data: composition.props,diff --git a/packages/studio-server/src/codemods/apply-visual-control.ts b/packages/studio-server/src/codemods/apply-visual-control.tsindex b431740910..d12d457440 100644--- a/packages/studio-server/src/codemods/apply-visual-control.ts+++ b/packages/studio-server/src/codemods/apply-visual-control.ts@@ -3,7 +3,10 @@ import type {ExpressionStatement,File,} from '@babel/types';-import type {ApplyVisualControlCodemod} from '@remotion/studio-shared';+import {+ stringifyDefaultProps,+ type ApplyVisualControlCodemod,+} from '@remotion/studio-shared';import type {namedTypes} from 'ast-types';import {visit} from 'ast-types';import type {ExpressionKind} from 'ast-types/lib/gen/kinds';@@ -61,8 +64,9 @@ export const applyVisualControl = ({const parsed = ((- parseAst('a = ' + change.newValueSerialized).program- .body[0] as unknown as ExpressionStatement+ parseAst(+ `a = ${stringifyDefaultProps({props: JSON.parse(change.newValueSerialized), enumPaths: change.enumPaths})}`,+ ).program.body[0] as unknown as ExpressionStatement).expression as AssignmentExpression).right as ExpressionKind;diff --git a/packages/studio-server/src/preview-server/handler.ts b/packages/studio-server/src/preview-server/handler.tsindex 5e8590959f..108f0c9e70 100644--- a/packages/studio-server/src/preview-server/handler.ts+++ b/packages/studio-server/src/preview-server/handler.ts@@ -55,6 +55,7 @@ export const handleRequest = async <Req, Res>({}),);} catch (err) {+ console.error(err);response.end(JSON.stringify({success: false,diff --git a/packages/studio-shared/src/codemods.ts b/packages/studio-shared/src/codemods.tsindex 8519469e87..5ad3ecc1e2 100644--- a/packages/studio-shared/src/codemods.ts+++ b/packages/studio-shared/src/codemods.ts@@ -1,6 +1,9 @@+import type {EnumPath} from './stringify-default-props';+export type VisualControlChange = {id: string;newValueSerialized: string;+ enumPaths: EnumPath[];};export type ApplyVisualControlCodemod = {diff --git a/packages/studio/src/api/save-default-props.ts b/packages/studio/src/api/save-default-props.tsindex 986a7745e8..c0736bbf2e 100644--- a/packages/studio/src/api/save-default-props.ts+++ b/packages/studio/src/api/save-default-props.ts@@ -1,4 +1,5 @@import {getRemotionEnvironment} from 'remotion';+import type {ZodTypesType} from '../components/get-zod-if-possible';import {extractEnumJsonPaths} from '../components/RenderModal/SchemaEditor/extract-enum-json-paths';import {callUpdateDefaultPropsApi} from '../components/RenderQueue/actions';import type {UpdateDefaultPropsFunction} from './helpers/calc-new-props';@@ -32,6 +33,10 @@ export const saveDefaultProps = async ({}const z = await import('zod');+ let zodTypes: ZodTypesType | null = null;+ try {+ zodTypes = await import('@remotion/zod-types');+ } catch {}const {generatedDefaultProps, composition} = calcNewProps(compositionId,@@ -41,7 +46,14 @@ export const saveDefaultProps = async ({const res = await callUpdateDefaultPropsApi(compositionId,generatedDefaultProps,- composition.schema ? extractEnumJsonPaths(composition.schema, z, []) : [],+ composition.schema+ ? extractEnumJsonPaths({+ schema: composition.schema,+ zodRuntime: z,+ currentPath: [],+ zodTypes,+ })+ : [],);if (res.success) {diff --git a/packages/studio/src/components/RenderModal/DataEditor.tsx b/packages/studio/src/components/RenderModal/DataEditor.tsxindex aaec37cc47..e75d682f5d 100644--- a/packages/studio/src/components/RenderModal/DataEditor.tsx+++ b/packages/studio/src/components/RenderModal/DataEditor.tsx@@ -19,7 +19,7 @@ import {} from '../RenderQueue/actions';import type {SegmentedControlItem} from '../SegmentedControl';import {SegmentedControl} from '../SegmentedControl';-import {useZodIfPossible} from '../get-zod-if-possible';+import {useZodIfPossible, useZodTypesIfPossible} from '../get-zod-if-possible';import {Flex, Spacing} from '../layout';import {RenderModalJSONPropsEditor} from './RenderModalJSONPropsEditor';import {SchemaEditor} from './SchemaEditor/SchemaEditor';@@ -147,7 +147,7 @@ export const DataEditor: React.FC<{}const value = defaultProps;- return NoReactInternals.serializeJSONWithDate({+ return NoReactInternals.serializeJSONWithSpecialTypes({data: value,indent: 2,staticBase: window.remotion_staticBase,@@ -161,6 +161,7 @@ export const DataEditor: React.FC<{});const z = useZodIfPossible();+ const zodTypes = useZodTypesIfPossible();const schema = useMemo(() => {if (!z) {@@ -300,7 +301,7 @@ export const DataEditor: React.FC<{callUpdateDefaultPropsApi(unresolvedComposition.id,defaultProps,- extractEnumJsonPaths(schema, z, []),+ extractEnumJsonPaths({schema, zodRuntime: z, currentPath: [], zodTypes}),).then((response) => {if (!response.success) {showNotification(@@ -309,7 +310,7 @@ export const DataEditor: React.FC<{);}});- }, [unresolvedComposition.id, defaultProps, schema, z]);+ }, [schema, z, unresolvedComposition.id, defaultProps, zodTypes]);const onSave = useCallback((@@ -326,7 +327,12 @@ export const DataEditor: React.FC<{callUpdateDefaultPropsApi(unresolvedComposition.id,newDefaultProps,- extractEnumJsonPaths(schema, z, []),+ extractEnumJsonPaths({+ schema,+ zodRuntime: z,+ currentPath: [],+ zodTypes,+ }),).then((response) => {if (!response.success) {@@ -353,6 +359,7 @@ export const DataEditor: React.FC<{[schema,z,+ zodTypes,fastRefreshes,setSaving,unresolvedComposition.defaultProps,diff --git a/packages/studio/src/components/RenderModal/RenderModalJSONPropsEditor.tsx b/packages/studio/src/components/RenderModal/RenderModalJSONPropsEditor.tsxindex 4014d9b485..16d82b629c 100644--- a/packages/studio/src/components/RenderModal/RenderModalJSONPropsEditor.tsx+++ b/packages/studio/src/components/RenderModal/RenderModalJSONPropsEditor.tsx@@ -27,7 +27,7 @@ const scrollable: React.CSSProperties = {const parseJSON = (str: string, schema: z.ZodTypeAny): State => {try {- const value = NoReactInternals.deserializeJSONWithCustomFields(str);+ const value = NoReactInternals.deserializeJSONWithSpecialTypes(str);const zodValidation = schema.safeParse(value);return {str, value, validJSON: true, zodValidation};} catch (e) {diff --git a/packages/studio/src/components/RenderModal/SchemaEditor/extract-enum-json-paths.ts b/packages/studio/src/components/RenderModal/SchemaEditor/extract-enum-json-paths.tsindex b1bc51a817..d11448fcbe 100644--- a/packages/studio/src/components/RenderModal/SchemaEditor/extract-enum-json-paths.ts+++ b/packages/studio/src/components/RenderModal/SchemaEditor/extract-enum-json-paths.ts@@ -1,11 +1,17 @@import type {z} from 'zod';-import type {ZodType} from '../../get-zod-if-possible';--export const extractEnumJsonPaths = (- schema: Zod.ZodTypeAny,- zodRuntime: ZodType,- currentPath: (string | number)[],-): (string | number)[][] => {+import type {ZodType, ZodTypesType} from '../../get-zod-if-possible';++export const extractEnumJsonPaths = ({+ schema,+ zodRuntime,+ currentPath,+ zodTypes,+}: {+ schema: Zod.ZodTypeAny;+ zodRuntime: ZodType;+ zodTypes: ZodTypesType | null;+ currentPath: (string | number)[];+}): (string | number)[][] => {const def = schema._def;const typeName = def.typeName as z.ZodFirstPartyTypeKind;@@ -15,25 +21,34 @@ export const extractEnumJsonPaths = (const keys = Object.keys(shape);return keys.map((key) => {- return extractEnumJsonPaths(shape[key], zodRuntime, [- ...currentPath,- key,- ]);+ return extractEnumJsonPaths({+ schema: shape[key],+ zodRuntime,+ currentPath: [...currentPath, key],+ zodTypes,+ });}).flat(1);}case zodRuntime.ZodFirstPartyTypeKind.ZodArray: {- return extractEnumJsonPaths((def as z.ZodArrayDef).type, zodRuntime, [- ...currentPath,- '[]',- ]);+ return extractEnumJsonPaths({+ schema: (def as z.ZodArrayDef).type,+ zodRuntime,+ currentPath: [...currentPath, '[]'],+ zodTypes,+ });}case zodRuntime.ZodFirstPartyTypeKind.ZodUnion: {return (def as z.ZodUnionDef).options.map((option) => {- return extractEnumJsonPaths(option, zodRuntime, currentPath);+ return extractEnumJsonPaths({+ schema: option,+ zodRuntime,+ currentPath,+ zodTypes,+ });}).flat(1);}@@ -41,7 +56,12 @@ export const extractEnumJsonPaths = (case zodRuntime.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {return (def as z.ZodDiscriminatedUnionDef<string>).options.map((op) => {- return extractEnumJsonPaths(op, zodRuntime, currentPath);+ return extractEnumJsonPaths({+ schema: op,+ zodRuntime,+ currentPath,+ zodTypes,+ });}).flat(1);}@@ -51,18 +71,37 @@ export const extractEnumJsonPaths = (}case zodRuntime.ZodFirstPartyTypeKind.ZodEffects: {- return extractEnumJsonPaths(- (def as z.ZodEffectsDef).schema,+ if (+ zodTypes &&+ schema._def.description ===+ zodTypes.ZodZypesInternals.REMOTION_MATRIX_BRAND+ ) {+ return [currentPath];+ }++ return extractEnumJsonPaths({+ schema: (def as z.ZodEffectsDef).schema,zodRuntime,currentPath,- );+ zodTypes,+ });}case zodRuntime.ZodFirstPartyTypeKind.ZodIntersection: {const {left, right} = def as z.ZodIntersectionDef;- const leftValue = extractEnumJsonPaths(left, zodRuntime, currentPath);+ const leftValue = extractEnumJsonPaths({+ schema: left,+ zodRuntime,+ currentPath,+ zodTypes,+ });- const rightValue = extractEnumJsonPaths(right, zodRuntime, currentPath);+ const rightValue = extractEnumJsonPaths({+ schema: right,+ zodRuntime,+ currentPath,+ zodTypes,+ });return [...leftValue, ...rightValue];}@@ -70,17 +109,23 @@ export const extractEnumJsonPaths = (case zodRuntime.ZodFirstPartyTypeKind.ZodTuple: {return (def as z.ZodTupleDef).items.map((item, i) =>- extractEnumJsonPaths(item, zodRuntime, [...currentPath, i]),+ extractEnumJsonPaths({+ schema: item,+ zodRuntime,+ currentPath: [...currentPath, i],+ zodTypes,+ }),).flat(1);}case zodRuntime.ZodFirstPartyTypeKind.ZodRecord: {- const values = extractEnumJsonPaths(- (def as z.ZodRecordDef).valueType,+ const values = extractEnumJsonPaths({+ schema: (def as z.ZodRecordDef).valueType,zodRuntime,- [...currentPath, '{}'],- );+ currentPath: [...currentPath, '{}'],+ zodTypes,+ });return values;}@@ -98,32 +143,44 @@ export const extractEnumJsonPaths = (case zodRuntime.ZodFirstPartyTypeKind.ZodOptional: {const defType = def as z.ZodOptionalDef;- const value = extractEnumJsonPaths(- defType.innerType,+ const value = extractEnumJsonPaths({+ schema: defType.innerType,zodRuntime,currentPath,- );+ zodTypes,+ });return value;}case zodRuntime.ZodFirstPartyTypeKind.ZodNullable: {const defType = def as z.ZodNullableDef;- const value = extractEnumJsonPaths(- defType.innerType,+ const value = extractEnumJsonPaths({+ schema: defType.innerType,zodRuntime,currentPath,- );+ zodTypes,+ });return value;}case zodRuntime.ZodFirstPartyTypeKind.ZodDefault: {const defType = def as z.ZodDefaultDef;- return extractEnumJsonPaths(defType.innerType, zodRuntime, currentPath);+ return extractEnumJsonPaths({+ schema: defType.innerType,+ zodRuntime,+ currentPath,+ zodTypes,+ });}case zodRuntime.ZodFirstPartyTypeKind.ZodCatch: {const defType = def as z.ZodCatchDef;- return extractEnumJsonPaths(defType.innerType, zodRuntime, currentPath);+ return extractEnumJsonPaths({+ schema: defType.innerType,+ zodRuntime,+ currentPath,+ zodTypes,+ });}case zodRuntime.ZodFirstPartyTypeKind.ZodPromise: {@@ -133,14 +190,24 @@ export const extractEnumJsonPaths = (case zodRuntime.ZodFirstPartyTypeKind.ZodBranded: {// eslint-disable-next-line @typescript-eslint/no-explicit-anyconst defType = def as z.ZodBrandedDef<any>;- const value = extractEnumJsonPaths(defType.type, zodRuntime, currentPath);+ const value = extractEnumJsonPaths({+ schema: defType.type,+ zodRuntime,+ currentPath,+ zodTypes,+ });return value;}case zodRuntime.ZodFirstPartyTypeKind.ZodPipeline: {// eslint-disable-next-line @typescript-eslint/no-explicit-anyconst defType = def as z.ZodPipelineDef<any, any>;- const value = extractEnumJsonPaths(defType.out, zodRuntime, currentPath);+ const value = extractEnumJsonPaths({+ schema: defType.out,+ zodRuntime,+ currentPath,+ zodTypes,+ });return value;}diff --git a/packages/studio/src/components/RenderQueue/actions.ts b/packages/studio/src/components/RenderQueue/actions.tsindex 25151261b7..121b154019 100644--- a/packages/studio/src/components/RenderQueue/actions.ts+++ b/packages/studio/src/components/RenderQueue/actions.ts@@ -74,7 +74,7 @@ export const addStillRenderJob = ({delayRenderTimeout,envVariables,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps,staticBase: window.remotion_staticBase,indent: undefined,@@ -148,7 +148,7 @@ export const addSequenceRenderJob = ({envVariables,concurrency,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps,staticBase: window.remotion_staticBase,indent: undefined,@@ -273,7 +273,7 @@ export const addVideoRenderJob = ({chromiumOptions,envVariables,serializedInputPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: inputProps,staticBase: window.remotion_staticBase,indent: undefined,@@ -368,7 +368,7 @@ export const callUpdateDefaultPropsApi = () => {return callApi('/api/update-default-props', {compositionId,- defaultProps: NoReactInternals.serializeJSONWithDate({+ defaultProps: NoReactInternals.serializeJSONWithSpecialTypes({data: defaultProps,indent: undefined,staticBase: window.remotion_staticBase,diff --git a/packages/studio/src/components/VisualControls/VisualControlHandle.tsx b/packages/studio/src/components/VisualControls/VisualControlHandle.tsxindex cd5356f061..767ccff451 100644--- a/packages/studio/src/components/VisualControls/VisualControlHandle.tsx+++ b/packages/studio/src/components/VisualControls/VisualControlHandle.tsx@@ -1,5 +1,6 @@import React, {useCallback, useContext} from 'react';import {Internals} from 'remotion';+import {NoReactInternals} from 'remotion/no-react';import {SetVisualControlsContext,VisualControlsContext,@@ -9,9 +10,10 @@ import {getVisualControlEditedValue} from '../../visual-controls/get-current-ediimport {showNotification} from '../Notifications/NotificationCenter';import type {UpdaterFunction} from '../RenderModal/SchemaEditor/ZodSwitch';import {ZodSwitch} from '../RenderModal/SchemaEditor/ZodSwitch';+import {extractEnumJsonPaths} from '../RenderModal/SchemaEditor/extract-enum-json-paths';import {useLocalState} from '../RenderModal/SchemaEditor/local-state';import {applyVisualControlChange} from '../RenderQueue/actions';-import {useZodIfPossible} from '../get-zod-if-possible';+import {useZodIfPossible, useZodTypesIfPossible} from '../get-zod-if-possible';import {Spacing} from '../layout';import {ClickableFileName} from './ClickableFileName';import {useOriginalFileName} from './get-original-stack-trace';@@ -25,6 +27,8 @@ export const VisualControlHandle: React.FC<{throw new Error('expected zod');}+ const zodTypes = useZodTypesIfPossible();+const state = useContext(VisualControlsContext);const {updateValue} = useContext(SetVisualControlsContext);const {fastRefreshes} = useContext(Internals.NonceContext);@@ -61,19 +65,39 @@ export const VisualControlHandle: React.FC<{const val = updater(value.valueInCode);window.remotion_ignoreFastRefreshUpdate = fastRefreshes + 1;+ const enumPaths = extractEnumJsonPaths({+ schema: value.schema,+ zodRuntime: z,+ currentPath: [],+ zodTypes,+ });applyVisualControlChange({fileName: originalFileName.source as string,changes: [{id: keyName,- newValueSerialized: JSON.stringify(val),+ newValueSerialized: NoReactInternals.serializeJSONWithSpecialTypes({+ data: val as Record<string, unknown>,+ indent: 2,+ staticBase: window.remotion_staticBase,+ }).serializedString,+ enumPaths,},],}).catch((e) => {showNotification(`Could not save visual control: ${e.message}`, 3000);});},- [fastRefreshes, keyName, value.valueInCode, originalFileName, disableSave],+ [+ disableSave,+ value.valueInCode,+ value.schema,+ fastRefreshes,+ z,+ originalFileName,+ keyName,+ zodTypes,+ ],);return (diff --git a/packages/studio/src/helpers/retry-payload.ts b/packages/studio/src/helpers/retry-payload.tsindex 44c373dcaf..d0b26d3f94 100644--- a/packages/studio/src/helpers/retry-payload.ts+++ b/packages/studio/src/helpers/retry-payload.ts@@ -46,7 +46,7 @@ export const makeRetryPayload = (job: RenderJob): RenderModalState => {initialHeadless: job.chromiumOptions.headless,initialIgnoreCertificateErrors:job.chromiumOptions.ignoreCertificateErrors,- defaultProps: NoReactInternals.deserializeJSONWithCustomFields(+ defaultProps: NoReactInternals.deserializeJSONWithSpecialTypes(job.serializedInputPropsWithCustomSchema,),inFrameMark: null,@@ -97,7 +97,7 @@ export const makeRetryPayload = (job: RenderJob): RenderModalState => {initialHeadless: job.chromiumOptions.headless,initialIgnoreCertificateErrors:job.chromiumOptions.ignoreCertificateErrors,- defaultProps: NoReactInternals.deserializeJSONWithCustomFields(+ defaultProps: NoReactInternals.deserializeJSONWithSpecialTypes(job.serializedInputPropsWithCustomSchema,),initialStillImageFormat: defaults.stillImageFormat,@@ -152,7 +152,7 @@ export const makeRetryPayload = (job: RenderJob): RenderModalState => {initialHeadless: job.chromiumOptions.headless,initialIgnoreCertificateErrors:job.chromiumOptions.ignoreCertificateErrors,- defaultProps: NoReactInternals.deserializeJSONWithCustomFields(+ defaultProps: NoReactInternals.deserializeJSONWithSpecialTypes(job.serializedInputPropsWithCustomSchema,),inFrameMark: job.startFrame,diff --git a/packages/studio/src/renderEntry.tsx b/packages/studio/src/renderEntry.tsxindex b3a90c53cc..2affa39374 100644--- a/packages/studio/src/renderEntry.tsx+++ b/packages/studio/src/renderEntry.tsx@@ -226,7 +226,7 @@ const renderContent = (Root: React.FC) => {numberOfAudioTags={0}onlyRenderComposition={bundleMode.compositionName}currentCompositionMetadata={{- props: NoReactInternals.deserializeJSONWithCustomFields(+ props: NoReactInternals.deserializeJSONWithSpecialTypes(bundleMode.serializedResolvedPropsWithSchema,),durationInFrames: bundleMode.compositionDurationInFrames,@@ -379,13 +379,13 @@ if (typeof window !== 'undefined') {return {...data,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: props,indent: undefined,staticBase: null,}).serializedString,serializedDefaultPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: defaultProps,indent: undefined,staticBase: null,@@ -444,13 +444,13 @@ if (typeof window !== 'undefined') {return {...data,serializedResolvedPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: props,indent: undefined,staticBase: null,}).serializedString,serializedDefaultPropsWithCustomSchema:- NoReactInternals.serializeJSONWithDate({+ NoReactInternals.serializeJSONWithSpecialTypes({data: defaultProps,indent: undefined,staticBase: null,diff --git a/packages/studio/src/test/extract-zod-enums.test.ts b/packages/studio/src/test/extract-zod-enums.test.tsindex f5c66ef85a..5970458509 100644--- a/packages/studio/src/test/extract-zod-enums.test.ts+++ b/packages/studio/src/test/extract-zod-enums.test.ts@@ -1,27 +1,33 @@+// eslint-disable-next-line @typescript-eslint/no-restricted-imports+import * as zodTypes from '@remotion/zod-types';import {expect, test} from 'bun:test';// eslint-disable-next-line @typescript-eslint/no-restricted-imports+import {zMatrix} from '@remotion/zod-types';+// eslint-disable-next-line @typescript-eslint/no-restricted-importsimport {z} from 'zod';import {extractEnumJsonPaths} from '../components/RenderModal/SchemaEditor/extract-enum-json-paths';test('Extract Zod enums', () => {expect(- extractEnumJsonPaths(- z.object({+ extractEnumJsonPaths({+ schema: z.object({enums: z.enum(['a', 'b', 'c']),}),- z,- [],- ),+ zodRuntime: z,+ currentPath: [],+ zodTypes,+ }),).toStrictEqual([['enums']]);});test('Extract Zod enums #2', () => {expect(- extractEnumJsonPaths(- z.object({+ extractEnumJsonPaths({+ schema: z.object({enums: z.enum(['a', 'b', 'c']),nested: z.object({second: z.enum(['a', 'b', 'c']),+ matrix: zMatrix(),}),arrays: z.array(z.enum(['a', 'b', 'c'])),union: z.object({hi: z.enum(['a'])}).or(z.object({abc: z.enum(['b'])})),@@ -42,12 +48,14 @@ test('Extract Zod enums #2', () => {.default({}),branded: z.object({a: z.enum(['a'])}).brand('branded'),}),- z,- [],- ),+ zodRuntime: z,+ currentPath: [],+ zodTypes,+ }),).toStrictEqual([['enums'],['nested', 'second'],+ ['nested', 'matrix'],['arrays', '[]'],['union', 'hi'],['union', 'abc'],diff --git a/packages/studio/src/test/stringify-default-props.test.ts b/packages/studio/src/test/stringify-default-props.test.tsindex e7cbd696ec..1068488c17 100644--- a/packages/studio/src/test/stringify-default-props.test.ts+++ b/packages/studio/src/test/stringify-default-props.test.ts@@ -1,6 +1,8 @@import {stringifyDefaultProps} from '@remotion/studio-shared';import {expect, test} from 'bun:test';// eslint-disable-next-line @typescript-eslint/no-restricted-imports+import * as zodTypes from '@remotion/zod-types';+// eslint-disable-next-line @typescript-eslint/no-restricted-importsimport {z} from 'zod';import {createZodValues} from '../components/RenderModal/SchemaEditor/create-zod-values';import {extractEnumJsonPaths} from '../components/RenderModal/SchemaEditor/extract-enum-json-paths';@@ -29,7 +31,12 @@ test('Should stringify default props correctly', () => {array: ['hi'],notAnEnum: '',});- const enumPaths = extractEnumJsonPaths(schema, z, []);+ const enumPaths = extractEnumJsonPaths({+ schema,+ zodRuntime: z,+ currentPath: [],+ zodTypes,+ });expect(enumPaths).toStrictEqual([['abc'], ['array', '[]']]);const result = stringifyDefaultProps({