π₯ Make videos programmatically with React
`remotion-monorepo`: Preserve computed styles from object spreads (#9462)
Jonny Burgerf41f30c92a6c
diff --git a/packages/docs/docs/studio/interactivity-best-practices.mdx b/packages/docs/docs/studio/interactivity-best-practices.mdxindex f57d9d5c21..3caccbe3f0 100644--- a/packages/docs/docs/studio/interactivity-best-practices.mdx+++ b/packages/docs/docs/studio/interactivity-best-practices.mdx@@ -71,6 +71,9 @@ Do not animate with frame math such as `frame * 2`, modulo expressions, helper fKeep the input range and output range directly in the `interpolate()` call.The input range must use hardcoded numbers, not variables or expressions such as `[sendStartFrame, sendStartFrame + duration]`.+Do not use object spreads for interactive props.+Write the values inline so the Studio can detect and edit them.+```tsx title="Inline values"// π Inline values can be standardized and keyframed<Interactive.Divdiff --git a/packages/skills/skills/remotion-interactivity/SKILL.md b/packages/skills/skills/remotion-interactivity/SKILL.mdindex 4b33125f52..fbedd9a2ac 100644--- a/packages/skills/skills/remotion-interactivity/SKILL.md+++ b/packages/skills/skills/remotion-interactivity/SKILL.md@@ -13,6 +13,11 @@ Use the canonical interactivity best-practices page instead:To make an element or custom component interactive, use:[Make a component interactive](https://www.remotion.dev/docs/studio/make-component-interactive.md)+## Avoid object spreads++Do not use object spreads for interactive props. Write the values inline so the+Studio can detect and edit them.+## Video editingIf a Remotion component mainly consists of video and audio clips, see [Video editing](../remotion-markup/video-editing.md) for best practices on how to structure Remotion markup so the clips are interactively editable in the timeline.diff --git a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.tsindex 98e0760d17..5a566738f0 100644--- a/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts+++ b/packages/studio-server/src/preview-server/routes/can-update-sequence-props.ts@@ -1021,13 +1021,22 @@ const getNestedPropStatus = ({return computedStatus();}- const relevantProperties = objExpr.properties.filter(- (p) =>- p.type === 'ObjectProperty' &&- (getObjectPropertyName(p) === childKey ||- getObjectPropertyName(p) === cssShorthand?.shorthand),- ) as ObjectProperty[];- const prop = relevantProperties.at(-1);+ let prop: ObjectProperty | undefined;+ for (let index = objExpr.properties.length - 1; index >= 0; index--) {+ const candidate = objExpr.properties[index];+ if (candidate.type === 'SpreadElement') {+ return computedStatus();+ }++ if (+ candidate.type === 'ObjectProperty' &&+ (getObjectPropertyName(candidate) === childKey ||+ getObjectPropertyName(candidate) === cssShorthand?.shorthand)+ ) {+ prop = candidate;+ break;+ }+ }if (prop &&diff --git a/packages/studio-server/src/test/compute-sequence-props-status.test.ts b/packages/studio-server/src/test/compute-sequence-props-status.test.tsindex d70626e296..ad555cf467 100644--- a/packages/studio-server/src/test/compute-sequence-props-status.test.ts+++ b/packages/studio-server/src/test/compute-sequence-props-status.test.ts@@ -752,6 +752,37 @@ test('computeSequencePropsStatus should flag computed nested props', () => {});});+test('computeSequencePropsStatus should preserve nested props from object spreads', () => {+ const input = `import {Interactive} from 'remotion';++const sharedStyle = {color: 'white'};++export const Example = () => {+ return (+ <>+ <Interactive.Div style={{...sharedStyle, fontSize: 40}} />+ <Interactive.Div style={{color: 'red', ...sharedStyle}} />+ <Interactive.Div style={{...sharedStyle, color: 'red'}} />+ </>+ );+};+`;+ const getColorStatus = (line: number) => {+ return computeSequencePropsStatusFromContent({+ fileContents: input,+ nodePath: getNodePathFromContent(input, line),+ componentIdentity: null,+ keys: ['style.color'],+ effects: [],+ videoConfigValues: null,+ }).props['style.color'];+ };++ expect(getColorStatus(8)).toEqual({status: 'computed'});+ expect(getColorStatus(9)).toEqual({status: 'computed'});+ expect(getColorStatus(10)).toEqual({status: 'static', codeValue: 'red'});+});+test('computeSequencePropsStatus should flag computed when parent is not an object', () => {const filePath = path.join(__dirname, 'snapshots', 'nested-props.tsx');const result = computeSequencePropsStatus({