🎥 Make videos programmatically with React
Add resolve guidance for default props warning
Cursor Agentced8dd1b6d90
diff --git a/packages/docs/docs/troubleshooting/cannot-save-default-props.mdx b/packages/docs/docs/troubleshooting/cannot-save-default-props.mdxnew file mode 100644index 0000000000..845a61d8d1--- /dev/null+++ b/packages/docs/docs/troubleshooting/cannot-save-default-props.mdx@@ -0,0 +1,103 @@+---+image: /generated/articles-docs-troubleshooting-cannot-save-default-props.png+sidebar_label: Cannot save default props+title: Cannot save default props+crumb: 'Troubleshooting'+---++# Cannot save default props++If the Props editor shows this warning:++```+Can't save default props: Could not find or extract defaultProps for composition "[composition-id]".+```++Remotion Studio can preview the composition, but it cannot write edited props back to your root file.++## Why this warning appears++The Props editor saves changes by modifying the `defaultProps` prop on the matching [`<Composition>`](/docs/composition) or [`<Still>`](/docs/still).+For that to work, Remotion needs to find the root file and extract the existing `defaultProps` value from source code.++This warning appears if one of these conditions is true:++- The composition has no `defaultProps` prop.+- The composition ID is not hardcoded as a string.+- The `defaultProps` value is not a hardcoded object literal.+- The root file cannot be found from the entry point or the known root file paths.+- The root file is not TypeScript.++## How to fix it++Put the composition in a root file that Remotion can find, and hardcode the `id` and `defaultProps` values:++```tsx title="Root.tsx"+import {Composition} from 'remotion';+import {MyComposition} from './MyComposition';++export const RemotionRoot = () => {+ return (+ <Composition+ id="my-comp"+ component={MyComposition}+ durationInFrames={150}+ fps={30}+ width={1920}+ height={1080}+ defaultProps={{+ title: 'Hello world',+ color: '#ffffff',+ }}+ />+ );+};+```++Avoid values that need runtime evaluation:++```tsx title="Root.tsx"+import {Composition} from 'remotion';+import {MyComposition} from './MyComposition';++const props = {+ title: 'Hello world',+};++export const RemotionRoot = () => {+ return <Composition id={'my-comp'} component={MyComposition} durationInFrames={150} fps={30} width={1920} height={1080} defaultProps={props} />;+};+```++## Root file paths++Remotion can automatically find a root file at these paths:++- `src/Root.tsx`+- `src/Root.jsx`+- `remotion/Root.tsx`+- `remotion/Root.jsx`+- `app/remotion/Root.tsx`+- `src/Video.tsx`+- `src/Video.jsx`+- `src/remotion/Root.tsx`+- `src/remotion/Root.jsx`++If your entry point ends in `-entry`, Remotion also looks for a matching PascalCase root next to it.+For example, `gold-star-entry.tsx` maps to `GoldStarRoot.tsx`.++## AI agent prompt++Use this prompt to resolve the warning:++```txt+Remotion Studio shows "Can't save default props" for my composition.+Find the root file that registers the composition, then make the composition id and defaultProps statically analyzable.+The id should be a hardcoded string and defaultProps should be an inline object literal on the <Composition> or <Still>.+Preserve the current prop values and keep the composition behavior unchanged.+```++## See also++- [`<Composition>`](/docs/composition)+- [`saveDefaultProps()`](/docs/studio/save-default-props)diff --git a/packages/docs/sidebars.ts b/packages/docs/sidebars.tsindex 348d06f1cc..c934afdb90 100644--- a/packages/docs/sidebars.ts+++ b/packages/docs/sidebars.ts@@ -1439,6 +1439,7 @@ const sidebars: SidebarsConfig = {'troubleshooting/rosetta','troubleshooting/loading-root-component','troubleshooting/defaultprops-too-big',+ 'troubleshooting/cannot-save-default-props','troubleshooting/could-not-be-parsed-as-a-value-list','troubleshooting/broken-fast-refresh','troubleshooting/timed-out-page-function',diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.tsindex 16e066a47b..0ec8e928b4 100644--- a/packages/docs/src/data/articles.ts+++ b/packages/docs/src/data/articles.ts@@ -6753,6 +6753,15 @@ export const articles = [noAi: false,slug: 'troubleshooting/bundling-bundle',},+ {+ id: 'troubleshooting/cannot-save-default-props',+ title: 'Cannot save default props',+ relativePath: 'docs/troubleshooting/cannot-save-default-props.mdx',+ compId: 'articles-docs-troubleshooting-cannot-save-default-props',+ crumb: 'Troubleshooting',+ noAi: false,+ slug: 'troubleshooting/cannot-save-default-props',+ },{id: 'troubleshooting/could-not-be-parsed-as-a-value-list',title: 'The source provided could not be parsed as a value list',diff --git a/packages/docs/static/generated/articles-docs-troubleshooting-cannot-save-default-props.png b/packages/docs/static/generated/articles-docs-troubleshooting-cannot-save-default-props.pngnew file mode 100644index 0000000000..75dc0e2c2aBinary files /dev/null and b/packages/docs/static/generated/articles-docs-troubleshooting-cannot-save-default-props.png differdiff --git a/packages/studio/src/components/NewComposition/ValidationMessage.tsx b/packages/studio/src/components/NewComposition/ValidationMessage.tsxindex 6778d8eb8a..0fd71f373a 100644--- a/packages/studio/src/components/NewComposition/ValidationMessage.tsx+++ b/packages/studio/src/components/NewComposition/ValidationMessage.tsx@@ -28,10 +28,11 @@ const label: React.CSSProperties = {};export const ValidationMessage: React.FC<{- readonly message: string;+ readonly message: React.ReactNode;readonly align: 'flex-start' | 'flex-end';readonly type: 'warning' | 'error';-}> = ({message, align, type}) => {+ readonly action?: React.ReactNode;+}> = ({message, align, type, action}) => {const finalStyle = useMemo(() => {return {...style,@@ -45,6 +46,12 @@ export const ValidationMessage: React.FC<{<WarningTriangle style={finalStyle} /><Spacing x={1} /><div style={label}>{message}</div>+ {action ? (+ <>+ <Spacing x={1} />+ {action}+ </>+ ) : null}</Row></div>);diff --git a/packages/studio/src/components/RenderModal/DataEditor.tsx b/packages/studio/src/components/RenderModal/DataEditor.tsxindex d5aae107db..ebd7ffc754 100644--- a/packages/studio/src/components/RenderModal/DataEditor.tsx+++ b/packages/studio/src/components/RenderModal/DataEditor.tsx@@ -3,7 +3,7 @@ import type {_InternalTypes, SerializedJSONWithCustomFields} from 'remotion';import {getInputProps} from 'remotion';import {NoReactInternals} from 'remotion/no-react';import {StudioServerConnectionCtx} from '../../helpers/client-id';-import {BACKGROUND, BORDER_COLOR, LIGHT_TEXT} from '../../helpers/colors';+import {BACKGROUND, BLUE, BORDER_COLOR, LIGHT_TEXT} from '../../helpers/colors';import {useZodIfPossible} from '../get-zod-if-possible';import {Flex, Spacing} from '../layout';import {ValidationMessage} from '../NewComposition/ValidationMessage';@@ -82,6 +82,14 @@ const tabWrapper: React.CSSProperties = {alignItems: 'center',};+const resolveLinkStyle: React.CSSProperties = {+ color: BLUE,+ fontSize: 13,+ fontFamily: 'sans-serif',+ textDecoration: 'none',+ whiteSpace: 'nowrap',+};+const persistanceKey = 'remotion.show-render-modalwarning';const getPersistedShowWarningState = () => {@@ -299,12 +307,24 @@ export const DataEditor: React.FC<{</div>{showWarning && warnings.length > 0? warnings.map((warning) => (- <React.Fragment key={warning}>+ <React.Fragment key={warning.id}><Spacing y={1} /><ValidationMessage- message={warning}+ message={warning.message}align="flex-start"type="warning"+ action={+ warning.resolveLink ? (+ <a+ href={warning.resolveLink}+ target="_blank"+ rel="noopener noreferrer"+ style={resolveLinkStyle}+ >+ Resolve+ </a>+ ) : null+ }/></React.Fragment>))diff --git a/packages/studio/src/components/RenderModal/get-render-modal-warnings.ts b/packages/studio/src/components/RenderModal/get-render-modal-warnings.tsindex e50999b41c..440015b014 100644--- a/packages/studio/src/components/RenderModal/get-render-modal-warnings.ts+++ b/packages/studio/src/components/RenderModal/get-render-modal-warnings.ts@@ -1,6 +1,15 @@import {NoReactInternals} from 'remotion/no-react';import type {PropsEditType} from './DataEditor';+export const CANNOT_SAVE_DEFAULT_PROPS_DOCS =+ 'https://www.remotion.dev/docs/troubleshooting/cannot-save-default-props';++export type RenderModalWarning = {+ readonly id: string;+ readonly message: string;+ readonly resolveLink?: string;+};+export type TypeCanSaveState =| {canUpdate: true;@@ -11,6 +20,20 @@ export type TypeCanSaveState =determined: boolean;};+const warningOrNull = (+ id: string,+ message: string | null,+): RenderModalWarning | null => {+ if (message === null) {+ return null;+ }++ return {+ id,+ message,+ };+};+const getInputPropsWarning = ({cliProps,propsEditType,@@ -30,7 +53,7 @@ const getInputPropsWarning = ({const getCannotSaveDefaultProps = (canSaveDefaultProps: TypeCanSaveState | null,-) => {+): RenderModalWarning | null => {if (canSaveDefaultProps === null) {return null;}@@ -43,7 +66,11 @@ const getCannotSaveDefaultProps = (return null;}- return `Can't save default props: ${canSaveDefaultProps.reason}.`;+ return {+ id: 'cannot-save-default-props',+ message: `Can't save default props: ${canSaveDefaultProps.reason}.`,+ resolveLink: CANNOT_SAVE_DEFAULT_PROPS_DOCS,+ };};const customDateUsed = (used: boolean | undefined, inJSONEditor: boolean) => {@@ -96,13 +123,22 @@ export const getRenderModalWarnings = ({jsSetUsed: boolean;inJSONEditor: boolean;propsEditType: PropsEditType;-}) => {+}): RenderModalWarning[] => {return [- getInputPropsWarning({cliProps, propsEditType}),+ warningOrNull(+ 'input-props-override',+ getInputPropsWarning({cliProps, propsEditType}),+ ),getCannotSaveDefaultProps(canSaveDefaultProps),- customDateUsed(isCustomDateUsed, inJSONEditor),- staticFileUsed(customFileUsed, inJSONEditor),- mapUsed(jsMapUsed, inJSONEditor),- setUsed(jsSetUsed, inJSONEditor),+ warningOrNull(+ 'custom-date-used',+ customDateUsed(isCustomDateUsed, inJSONEditor),+ ),+ warningOrNull(+ 'static-file-used',+ staticFileUsed(customFileUsed, inJSONEditor),+ ),+ warningOrNull('map-used', mapUsed(jsMapUsed, inJSONEditor)),+ warningOrNull('set-used', setUsed(jsSetUsed, inJSONEditor)),].filter(NoReactInternals.truthy);};diff --git a/packages/studio/src/test/render-modal-warnings.test.ts b/packages/studio/src/test/render-modal-warnings.test.tsnew file mode 100644index 0000000000..45bdb2431a--- /dev/null+++ b/packages/studio/src/test/render-modal-warnings.test.ts@@ -0,0 +1,50 @@+import {expect, test} from 'bun:test';+import {+ CANNOT_SAVE_DEFAULT_PROPS_DOCS,+ getRenderModalWarnings,+} from '../components/RenderModal/get-render-modal-warnings';++test('Adds a Resolve link to the cannot save default props warning', () => {+ const warnings = getRenderModalWarnings({+ cliProps: {},+ canSaveDefaultProps: {+ canUpdate: false,+ determined: true,+ reason: 'Could not find or extract defaultProps for composition "Demo"',+ },+ isCustomDateUsed: false,+ customFileUsed: false,+ jsMapUsed: false,+ jsSetUsed: false,+ inJSONEditor: false,+ propsEditType: 'default-props',+ });++ expect(warnings).toStrictEqual([+ {+ id: 'cannot-save-default-props',+ message:+ 'Can\'t save default props: Could not find or extract defaultProps for composition "Demo".',+ resolveLink: CANNOT_SAVE_DEFAULT_PROPS_DOCS,+ },+ ]);+});++test('Does not add warnings before default props saveability is determined', () => {+ const warnings = getRenderModalWarnings({+ cliProps: {},+ canSaveDefaultProps: {+ canUpdate: false,+ determined: false,+ reason: 'Pending',+ },+ isCustomDateUsed: false,+ customFileUsed: false,+ jsMapUsed: false,+ jsSetUsed: false,+ inJSONEditor: false,+ propsEditType: 'default-props',+ });++ expect(warnings).toStrictEqual([]);+});