Skip to content

🎥 Make videos programmatically with React

`@remotion/studio-server`: Do not drop props passed to interactive components via JSX spread

JonnyBurgerddfc8dc8ce9e
diff --git a/packages/studio-codemods/src/sequence-props.ts b/packages/studio-codemods/src/sequence-props.ts
index e8e22471c2..1a72cd8342 100644
--- a/packages/studio-codemods/src/sequence-props.ts
+++ b/packages/studio-codemods/src/sequence-props.ts
@@ -1219,6 +1219,21 @@ const computeSequenceOnlyPropsRecord = ({
assetKeys: string[];
videoConfigValues: VideoConfigIdentifierValues;
}): Record<string, CanUpdatePropStatus> => {
+ // Props may arrive through a JSX spread attribute ({...props}), which the
+ // parser cannot resolve. Since the spread may set or override any prop,
+ // treat all of them as computed so the runtime values pass through
+ // untouched and Visual Mode does not offer to edit them.
+ if (
+ jsxElement.attributes.some((attr) => attr.type === 'JSXSpreadAttribute')
+ ) {
+ const computedProps: Record<string, CanUpdatePropStatus> = {};
+ for (const key of keys) {
+ computedProps[key] = computedStatus();
+ }
+
+ return computedProps;
+ }
+
const allProps = getPropsStatus(
jsxElement,
ast,
diff --git a/packages/studio-codemods/src/test/sequence-props-spread.test.ts b/packages/studio-codemods/src/test/sequence-props-spread.test.ts
new file mode 100644
index 0000000000..f8f8adfca7
--- /dev/null
+++ b/packages/studio-codemods/src/test/sequence-props-spread.test.ts
@@ -0,0 +1,51 @@
+import {expect, test} from 'bun:test';
+import {computeSequencePropsSubscriptionFromContent} from '../sequence-props';
+
+// https://github.com/remotion-dev/remotion/issues/10717
+// Props passed via a JSX spread are invisible to the parser. Reporting them as
+// static(undefined) made the Studio delete the runtime values of `from` /
+// `durationInFrames`, mounting every <Sequence> at every frame.
+test('treats all props as computed if a spread attribute is present', () => {
+ const input = `import {Sequence} from 'remotion';
+
+export const Example = ({timing}: {timing: {from: number; durationInFrames: number}}) => {
+ return (
+ <Sequence {...timing} name="Scene" style={{opacity: 0.5}}>
+ <div />
+ </Sequence>
+ );
+};
+`;
+ const result = computeSequencePropsSubscriptionFromContent({
+ fileContents: input,
+ absolutePath: '/project/src/Example.tsx',
+ line: 5,
+ preferredNodePath: null,
+ componentIdentity: 'dev.remotion.remotion.Sequence',
+ keys: ['from', 'durationInFrames', 'name', 'style.opacity'],
+ effects: [],
+ videoConfigValues: {
+ durationInFrames: 120,
+ fps: 30,
+ height: 1080,
+ width: 1920,
+ },
+ });
+
+ expect(result.success).toBe(true);
+ if (!result.success) {
+ throw new Error('Expected the subscription to succeed');
+ }
+
+ expect(result.status.canUpdate).toBe(true);
+ if (!result.status.canUpdate) {
+ throw new Error('Expected canUpdate to be true');
+ }
+
+ expect(result.status.props).toEqual({
+ from: {status: 'computed'},
+ durationInFrames: {status: 'computed'},
+ name: {status: 'computed'},
+ 'style.opacity': {status: 'computed'},
+ });
+});
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.ts
index 5858ec7d3e..1c0add0184 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
@@ -1759,6 +1759,21 @@ const computeSequenceOnlyPropsRecord = ({
assetKeys: string[];
videoConfigValues: VideoConfigIdentifierValues;
}): Record<string, CanUpdatePropStatus> => {
+ // Props may arrive through a JSX spread attribute ({...props}), which the
+ // parser cannot resolve. Since the spread may set or override any prop,
+ // treat all of them as computed so the runtime values pass through
+ // untouched and Visual Mode does not offer to edit them.
+ if (
+ jsxElement.attributes.some((attr) => attr.type === 'JSXSpreadAttribute')
+ ) {
+ const computedProps: Record<string, CanUpdatePropStatus> = {};
+ for (const key of keys) {
+ computedProps[key] = computedStatus();
+ }
+
+ return computedProps;
+ }
+
const allProps = getPropsStatus(
jsxElement,
ast,
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.ts
index 6149278b8a..40753c01b4 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
@@ -218,6 +218,38 @@ export const Example = () => {
});
});
+// https://github.com/remotion-dev/remotion/issues/10717
+// Props passed via a JSX spread are invisible to the parser. Reporting them as
+// static(undefined) made the Studio delete the runtime values of `from` /
+// `durationInFrames`, mounting every <Sequence> at every frame.
+test('computeSequencePropsStatus should treat all props as computed if a spread attribute is present', () => {
+ const input = `import {Sequence} from 'remotion';
+
+export const Example = ({timing}: {timing: {from: number; durationInFrames: number}}) => {
+ return (
+ <Sequence {...timing} name="Scene" style={{opacity: 0.5}}>
+ <div />
+ </Sequence>
+ );
+};
+`;
+ const result = computeSequencePropsStatusFromContent({
+ fileContents: input,
+ nodePath: getNodePathFromContent(input, 5),
+ componentIdentity: null,
+ keys: ['from', 'durationInFrames', 'name', 'style.opacity'],
+ effects: [],
+ videoConfigValues: null,
+ });
+
+ expect(result.props).toEqual({
+ from: {status: 'computed'},
+ durationInFrames: {status: 'computed'},
+ name: {status: 'computed'},
+ 'style.opacity': {status: 'computed'},
+ });
+});
+
test('computeSequencePropsStatus should parse video config numeric expressions', () => {
const input = `import React from 'react';
import {Sequence, interpolate, useCurrentFrame, useVideoConfig} from 'remotion';