Summary
Remotion Studio currently rejects any composition schema whose top-level Zod type is not a plain z.object(). Using z.discriminatedUnion() (a common pattern for preset-specific props) surfaces:
The top-level type of the schema must be a pure z.object. Instead got a schema of type discriminatedUnion
This forces a flat z.object() with all fields optional/defaulted and manual .superRefine() or runtime branching, which is weaker for typing and clutters the Studio props UI with irrelevant fields.
Motivation
z.discriminatedUnion("preset", [...]) is idiomatic Zod for “one of several shapes” (e.g. caption presets where only some variants have outline, centerStageFont, etc.). TypeScript narrows correctly on preset, and each branch can omit unrelated keys entirely.
Supporting this at the root would align Remotion with common Zod patterns and avoid workarounds.
Minimal example
import { z } from "zod";
const CaptionsSchema = z.discriminatedUnion("preset", [
z.object({
preset: z.literal("Simple"),
track: z.string(),
fontSize: z.number().default(48),
}),
z.object({
preset: z.literal("Fancy"),
track: z.string(),
fontSize: z.number().default(48),
outline: z.boolean().default(false), // only meaningful for Fancy
}),
]);
// <Composition schema={CaptionsSchema} ... />
// Today: Studio shows the error above.
// Desired: Schema editor / validation accept discriminated unions.
Possible directions
- Treat
ZodDiscriminatedUnion like z.object for the editor when the discriminator is a known literal field (e.g. preset).
- Or document a supported wrapper if full editor support is hard (e.g. codegen from union → flat object for Studio only).
Workaround
Use a single z.object({ preset, ...allFields }) with defaults and ignore irrelevant fields at runtime, or validate with .superRefine().
Happy to help test or sketch editor behavior for a fixed set of union members if useful.
Summary
Remotion Studio currently rejects any composition
schemawhose top-level Zod type is not a plainz.object(). Usingz.discriminatedUnion()(a common pattern for preset-specific props) surfaces:This forces a flat
z.object()with all fields optional/defaulted and manual.superRefine()or runtime branching, which is weaker for typing and clutters the Studio props UI with irrelevant fields.Motivation
z.discriminatedUnion("preset", [...])is idiomatic Zod for “one of several shapes” (e.g. caption presets where only some variants haveoutline,centerStageFont, etc.). TypeScript narrows correctly onpreset, and each branch can omit unrelated keys entirely.Supporting this at the root would align Remotion with common Zod patterns and avoid workarounds.
Minimal example
Possible directions
ZodDiscriminatedUnionlikez.objectfor the editor when the discriminator is a known literal field (e.g.preset).Workaround
Use a single
z.object({ preset, ...allFields })with defaults and ignore irrelevant fields at runtime, or validate with.superRefine().Happy to help test or sketch editor behavior for a fixed set of union members if useful.