Skip to content

🎥 Make videos programmatically with React

Simplify web-renderer to only support Zod v4

Jonny Burger0be7801fd86e
diff --git a/packages/web-renderer/src/create-scaffold.tsx b/packages/web-renderer/src/create-scaffold.tsx
index 7fe063a1db..02d7237a06 100644
--- a/packages/web-renderer/src/create-scaffold.tsx
+++ b/packages/web-renderer/src/create-scaffold.tsx
@@ -1,14 +1,9 @@
import {createRef, type ComponentType} from 'react';
import {flushSync} from 'react-dom';
import ReactDOM from 'react-dom/client';
-import type {
- AnyZodObject,
- Codec,
- DelayRenderScope,
- LogLevel,
- TRenderAsset,
-} from 'remotion';
+import type {Codec, DelayRenderScope, LogLevel, TRenderAsset} from 'remotion';
import {Internals} from 'remotion';
+import type {$ZodObject} from 'zod/v4/core';
import type {TimeUpdaterRef} from './update-time';
import {UpdateTime} from './update-time';
@@ -50,7 +45,7 @@ export function createScaffold<Props extends Record<string, unknown>>({
initialFrame: number;
durationInFrames: number;
fps: number;
- schema: AnyZodObject | null;
+ schema: $ZodObject | null;
Component: ComponentType<Props>;
audioEnabled: boolean;
videoEnabled: boolean;
diff --git a/packages/web-renderer/src/props-if-has-props.ts b/packages/web-renderer/src/props-if-has-props.ts
index 87fbe09429..3e9564ac20 100644
--- a/packages/web-renderer/src/props-if-has-props.ts
+++ b/packages/web-renderer/src/props-if-has-props.ts
@@ -1,18 +1,12 @@
import type {ComponentType} from 'react';
-import type {AnyZodObject, CalculateMetadataFunction} from 'remotion';
-
-// eslint-disable-next-line @typescript-eslint/no-explicit-any
-export type InferZodInput<T> = T extends {_zod: {input: any}}
- ? T['_zod']['input']
- : // eslint-disable-next-line @typescript-eslint/no-explicit-any
- T extends {_input: any}
- ? T['_input']
- : Record<string, unknown>;
+import type {CalculateMetadataFunction} from 'remotion';
+import type {z} from 'zod';
+import type {$ZodObject} from 'zod/v4/core';
export type InferProps<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
-> = AnyZodObject extends Schema
+> = $ZodObject extends Schema
? {} extends Props
? // Neither props nor schema specified
Record<string, unknown>
@@ -20,18 +14,18 @@ export type InferProps<
Props
: {} extends Props
? // Only schema specified
- InferZodInput<Schema>
+ z.input<Schema>
: // Props and schema specified
- InferZodInput<Schema> & Props;
+ z.input<Schema> & Props;
export type DefaultPropsIfHasProps<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props,
-> = AnyZodObject extends Schema
+> = $ZodObject extends Schema
? {} extends Props
? {
// Neither props nor schema specified
- defaultProps?: InferZodInput<Schema> & Props;
+ defaultProps?: z.input<Schema> & Props;
}
: {
// Only props specified
@@ -40,17 +34,17 @@ export type DefaultPropsIfHasProps<
: {} extends Props
? {
// Only schema specified
- defaultProps: InferZodInput<Schema>;
+ defaultProps: z.input<Schema>;
}
: {
// Props and schema specified
- defaultProps: InferZodInput<Schema> & Props;
+ defaultProps: z.input<Schema> & Props;
};
type LooseComponentType<T> = ComponentType<T> | ((props: T) => React.ReactNode);
type OptionalDimensions<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = {
component: LooseComponentType<Props>;
@@ -61,7 +55,7 @@ type OptionalDimensions<
};
type MandatoryDimensions<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = {
component: LooseComponentType<Props>;
@@ -74,7 +68,7 @@ type MandatoryDimensions<
};
export type CompositionCalculateMetadataOrExplicit<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = (
| (OptionalDimensions<Schema, Props> & {
diff --git a/packages/web-renderer/src/render-media-on-web.tsx b/packages/web-renderer/src/render-media-on-web.tsx
index 9d9e55b6f4..74c455495e 100644
--- a/packages/web-renderer/src/render-media-on-web.tsx
+++ b/packages/web-renderer/src/render-media-on-web.tsx
@@ -1,7 +1,9 @@
import {BufferTarget, StreamTarget} from 'mediabunny';
-import type {AnyZodObject, CalculateMetadataFunction} from 'remotion';
+import type {CalculateMetadataFunction} from 'remotion';
import {Internals, type LogLevel} from 'remotion';
import {VERSION} from 'remotion/version';
+import type {z} from 'zod';
+import type {$ZodObject} from 'zod/v4/core';
import {addAudioSample, addVideoSampleAndCloseFrame} from './add-sample';
import {handleArtifacts, type WebRendererOnArtifact} from './artifact';
import {onlyInlineAudio} from './audio';
@@ -31,10 +33,7 @@ import {
type WebRendererVideoCodec,
} from './mediabunny-mappings';
import type {WebRendererOutputTarget} from './output-target';
-import type {
- CompositionCalculateMetadataOrExplicit,
- InferZodInput,
-} from './props-if-has-props';
+import type {CompositionCalculateMetadataOrExplicit} from './props-if-has-props';
import {onlyOneRenderAtATimeQueue} from './render-operations-queue';
import {resolveAudioCodec} from './resolve-audio-codec';
import {sendUsageEvent} from './send-telemetry-event';
@@ -46,13 +45,13 @@ import {waitForReady} from './wait-for-ready';
import {cleanupStaleOpfsFiles, createWebFsTarget} from './web-fs-target';
export type InputPropsIfHasProps<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props,
-> = AnyZodObject extends Schema
+> = $ZodObject extends Schema
? {} extends Props
? {
// Neither props nor schema specified
- inputProps?: InferZodInput<Schema> & Props;
+ inputProps?: z.input<Schema> & Props;
}
: {
// Only props specified
@@ -61,15 +60,15 @@ export type InputPropsIfHasProps<
: {} extends Props
? {
// Only schema specified
- inputProps: InferZodInput<Schema>;
+ inputProps: z.input<Schema>;
}
: {
// Props and schema specified
- inputProps: InferZodInput<Schema> & Props;
+ inputProps: z.input<Schema> & Props;
};
type MandatoryRenderMediaOnWebOptions<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = {
composition: CompositionCalculateMetadataOrExplicit<Schema, Props>;
@@ -95,7 +94,7 @@ export type WebRendererHardwareAcceleration =
| 'prefer-hardware'
| 'prefer-software';
-type OptionalRenderMediaOnWebOptions<Schema extends AnyZodObject> = {
+type OptionalRenderMediaOnWebOptions<Schema extends $ZodObject> = {
delayRenderTimeoutInMilliseconds: number;
logLevel: LogLevel;
schema: Schema | undefined;
@@ -121,14 +120,14 @@ type OptionalRenderMediaOnWebOptions<Schema extends AnyZodObject> = {
};
export type RenderMediaOnWebOptions<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = MandatoryRenderMediaOnWebOptions<Schema, Props> &
Partial<OptionalRenderMediaOnWebOptions<Schema>> &
InputPropsIfHasProps<Schema, Props>;
type InternalRenderMediaOnWebOptions<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = MandatoryRenderMediaOnWebOptions<Schema, Props> &
OptionalRenderMediaOnWebOptions<Schema> &
@@ -139,7 +138,7 @@ type InternalRenderMediaOnWebOptions<
// TODO: Apply defaultCodec
const internalRenderMediaOnWeb = async <
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
>({
composition,
@@ -534,7 +533,7 @@ const internalRenderMediaOnWeb = async <
};
export const renderMediaOnWeb = <
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
>(
options: RenderMediaOnWebOptions<Schema, Props>,
diff --git a/packages/web-renderer/src/render-still-on-web.tsx b/packages/web-renderer/src/render-still-on-web.tsx
index bce0cb6a44..ce28d2125a 100644
--- a/packages/web-renderer/src/render-still-on-web.tsx
+++ b/packages/web-renderer/src/render-still-on-web.tsx
@@ -1,9 +1,9 @@
-import type {AnyZodObject} from 'remotion';
import {
Internals,
type CalculateMetadataFunction,
type LogLevel,
} from 'remotion';
+import type {$ZodObject} from 'zod/v4/core';
import type {WebRendererOnArtifact} from './artifact';
import {handleArtifacts} from './artifact';
import {checkForError, createScaffold} from './create-scaffold';
@@ -20,7 +20,7 @@ import {waitForReady} from './wait-for-ready';
export type RenderStillOnWebImageFormat = 'png' | 'jpeg' | 'webp';
type MandatoryRenderStillOnWebOptions<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = {
frame: number;
@@ -29,7 +29,7 @@ type MandatoryRenderStillOnWebOptions<
composition: CompositionCalculateMetadataOrExplicit<Schema, Props>;
};
-type OptionalRenderStillOnWebOptions<Schema extends AnyZodObject> = {
+type OptionalRenderStillOnWebOptions<Schema extends $ZodObject> = {
delayRenderTimeoutInMilliseconds: number;
logLevel: LogLevel;
schema: Schema | undefined;
@@ -42,21 +42,21 @@ type OptionalRenderStillOnWebOptions<Schema extends AnyZodObject> = {
};
type InternalRenderStillOnWebOptions<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = MandatoryRenderStillOnWebOptions<Schema, Props> &
OptionalRenderStillOnWebOptions<Schema> &
InputPropsIfHasProps<Schema, Props>;
export type RenderStillOnWebOptions<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
> = MandatoryRenderStillOnWebOptions<Schema, Props> &
Partial<OptionalRenderStillOnWebOptions<Schema>> &
InputPropsIfHasProps<Schema, Props>;
async function internalRenderStillOnWeb<
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
>({
frame,
@@ -187,7 +187,7 @@ async function internalRenderStillOnWeb<
}
export const renderStillOnWeb = <
- Schema extends AnyZodObject,
+ Schema extends $ZodObject,
Props extends Record<string, unknown>,
>(
options: RenderStillOnWebOptions<Schema, Props>,