🎥 Make videos programmatically with React
show big error message if no default props are specified
Jonny Burger4333baf76999
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsxindex 410a2e79e9..b80984d2bc 100644--- a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx+++ b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx@@ -6,7 +6,7 @@ import React, {useState,} from 'react';import type {AnyComposition} from 'remotion';-import {getInputProps} from 'remotion';+import {getInputProps, z} from 'remotion';import {BORDER_COLOR, LIGHT_TEXT} from '../../helpers/colors';import {ValidationMessage} from '../NewComposition/ValidationMessage';@@ -20,6 +20,10 @@ import type {SegmentedControlItem} from '../SegmentedControl';import {SegmentedControl} from '../SegmentedControl';import {RenderModalJSONInputPropsEditor} from './RenderModalJSONInputPropsEditor';import {SchemaEditor} from './SchemaEditor/SchemaEditor';+import {+ NoDefaultProps,+ NoSchemaDefined,+} from './SchemaEditor/SchemaErrorMessages';type Mode = 'json' | 'schema';@@ -175,6 +179,18 @@ export const RenderModalData: React.FC<{);}+ const def: z.ZodTypeDef = composition.schema._def;+ // eslint-disable-next-line @typescript-eslint/no-explicit-any+ const typeName = (def as any).typeName as z.ZodFirstPartyTypeKind;++ if (typeName === z.ZodFirstPartyTypeKind.ZodAny) {+ return <NoSchemaDefined />;+ }++ if (composition.defaultProps) {+ return <NoDefaultProps />;+ }+return (<div style={outer}><div style={controlContainer}>diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsxindex 6b0e145167..e70d359063 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaEditor.tsx@@ -1,26 +1,9 @@import React, {useCallback} from 'react';import {z} from 'remotion';-import {Button} from '../../../../preview-server/error-overlay/remotion-overlay/Button';-import {LIGHT_TEXT} from '../../../helpers/colors';-import {Spacing} from '../../layout';import {VERTICAL_SCROLLBAR_CLASSNAME} from '../../Menu/is-menu-item';-import {SchemaEmptyStateGraphic} from './SchemaEmptyStateGraphic';-import {ZodErrorMessages} from './ZodErrorMessages';+import {InvalidDefaultProps, InvalidSchema} from './SchemaErrorMessages';import {ZodObjectEditor} from './ZodObjectEditor';-const errorExplanation: React.CSSProperties = {- fontSize: 14,- color: LIGHT_TEXT,- fontFamily: 'sans-serif',- lineHeight: 1.5,-};--const codeSnippet: React.CSSProperties = {- fontSize: 14,- color: 'var(--blue)',- fontFamily: 'monospace',-};-const scrollable: React.CSSProperties = {padding: '8px 12px',display: 'flex',@@ -28,21 +11,6 @@ const scrollable: React.CSSProperties = {overflowY: 'auto',};-const explainer: React.CSSProperties = {- display: 'flex',- flex: 1,- flexDirection: 'column',- padding: '0 12px',- justifyContent: 'center',- alignItems: 'center',- textAlign: 'center',-};--const errorContainer: React.CSSProperties = {- padding: '8px 12px',- overflowY: 'auto',-};-export const SchemaEditor: React.FC<{schema: z.ZodTypeAny;value: unknown;@@ -70,92 +38,15 @@ export const SchemaEditor: React.FC<{setValue(defaultProps);}, [defaultProps, setValue]);- const openDocs = useCallback(() => {- window.open(- // TODO: Make sure to update this link when we release v4- 'https://v4.remotion.dev/docs/parametrized-rendering#define-a-schema-'- );- }, []);-- if (typeName === z.ZodFirstPartyTypeKind.ZodAny) {- return (- <div style={explainer}>- <SchemaEmptyStateGraphic />- <Spacing y={5} />- <div style={errorExplanation}>- Make the props of this composition interactively editable by adding a{' '}- <code style={codeSnippet}>schema</code> prop to the{' '}- <code style={codeSnippet}>{'<Composition>'}</code> component.- </div>- <Spacing y={2} block />- <Button onClick={openDocs}>Learn how</Button>- </div>- );- }-if (!zodValidationResult.success) {- if (defaultProps === undefined) {- return (- <div style={explainer}>- <div style={errorExplanation}>- The schema can not be edited because the{' '}- <code style={codeSnippet}>defaultProps</code> prop in the{' '}- <code style={codeSnippet}>{'<Composition>'}</code> does not exist.- </div>- <Spacing y={1} />- <div style={errorExplanation}>- Fix the schema by adding a{' '}- <code style={codeSnippet}>defaultProps</code> prop to your- composition.- </div>- <Spacing y={2} block />- <Button onClick={openDocs}>Learn more</Button>- </div>- );- }-const defaultPropsValid = schema.safeParse(defaultProps);if (!defaultPropsValid.success) {- // TODO: Does not react to when schema is updated- return (- <div style={errorContainer}>- <div style={errorExplanation}>- The schema can not be edited because the{' '}- <code style={codeSnippet}>defaultProps</code> prop in the{' '}- <code style={codeSnippet}>{'<Composition>'}</code> is not valid:- </div>- <Spacing y={1} block />- <ZodErrorMessages zodValidationResult={zodValidationResult} />- <Spacing y={1} block />- <div style={errorExplanation}>- Fix the schema by changing the{' '}- <code style={codeSnippet}>defaultProps</code> prop in your- composition so it does not give a type error.- </div>- </div>- );+ return <InvalidDefaultProps zodValidationResult={zodValidationResult} />;}return (- <div style={errorContainer}>- <div style={errorExplanation}>- The data does not satisfy the schema:- </div>- <Spacing y={1} block />- <ZodErrorMessages zodValidationResult={zodValidationResult} />- <Spacing y={1} block />- <div style={errorExplanation}>- Fix the schema using the JSON editor.- </div>- <Spacing y={1} block />- <div style={errorExplanation}>- Alternatively, reset the data to the <code>defaultProps</code> that- you have defined.- </div>- <Spacing y={1} block />- <Button onClick={reset}>Reset props</Button>- </div>+ <InvalidSchema reset={reset} zodValidationResult={zodValidationResult} />);}diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.tsxnew file mode 100644index 0000000000..04f8f3de19--- /dev/null+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/SchemaErrorMessages.tsx@@ -0,0 +1,122 @@+import type {z} from 'remotion';+import {Button} from '../../../../preview-server/error-overlay/remotion-overlay/Button';+import {LIGHT_TEXT} from '../../../helpers/colors';+import {Spacing} from '../../layout';+import {SchemaEmptyStateGraphic} from './SchemaEmptyStateGraphic';+import {ZodErrorMessages} from './ZodErrorMessages';++const explainer: React.CSSProperties = {+ display: 'flex',+ flex: 1,+ flexDirection: 'column',+ padding: '0 12px',+ justifyContent: 'center',+ alignItems: 'center',+ textAlign: 'center',+};++const errorExplanation: React.CSSProperties = {+ fontSize: 14,+ color: LIGHT_TEXT,+ fontFamily: 'sans-serif',+ lineHeight: 1.5,+};++const codeSnippet: React.CSSProperties = {+ fontSize: 14,+ color: 'var(--blue)',+ fontFamily: 'monospace',+};++const errorContainer: React.CSSProperties = {+ padding: '8px 12px',+ overflowY: 'auto',+};++const openDocs = () => {+ window.open(+ // TODO: Make sure to update this link when we release v4+ 'https://v4.remotion.dev/docs/parametrized-rendering#define-a-schema-'+ );+};++export const NoSchemaDefined = () => {+ return (+ <div style={explainer}>+ <SchemaEmptyStateGraphic />+ <Spacing y={5} />+ <div style={errorExplanation}>+ Make the props of this composition interactively editable by adding a{' '}+ <code style={codeSnippet}>schema</code> prop to the{' '}+ <code style={codeSnippet}>{'<Composition>'}</code> component.+ </div>+ <Spacing y={2} block />+ <Button onClick={openDocs}>Learn how</Button>+ </div>+ );+};++export const NoDefaultProps = () => {+ return (+ <div style={explainer}>+ <div style={errorExplanation}>+ The schema can not be edited because the{' '}+ <code style={codeSnippet}>defaultProps</code> prop in the{' '}+ <code style={codeSnippet}>{'<Composition>'}</code> does not exist.+ </div>+ <Spacing y={1} />+ <div style={errorExplanation}>+ Fix the schema by adding a <code style={codeSnippet}>defaultProps</code>{' '}+ prop to your composition.+ </div>+ <Spacing y={2} block />+ <Button onClick={openDocs}>Learn more</Button>+ </div>+ );+};++export const InvalidDefaultProps: React.FC<{+ zodValidationResult: z.SafeParseReturnType<unknown, unknown>;+}> = ({zodValidationResult}) => {+ // TODO: Does not react to when schema is updated++ return (+ <div style={errorContainer}>+ <div style={errorExplanation}>+ The schema can not be edited because the{' '}+ <code style={codeSnippet}>defaultProps</code> prop in the{' '}+ <code style={codeSnippet}>{'<Composition>'}</code> is not valid:+ </div>+ <Spacing y={1} block />+ <ZodErrorMessages zodValidationResult={zodValidationResult} />+ <Spacing y={1} block />+ <div style={errorExplanation}>+ Fix the schema by changing the{' '}+ <code style={codeSnippet}>defaultProps</code> prop in your composition+ so it does not give a type error.+ </div>+ </div>+ );+};++export const InvalidSchema: React.FC<{+ zodValidationResult: z.SafeParseReturnType<unknown, unknown>;+ reset: () => void;+}> = ({zodValidationResult, reset}) => {+ return (+ <div style={errorContainer}>+ <div style={errorExplanation}>The data does not satisfy the schema:</div>+ <Spacing y={1} block />+ <ZodErrorMessages zodValidationResult={zodValidationResult} />+ <Spacing y={1} block />+ <div style={errorExplanation}>Fix the schema using the JSON editor.</div>+ <Spacing y={1} block />+ <div style={errorExplanation}>+ Alternatively, reset the data to the <code>defaultProps</code> that you+ have defined.+ </div>+ <Spacing y={1} block />+ <Button onClick={reset}>Reset props</Button>+ </div>+ );+};diff --git a/packages/cli/src/editor/components/RenderQueue/index.tsx b/packages/cli/src/editor/components/RenderQueue/index.tsxindex dd42c05346..9637815d1e 100644--- a/packages/cli/src/editor/components/RenderQueue/index.tsx+++ b/packages/cli/src/editor/components/RenderQueue/index.tsx@@ -35,9 +35,7 @@ export const RenderQueue: React.FC = () => {return (<div style={explainer}><Spacing y={5} />- <div style={errorExplanation}>- The preview server has disconnected. Renderqueue unavailable.- </div>+ <div style={errorExplanation}>The preview server has disconnected.</div><Spacing y={2} block /></div>);@@ -47,10 +45,7 @@ export const RenderQueue: React.FC = () => {return (<div style={explainer}><Spacing y={5} />- <div style={errorExplanation}>- No renders done yet. Click on the Rocket or press R to render this- composition- </div>+ <div style={errorExplanation}>No renders in the queue.</div><Spacing y={2} block /></div>);