Skip to content

🎥 Make videos programmatically with React

crash fix

Patric Salvisbergba5c3c813765
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
index a8356678e7..a89f472f95 100644
--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodObjectEditor.tsx
@@ -109,6 +109,14 @@ export const ZodObjectEditor: React.FC<{
return discriminatedUnionReplacement.markup;
}
+ let derivedDefaultValue;
+
+ if (defaultValue && defaultValue[key] !== undefined) {
+ derivedDefaultValue = defaultValue[key];
+ } else {
+ derivedDefaultValue = value[key];
+ }
+
return (
<React.Fragment key={key}>
<ZodSwitch
@@ -117,7 +125,7 @@ export const ZodObjectEditor: React.FC<{
schema={shape[key]}
value={localValue.value[key]}
// In case of null | {a: string, b: string} type, we need to fallback to the default value
- defaultValue={(defaultValue ?? value)[key]}
+ defaultValue={derivedDefaultValue}
setValue={(val, forceApply) => {
onChange(
(oldVal) => {
diff --git a/packages/example/src/Root.tsx b/packages/example/src/Root.tsx
index 05a687f477..df27d4937a 100644
--- a/packages/example/src/Root.tsx
+++ b/packages/example/src/Root.tsx
@@ -1,4 +1,3 @@
-import {zColor} from '@remotion/zod-types';
import {alias} from 'lib/alias';
import React, {useCallback} from 'react';
import {
@@ -949,126 +948,31 @@ export const Index: React.FC = () => {
height={630}
fps={30}
schema={z.object({
- vehicle: z
- .string()
- .max(3, 'Too long')
- .refine((v) => ['car', 'bus', 'truck'].includes(v)),
- other: z.string(),
- abc: z.object({
- union: z.null().or(
+ union: z.array(
+ z.discriminatedUnion('type', [
z.object({
- abc: z.string(),
+ type: z.literal('car'),
+ color: z.string(),
+ obj: z.array(
+ z.object({
+ link: z.string(),
+ }),
+ ),
}),
- ),
- jkl: z.string(),
- def: z.object({
- unionArray: z.array(z.null().or(z.string())),
- pef: z.string(),
- }),
- }),
- array: z
- .array(
z.object({
- a: z.string(),
- b: z.string(),
+ type: z.literal('boat'),
+ depth: z.number(),
}),
- )
- .min(2),
- array2: z.array(z.array(z.number())),
- mynum: z.number().lt(10),
- value: z.boolean().refine((v) => v === false || v === true),
- lol: z.undefined(),
- haha: z.null(),
- yo: z.any(),
- un: z.unknown(),
- num: z.coerce.string(),
- date: z.date(),
- values: z.enum(['a', 'b', 'c']),
- supersuperlongvalueabcdefghji: z.string(),
- incompatible: z.null().or(z.undefined()),
- color: zColor(),
- nullable: z.nullable(z.string()),
- optional: z.string().optional(),
- filePath: z.string().refine((v) => v.endsWith('.png')),
- longEnum: z.enum([
- 'a',
- 'b',
- 'c',
- 'd',
- 'e',
- 'f',
- 'gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg',
- 'h',
- 'i',
- 'j',
- 'k',
- 'l',
- 'm',
- 'n',
- 'o',
- 'p',
- 'q',
- 'r',
- 's',
- 't',
- 'u',
- 'v',
- 'w',
- 'x',
- 'y',
- 'z',
- ]),
- union: z.discriminatedUnion('type', [
- z.object({
- type: z.literal('car'),
- color: z.string(),
- }),
- z.object({
- type: z.literal('boat'),
- depth: z.number(),
- }),
- ]),
+ ]),
+ ),
})}
defaultProps={{
- vehicle: 'car',
- other: 'hi',
- abc: {
- union: null,
- def: {unionArray: [null], pef: 'hu'},
- jkl: 'sting',
- xyz: 'hi',
- },
- array: [
- {a: 'a', b: 'bbbbb'},
- {a: 'a', b: 'b'},
+ union: [
+ {type: 'boat' as const, depth: 10},
+ {type: 'car' as const, color: 'red', obj: [{link: 'hi there'}]},
],
- array2: [[12], [12]],
- mynum: 4,
- value: true,
- haha: null,
- yo: {hi: ' there'},
- un: 'hi',
- num: '179',
- date: new Date('1999-02-12T22:20:00.000Z'),
- values: 'a' as const,
- supersuperlongvalueabcdefghji: 'hi',
- incompatible: null,
- longEnum: 'k' as const,
- color: '#eb3a60',
- nullable: null,
- optional: '',
- filePath: staticFile('nested/logö.png'),
- union: {type: 'car', color: 'red'},
}}
durationInFrames={150}
- calculateMetadata={({defaultProps}) => {
- return {
- durationInFrames: defaultProps.mynum * 10,
- props: {
- ...defaultProps,
- },
- };
- }}
/>
</Folder>
<Folder name="Transitions">
@@ -1109,9 +1013,9 @@ export const Index: React.FC = () => {
defaultProps={{
title: 'sdasds',
delay: 5.2,
- color: '#b47841',
- list: ['test'],
- description: null,
+ color: '#df822a',
+ list: [{name: 'first', age: 12}],
+ description: 'Sample description \nOn multiple lines',
dropdown: 'a' as const,
}}
/>
diff --git a/packages/example/src/SchemaTest/index.tsx b/packages/example/src/SchemaTest/index.tsx
index 85208c77c1..a61de4bc0b 100644
--- a/packages/example/src/SchemaTest/index.tsx
+++ b/packages/example/src/SchemaTest/index.tsx
@@ -7,7 +7,7 @@ export const schemaTestSchema = z.object({
title: z.string().nullable(),
delay: z.number().min(0).max(1000).step(0.1),
color: zColor(),
- list: z.array(z.string()),
+ list: z.array(z.object({name: z.string(), age: z.number()})),
description: zTextarea().nullable(),
dropdown: z.enum(['a', 'b', 'c']),
});
@@ -46,8 +46,8 @@ export const SchemaTest: React.FC<z.infer<typeof schemaTestSchema>> = ({
<ul style={{listStyleType: 'disc'}}>
{list.map((item) => (
- <li key={item} style={{fontSize: 10}}>
- {item}
+ <li key={item.name} style={{fontSize: 30, color: 'red'}}>
+ {item.name} is {item.age} years old
</li>
))}
</ul>