Skip to content

πŸŽ₯ Make videos programmatically with React

seems fine

Jonny Burgerca2287501eac
diff --git a/packages/studio-server/src/codemods/update-sequence-props.ts b/packages/studio-server/src/codemods/update-sequence-props.ts
index d07a7cad4f..0f3556fb90 100644
--- a/packages/studio-server/src/codemods/update-sequence-props.ts
+++ b/packages/studio-server/src/codemods/update-sequence-props.ts
@@ -1,5 +1,6 @@
-import type {EnumPath} from '@remotion/studio-shared';
+import type {EnumPath, SequenceNodePath} from '@remotion/studio-shared';
import * as recast from 'recast';
+import {findJsxElementAtNodePath} from '../preview-server/routes/can-update-sequence-props';
import {parseAst, serializeAst} from './parse-ast';
import {parseValueExpression, updateNestedProp} from './update-nested-prop';
@@ -7,21 +8,24 @@ const b = recast.types.builders;
export const updateSequenceProps = async ({
input,
- targetLine,
+ nodePath,
key,
value,
enumPaths,
defaultValue,
}: {
input: string;
- targetLine: number;
+ nodePath: SequenceNodePath;
key: string;
value: unknown;
enumPaths: EnumPath[];
defaultValue: unknown | null;
-}): Promise<{output: string; oldValueString: string; formatted: boolean}> => {
+}): Promise<{
+ output: string;
+ oldValueString: string;
+ formatted: boolean;
+}> => {
const ast = parseAst(input);
- let found = false;
let oldValueString = '';
const isDefault =
@@ -33,68 +37,62 @@ export const updateSequenceProps = async ({
const parentKey = isNested ? key.slice(0, dotIndex) : key;
const childKey = isNested ? key.slice(dotIndex + 1) : '';
- recast.types.visit(ast, {
- visitJSXOpeningElement(path) {
- const {node} = path;
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const node = findJsxElementAtNodePath(ast, nodePath) as any;
+ if (!node) {
+ throw new Error(
+ 'Could not find a JSX element at the specified line to update',
+ );
+ }
- if (!node.loc || node.loc.start.line !== targetLine) {
- return this.traverse(path);
+ if (isNested) {
+ oldValueString = updateNestedProp({
+ node,
+ parentKey,
+ childKey,
+ value,
+ enumPaths,
+ defaultValue,
+ isDefault,
+ });
+ } else {
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ const attrIndex = node.attributes?.findIndex((a: any) => {
+ if (a.type === 'JSXSpreadAttribute') {
+ return false;
}
- if (isNested) {
- oldValueString = updateNestedProp({
- node,
- parentKey,
- childKey,
- value,
- enumPaths,
- defaultValue,
- isDefault,
- });
- found = true;
- return this.traverse(path);
+ if (a.name.type === 'JSXNamespacedName') {
+ return false;
}
- const attrIndex = node.attributes?.findIndex((a) => {
- if (a.type === 'JSXSpreadAttribute') {
- return false;
- }
-
- if (a.name.type === 'JSXNamespacedName') {
- return false;
- }
-
- return a.name.name === key;
- });
-
- const attr =
- attrIndex !== undefined && attrIndex !== -1
- ? node.attributes?.[attrIndex]
- : undefined;
-
- if (attr && attr.type !== 'JSXSpreadAttribute' && attr.value) {
- const printed = recast.print(attr.value).code;
- // Strip JSX expression container braces, e.g. "{30}" -> "30"
- oldValueString =
- printed.startsWith('{') && printed.endsWith('}')
- ? printed.slice(1, -1)
- : printed;
- } else if (attr && attr.type !== 'JSXSpreadAttribute' && !attr.value) {
- // JSX shorthand like `loop` (no value) is implicitly `true`
- oldValueString = 'true';
- } else if (!attr && defaultValue !== null) {
- oldValueString = JSON.stringify(defaultValue);
+ return a.name.name === key;
+ });
+
+ const attr =
+ attrIndex !== undefined && attrIndex !== -1
+ ? node.attributes?.[attrIndex]
+ : undefined;
+
+ if (attr && attr.type !== 'JSXSpreadAttribute' && attr.value) {
+ const printed = recast.print(attr.value).code;
+ // Strip JSX expression container braces, e.g. "{30}" -> "30"
+ oldValueString =
+ printed.startsWith('{') && printed.endsWith('}')
+ ? printed.slice(1, -1)
+ : printed;
+ } else if (attr && attr.type !== 'JSXSpreadAttribute' && !attr.value) {
+ // JSX shorthand like `loop` (no value) is implicitly `true`
+ oldValueString = 'true';
+ } else if (!attr && defaultValue !== null) {
+ oldValueString = JSON.stringify(defaultValue);
+ }
+
+ if (isDefault) {
+ if (attr && attr.type !== 'JSXSpreadAttribute' && node.attributes) {
+ node.attributes.splice(attrIndex!, 1);
}
-
- if (isDefault) {
- if (attr && attr.type !== 'JSXSpreadAttribute' && node.attributes) {
- node.attributes.splice(attrIndex!, 1);
- }
-
- found = true;
- return this.traverse(path);
- }
-
+ } else {
const parsed = parseValueExpression(value, enumPaths);
const newValue = value === true ? null : b.jsxExpressionContainer(parsed);
@@ -110,17 +108,7 @@ export const updateSequenceProps = async ({
} else {
attr.value = newValue;
}
-
- found = true;
-
- return this.traverse(path);
- },
- });
-
- if (!found) {
- throw new Error(
- 'Could not find a JSX element at the specified line to update',
- );
+ }
}
const finalFile = serializeAst(ast);
@@ -132,19 +120,31 @@ export const updateSequenceProps = async ({
try {
prettier = await import('prettier');
} catch {
- return {output: finalFile, oldValueString, formatted: false};
+ return {
+ output: finalFile,
+ oldValueString,
+ formatted: false,
+ };
}
const {format, resolveConfig, resolveConfigFile} = prettier as PrettierType;
const configFilePath = await resolveConfigFile();
if (!configFilePath) {
- return {output: finalFile, oldValueString, formatted: false};
+ return {
+ output: finalFile,
+ oldValueString,
+ formatted: false,
+ };
}
const prettierConfig = await resolveConfig(configFilePath);
if (!prettierConfig) {
- return {output: finalFile, oldValueString, formatted: false};
+ return {
+ output: finalFile,
+ oldValueString,
+ formatted: false,
+ };
}
const prettified = await format(finalFile, {
@@ -153,5 +153,10 @@ export const updateSequenceProps = async ({
plugins: [],
endOfLine: 'auto',
});
- return {output: prettified, oldValueString, formatted: true};
+
+ return {
+ output: prettified,
+ oldValueString,
+ formatted: true,
+ };
};
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 d7a895ea45..f3809c47e9 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
@@ -9,7 +9,10 @@ import type {
ObjectProperty,
UnaryExpression,
} from '@babel/types';
-import type {CanUpdateSequencePropsResponse} from '@remotion/studio-shared';
+import type {
+ CanUpdateSequencePropsResponse,
+ SequenceNodePath,
+} from '@remotion/studio-shared';
import * as recast from 'recast';
import type {CanUpdateSequencePropStatus} from 'remotion';
import {parseAst} from '../../codemods/parse-ast';
@@ -158,25 +161,64 @@ const getPropsStatus = (
return props;
};
-const findJsxElementAtLine = (
+const getNodePathForRecastPath = (
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ recastPath: any,
+): SequenceNodePath => {
+ const segments: Array<string | number> = [];
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
+ let current: any = recastPath;
+ while (current && current.parentPath) {
+ segments.unshift(current.name);
+ current = current.parentPath;
+ }
+
+ // Recast paths start with "root" which doesn't correspond to a real AST property
+ if (segments.length > 0 && segments[0] === 'root') {
+ return segments.slice(1);
+ }
+
+ return segments;
+};
+
+export const findJsxElementAtNodePath = (
ast: File,
- targetLine: number,
+ nodePath: SequenceNodePath,
): JSXOpeningElement | null => {
- let found: JSXOpeningElement | null = null;
+ let current = new recast.types.NodePath(ast);
+ for (const segment of nodePath) {
+ current = current.get(segment);
+ if (current.value === null || current.value === undefined) {
+ return null;
+ }
+ }
+
+ if (recast.types.namedTypes.JSXOpeningElement.check(current.value)) {
+ return current.value as unknown as JSXOpeningElement;
+ }
+
+ return null;
+};
+
+export const lineColumnToNodePath = (
+ ast: File,
+ targetLine: number,
+): SequenceNodePath | null => {
+ let foundPath: SequenceNodePath | null = null;
recast.types.visit(ast, {
- visitJSXOpeningElement(nodePath) {
- const {node} = nodePath;
+ visitJSXOpeningElement(p) {
+ const {node} = p;
if (node.loc && node.loc.start.line === targetLine) {
- found = node as unknown as JSXOpeningElement;
+ foundPath = getNodePathForRecastPath(p);
return false;
}
- return this.traverse(nodePath);
+ return this.traverse(p);
},
});
- return found;
+ return foundPath;
};
const getNestedPropStatus = (
@@ -232,12 +274,12 @@ const getNestedPropStatus = (
export const computeSequencePropsStatus = ({
fileName,
- line,
+ nodePath,
keys,
remotionRoot,
}: {
fileName: string;
- line: number;
+ nodePath: SequenceNodePath;
keys: string[];
remotionRoot: string;
}): CanUpdateSequencePropsResponse => {
@@ -251,7 +293,7 @@ export const computeSequencePropsStatus = ({
const fileContents = readFileSync(absolutePath, 'utf-8');
const ast = parseAst(fileContents);
- const jsxElement = findJsxElementAtLine(ast, line);
+ const jsxElement = findJsxElementAtNodePath(ast, nodePath);
if (!jsxElement) {
throw new Error('Could not find a JSX element at the specified location');
@@ -277,6 +319,7 @@ export const computeSequencePropsStatus = ({
return {
canUpdate: true as const,
props: filteredProps,
+ nodePath,
};
} catch (err) {
return {
@@ -285,3 +328,43 @@ export const computeSequencePropsStatus = ({
};
}
};
+
+export const computeSequencePropsStatusByLine = ({
+ fileName,
+ line,
+ keys,
+ remotionRoot,
+}: {
+ fileName: string;
+ line: number;
+ keys: string[];
+ remotionRoot: string;
+}): CanUpdateSequencePropsResponse => {
+ try {
+ const absolutePath = path.resolve(remotionRoot, fileName);
+ const fileRelativeToRoot = path.relative(remotionRoot, absolutePath);
+ if (fileRelativeToRoot.startsWith('..')) {
+ throw new Error('Cannot read a file outside the project');
+ }
+
+ const fileContents = readFileSync(absolutePath, 'utf-8');
+ const ast = parseAst(fileContents);
+
+ const resolvedNodePath = lineColumnToNodePath(ast, line);
+ if (!resolvedNodePath) {
+ throw new Error('Could not find a JSX element at the specified location');
+ }
+
+ return computeSequencePropsStatus({
+ fileName,
+ nodePath: resolvedNodePath,
+ keys,
+ remotionRoot,
+ });
+ } catch (err) {
+ return {
+ canUpdate: false as const,
+ reason: (err as Error).message,
+ };
+ }
+};
diff --git a/packages/studio-server/src/preview-server/routes/save-sequence-props.ts b/packages/studio-server/src/preview-server/routes/save-sequence-props.ts
index 939f2f0dd8..0268e47a5a 100644
--- a/packages/studio-server/src/preview-server/routes/save-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/save-sequence-props.ts
@@ -16,7 +16,7 @@ export const saveSequencePropsHandler: ApiHandler<
SaveSequencePropsRequest,
SaveSequencePropsResponse
> = async ({
- input: {fileName, line, column, key, value, enumPaths, defaultValue},
+ input: {fileName, nodePath, key, value, enumPaths, defaultValue},
remotionRoot,
logLevel,
}) => {
@@ -31,7 +31,7 @@ export const saveSequencePropsHandler: ApiHandler<
const {output, oldValueString, formatted} = await updateSequenceProps({
input: fileContents,
- targetLine: line,
+ nodePath,
key,
value: JSON.parse(value),
enumPaths,
@@ -42,7 +42,7 @@ export const saveSequencePropsHandler: ApiHandler<
writeFileSync(absolutePath, output);
const newValueString = JSON.stringify(JSON.parse(value));
- const locationLabel = `${fileRelativeToRoot}:${line}:${column}`;
+ const locationLabel = fileRelativeToRoot;
const fileLink = makeHyperlink({
url: `file://${absolutePath}`,
text: locationLabel,
diff --git a/packages/studio-server/src/preview-server/routes/subscribe-to-sequence-props.ts b/packages/studio-server/src/preview-server/routes/subscribe-to-sequence-props.ts
index 5646d4361d..9369659d0f 100644
--- a/packages/studio-server/src/preview-server/routes/subscribe-to-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/subscribe-to-sequence-props.ts
@@ -8,11 +8,10 @@ import {subscribeToSequencePropsWatchers} from '../sequence-props-watchers';
export const subscribeToSequenceProps: ApiHandler<
SubscribeToSequencePropsRequest,
SubscribeToSequencePropsResponse
-> = ({input: {fileName, line, column, keys, clientId}, remotionRoot}) => {
+> = ({input: {fileName, line, keys, clientId}, remotionRoot}) => {
const result = subscribeToSequencePropsWatchers({
fileName,
line,
- column,
keys,
remotionRoot,
clientId,
diff --git a/packages/studio-server/src/preview-server/routes/unsubscribe-from-sequence-props.ts b/packages/studio-server/src/preview-server/routes/unsubscribe-from-sequence-props.ts
index 8243b67872..48b6540f67 100644
--- a/packages/studio-server/src/preview-server/routes/unsubscribe-from-sequence-props.ts
+++ b/packages/studio-server/src/preview-server/routes/unsubscribe-from-sequence-props.ts
@@ -5,11 +5,10 @@ import {unsubscribeFromSequencePropsWatchers} from '../sequence-props-watchers';
export const unsubscribeFromSequenceProps: ApiHandler<
UnsubscribeFromSequencePropsRequest,
undefined
-> = ({input: {fileName, line, column, clientId}, remotionRoot}) => {
+> = ({input: {fileName, nodePath, clientId}, remotionRoot}) => {
unsubscribeFromSequencePropsWatchers({
fileName,
- line,
- column,
+ nodePath,
remotionRoot,
clientId,
});
diff --git a/packages/studio-server/src/preview-server/sequence-props-watchers.ts b/packages/studio-server/src/preview-server/sequence-props-watchers.ts
index 6657b21c72..6596a9d3bc 100644
--- a/packages/studio-server/src/preview-server/sequence-props-watchers.ts
+++ b/packages/studio-server/src/preview-server/sequence-props-watchers.ts
@@ -1,8 +1,14 @@
import path from 'node:path';
-import type {CanUpdateSequencePropsResponse} from '@remotion/studio-shared';
+import type {
+ CanUpdateSequencePropsResponse,
+ SequenceNodePath,
+} from '@remotion/studio-shared';
import {installFileWatcher} from '../file-watcher';
import {waitForLiveEventsListener} from './live-events';
-import {computeSequencePropsStatus} from './routes/can-update-sequence-props';
+import {
+ computeSequencePropsStatus,
+ computeSequencePropsStatusByLine,
+} from './routes/can-update-sequence-props';
type WatcherInfo = {
unwatch: () => void;
@@ -12,46 +18,49 @@ const sequencePropsWatchers: Record<string, Record<string, WatcherInfo>> = {};
const makeWatcherKey = ({
absolutePath,
- line,
- column,
+ nodePath,
}: {
absolutePath: string;
- line: number;
- column: number;
+ nodePath: SequenceNodePath;
}): string => {
- return `${absolutePath}:${line}:${column}`;
+ return `${absolutePath}:${JSON.stringify(nodePath)}`;
};
export const subscribeToSequencePropsWatchers = ({
fileName,
line,
- column,
keys,
remotionRoot,
clientId,
}: {
fileName: string;
line: number;
- column: number;
keys: string[];
remotionRoot: string;
clientId: string;
}): CanUpdateSequencePropsResponse => {
const absolutePath = path.resolve(remotionRoot, fileName);
- const watcherKey = makeWatcherKey({absolutePath, line, column});
-
- // Unwatch any existing watcher for the same key
- if (sequencePropsWatchers[clientId]?.[watcherKey]) {
- sequencePropsWatchers[clientId][watcherKey].unwatch();
- }
- const initialResult = computeSequencePropsStatus({
+ // Initial lookup by line+column to resolve the nodePath
+ const initialResult = computeSequencePropsStatusByLine({
fileName,
line,
keys,
remotionRoot,
});
+ if (!initialResult.canUpdate) {
+ return initialResult;
+ }
+
+ const {nodePath} = initialResult;
+ const watcherKey = makeWatcherKey({absolutePath, nodePath});
+
+ // Unwatch any existing watcher for the same key
+ if (sequencePropsWatchers[clientId]?.[watcherKey]) {
+ sequencePropsWatchers[clientId][watcherKey].unwatch();
+ }
+
const {unwatch} = installFileWatcher({
file: absolutePath,
onChange: (type) => {
@@ -61,7 +70,7 @@ export const subscribeToSequencePropsWatchers = ({
const result = computeSequencePropsStatus({
fileName,
- line,
+ nodePath,
keys,
remotionRoot,
});
@@ -70,8 +79,7 @@ export const subscribeToSequencePropsWatchers = ({
listener.sendEventToClient({
type: 'sequence-props-updated',
fileName,
- line,
- column,
+ nodePath,
result,
});
});
@@ -89,25 +97,29 @@ export const subscribeToSequencePropsWatchers = ({
export const unsubscribeFromSequencePropsWatchers = ({
fileName,
- line,
- column,
+ nodePath,
remotionRoot,
clientId,
}: {
fileName: string;
- line: number;
- column: number;
+ nodePath: SequenceNodePath;
remotionRoot: string;
clientId: string;
}) => {
const absolutePath = path.resolve(remotionRoot, fileName);
- const watcherKey = makeWatcherKey({absolutePath, line, column});
-
- if (!sequencePropsWatchers[clientId]) {
+ const watcherKey = makeWatcherKey({absolutePath, nodePath});
+
+ if (
+ !sequencePropsWatchers[clientId] ||
+ !sequencePropsWatchers[clientId][watcherKey]
+ ) {
+ console.warn(
+ `Unexpected: unsubscribe for sequence props watcher that does not exist (clientId=${clientId}, key=${watcherKey})`,
+ );
return;
}
- sequencePropsWatchers[clientId][watcherKey]?.unwatch();
+ sequencePropsWatchers[clientId][watcherKey].unwatch();
delete sequencePropsWatchers[clientId][watcherKey];
};
diff --git a/packages/studio-server/src/test/code-shift.test.ts b/packages/studio-server/src/test/code-shift.test.ts
new file mode 100644
index 0000000000..955f2fb336
--- /dev/null
+++ b/packages/studio-server/src/test/code-shift.test.ts
@@ -0,0 +1,41 @@
+import {expect, test} from 'bun:test';
+import {updateSequenceProps} from '../codemods/update-sequence-props';
+import {lineColumnToNodePath} from './test-utils';
+
+const componentInput = `import {Video} from '@remotion/media';
+
+const src = 'https://remotion.media/video.mp4';
+
+export const Component = () => {
+ return <Video src={src} />;
+};
+`;
+
+test('Should add style.scale to a Video component and format with prettier', async () => {
+ const {output, oldValueString, formatted} = await updateSequenceProps({
+ input: componentInput,
+ nodePath: lineColumnToNodePath(componentInput, 6),
+ key: 'style.scale',
+ value: 2,
+ enumPaths: [],
+ defaultValue: null,
+ });
+
+ expect(oldValueString).toBe('');
+ expect(formatted).toBe(true);
+ expect(output).toBe(`import {Video} from '@remotion/media';
+
+const src = 'https://remotion.media/video.mp4';
+
+export const Component = () => {
+\treturn (
+\t\t<Video
+\t\t\tsrc={src}
+\t\t\tstyle={{
+\t\t\t\tscale: 2,
+\t\t\t}}
+\t\t/>
+\t);
+};
+`);
+});
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
new file mode 100644
index 0000000000..00b1a8fdcc
--- /dev/null
+++ b/packages/studio-server/src/test/compute-sequence-props-status.test.ts
@@ -0,0 +1,146 @@
+import {expect, test} from 'bun:test';
+import {readFileSync} from 'node:fs';
+import path from 'node:path';
+import {parseAst} from '../codemods/parse-ast';
+import {
+ computeSequencePropsStatus,
+ lineColumnToNodePath,
+} from '../preview-server/routes/can-update-sequence-props';
+
+const getNodePath = (filePath: string, line: number) => {
+ const content = readFileSync(filePath, 'utf-8');
+ const ast = parseAst(content);
+ const result = lineColumnToNodePath(ast, line);
+ if (!result) {
+ throw new Error(`No JSX element found at line ${line} in ${filePath}`);
+ }
+
+ return result;
+};
+
+test('canUpdateSequenceProps should flag computed props', () => {
+ const filePath = path.join(__dirname, 'snapshots', 'light-leak-computed.txt');
+ const result = computeSequencePropsStatus({
+ fileName: filePath,
+ nodePath: getNodePath(filePath, 8),
+ keys: ['durationInFrames', 'seed', 'hueShift', 'nonExistentProp'],
+ remotionRoot: '/',
+ });
+
+ expect(result.canUpdate).toBe(true);
+ if (!result.canUpdate) {
+ throw new Error('Expected canUpdate to be true');
+ }
+
+ expect(result.props.durationInFrames).toEqual({
+ canUpdate: true,
+ codeValue: 60,
+ });
+ expect(result.props.hueShift).toEqual({canUpdate: true, codeValue: 30});
+ expect(result.props.seed).toEqual({canUpdate: false, reason: 'computed'});
+ expect(result.props.nonExistentProp).toEqual({
+ canUpdate: true,
+ codeValue: undefined,
+ });
+});
+
+test('computeSequencePropsStatus should detect static nested props', () => {
+ const filePath = path.join(__dirname, 'snapshots', 'nested-props.txt');
+ const result = computeSequencePropsStatus({
+ fileName: filePath,
+ nodePath: getNodePath(filePath, 7),
+ keys: ['style.opacity', 'style.scale'],
+ remotionRoot: '/',
+ });
+
+ expect(result.canUpdate).toBe(true);
+ if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
+
+ expect(result.props['style.opacity']).toEqual({
+ canUpdate: true,
+ codeValue: 0.5,
+ });
+ expect(result.props['style.scale']).toEqual({
+ canUpdate: true,
+ codeValue: 2,
+ });
+});
+
+test('computeSequencePropsStatus should flag computed nested props', () => {
+ const filePath = path.join(__dirname, 'snapshots', 'nested-props.txt');
+ const result = computeSequencePropsStatus({
+ fileName: filePath,
+ nodePath: getNodePath(filePath, 8),
+ keys: ['style.opacity', 'style.scale'],
+ remotionRoot: '/',
+ });
+
+ expect(result.canUpdate).toBe(true);
+ if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
+
+ // opacity uses getOpacity() β€” computed
+ expect(result.props['style.opacity']).toEqual({
+ canUpdate: false,
+ reason: 'computed',
+ });
+ // scale is static
+ expect(result.props['style.scale']).toEqual({
+ canUpdate: true,
+ codeValue: 2,
+ });
+});
+
+test('computeSequencePropsStatus should flag computed when parent is not an object', () => {
+ const filePath = path.join(__dirname, 'snapshots', 'nested-props.txt');
+ const result = computeSequencePropsStatus({
+ fileName: filePath,
+ nodePath: getNodePath(filePath, 9),
+ keys: ['style.opacity'],
+ remotionRoot: '/',
+ });
+
+ expect(result.canUpdate).toBe(true);
+ if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
+
+ // style={dynamicStyles} β€” entire parent is computed
+ expect(result.props['style.opacity']).toEqual({
+ canUpdate: false,
+ reason: 'computed',
+ });
+});
+
+test('computeSequencePropsStatus should report unset nested props as undefined', () => {
+ const filePath = path.join(__dirname, 'snapshots', 'nested-props.txt');
+ const result = computeSequencePropsStatus({
+ fileName: filePath,
+ nodePath: getNodePath(filePath, 7),
+ keys: ['style.rotate'],
+ remotionRoot: '/',
+ });
+
+ expect(result.canUpdate).toBe(true);
+ if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
+
+ expect(result.props['style.rotate']).toEqual({
+ canUpdate: true,
+ codeValue: undefined,
+ });
+});
+
+test('computeSequencePropsStatus should report unset when parent attribute missing', () => {
+ const filePath = path.join(__dirname, 'snapshots', 'nested-props.txt');
+ const result = computeSequencePropsStatus({
+ fileName: filePath,
+ nodePath: getNodePath(filePath, 10),
+ keys: ['style.opacity'],
+ remotionRoot: '/',
+ });
+
+ expect(result.canUpdate).toBe(true);
+ if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
+
+ expect(result.props['style.opacity']).toEqual({
+ canUpdate: true,
+ codeValue: undefined,
+ });
+});
diff --git a/packages/studio-server/src/test/extract-static-value.test.ts b/packages/studio-server/src/test/extract-static-value.test.ts
new file mode 100644
index 0000000000..64f2f74baa
--- /dev/null
+++ b/packages/studio-server/src/test/extract-static-value.test.ts
@@ -0,0 +1,19 @@
+import {expect, test} from 'bun:test';
+import {extractStaticValue} from '../preview-server/routes/can-update-sequence-props';
+import {parseExpression} from './test-utils';
+
+test('extractStaticValue should extract values from AST nodes', () => {
+ expect(extractStaticValue(parseExpression('42'))).toBe(42);
+ expect(extractStaticValue(parseExpression('"hello"'))).toBe('hello');
+ expect(extractStaticValue(parseExpression('true'))).toBe(true);
+ expect(extractStaticValue(parseExpression('false'))).toBe(false);
+ expect(extractStaticValue(parseExpression('null'))).toBe(null);
+ expect(extractStaticValue(parseExpression('-1'))).toBe(-1);
+ expect(extractStaticValue(parseExpression('[1, 2, 3]'))).toEqual([1, 2, 3]);
+ expect(extractStaticValue(parseExpression('{a: 1, b: "c"}'))).toEqual({
+ a: 1,
+ b: 'c',
+ });
+ expect(extractStaticValue(parseExpression('[]'))).toEqual([]);
+ expect(extractStaticValue(parseExpression('{}'))).toEqual({});
+});
diff --git a/packages/studio-server/src/test/is-static-value.test.ts b/packages/studio-server/src/test/is-static-value.test.ts
new file mode 100644
index 0000000000..d8e79e8394
--- /dev/null
+++ b/packages/studio-server/src/test/is-static-value.test.ts
@@ -0,0 +1,26 @@
+import {expect, test} from 'bun:test';
+import {isStaticValue} from '../preview-server/routes/can-update-sequence-props';
+import {parseExpression} from './test-utils';
+
+test('Static values should be detected as static', () => {
+ expect(isStaticValue(parseExpression('42'))).toBe(true);
+ expect(isStaticValue(parseExpression('"hello"'))).toBe(true);
+ expect(isStaticValue(parseExpression('true'))).toBe(true);
+ expect(isStaticValue(parseExpression('false'))).toBe(true);
+ expect(isStaticValue(parseExpression('null'))).toBe(true);
+ expect(isStaticValue(parseExpression('-1'))).toBe(true);
+ expect(isStaticValue(parseExpression('[1, 2, 3]'))).toBe(true);
+ expect(isStaticValue(parseExpression('{a: 1, b: "c"}'))).toBe(true);
+ expect(isStaticValue(parseExpression('[]'))).toBe(true);
+ expect(isStaticValue(parseExpression('{}'))).toBe(true);
+});
+
+test('Computed values should be detected as computed', () => {
+ expect(isStaticValue(parseExpression('1 + 2'))).toBe(false);
+ expect(isStaticValue(parseExpression('Math.random()'))).toBe(false);
+ expect(isStaticValue(parseExpression('someVar'))).toBe(false);
+ expect(isStaticValue(parseExpression('foo()'))).toBe(false);
+ expect(isStaticValue(parseExpression('a ? b : c'))).toBe(false);
+ // eslint-disable-next-line no-template-curly-in-string
+ expect(isStaticValue(parseExpression('`template ${"x"}`'))).toBe(false);
+});
diff --git a/packages/studio-server/src/test/test-utils.ts b/packages/studio-server/src/test/test-utils.ts
new file mode 100644
index 0000000000..3245f3d804
--- /dev/null
+++ b/packages/studio-server/src/test/test-utils.ts
@@ -0,0 +1,30 @@
+import type {Expression} from '@babel/types';
+import type {SequenceNodePath} from '@remotion/studio-shared';
+import {parseAst} from '../codemods/parse-ast';
+import {lineColumnToNodePath as _lineColumnToNodePath} from '../preview-server/routes/can-update-sequence-props';
+
+export const parseExpression = (code: string): Expression => {
+ const ast = parseAst(`a = ${code}`);
+ const stmt = ast.program.body[0];
+ if (
+ stmt.type !== 'ExpressionStatement' ||
+ stmt.expression.type !== 'AssignmentExpression'
+ ) {
+ throw new Error('Unexpected AST');
+ }
+
+ return stmt.expression.right;
+};
+
+export const lineColumnToNodePath = (
+ input: string,
+ line: number,
+): SequenceNodePath => {
+ const ast = parseAst(input);
+ const result = _lineColumnToNodePath(ast, line);
+ if (!result) {
+ throw new Error(`No JSX element found at line ${line}`);
+ }
+
+ return result;
+};
diff --git a/packages/studio-server/src/test/update-nested-sequence-props.test.ts b/packages/studio-server/src/test/update-nested-sequence-props.test.ts
new file mode 100644
index 0000000000..632b359174
--- /dev/null
+++ b/packages/studio-server/src/test/update-nested-sequence-props.test.ts
@@ -0,0 +1,114 @@
+import {expect, test} from 'bun:test';
+import {updateSequenceProps} from '../codemods/update-sequence-props';
+import {lineColumnToNodePath} from './test-utils';
+
+const nestedInput = `import React from 'react';
+import {AbsoluteFill} from 'remotion';
+
+export const Example: React.FC = () => {
+ return (
+ <AbsoluteFill>
+ <div style={{opacity: 0.5, scale: 2}} />
+ <div />
+ </AbsoluteFill>
+ );
+};
+`;
+
+test('updateSequenceProps should update a nested style property', async () => {
+ const {output, oldValueString} = await updateSequenceProps({
+ input: nestedInput,
+ nodePath: lineColumnToNodePath(nestedInput, 7),
+ key: 'style.opacity',
+ value: 0.8,
+ enumPaths: [],
+ defaultValue: null,
+ });
+
+ expect(oldValueString).toBe('0.5');
+ expect(output).toContain('opacity: 0.8');
+ expect(output).toContain('scale: 2');
+});
+
+test('updateSequenceProps should add a nested property to existing object', async () => {
+ const {output, oldValueString} = await updateSequenceProps({
+ input: nestedInput,
+ nodePath: lineColumnToNodePath(nestedInput, 7),
+ key: 'style.rotate',
+ value: 45,
+ enumPaths: [],
+ defaultValue: null,
+ });
+
+ expect(oldValueString).toBe('');
+ expect(output).toContain('rotate: 45');
+ // Existing properties should be preserved
+ expect(output).toContain('opacity: 0.5');
+ expect(output).toContain('scale: 2');
+});
+
+test('updateSequenceProps should create style attribute when it does not exist', async () => {
+ const {output, oldValueString} = await updateSequenceProps({
+ input: nestedInput,
+ nodePath: lineColumnToNodePath(nestedInput, 8),
+ key: 'style.opacity',
+ value: 0.3,
+ enumPaths: [],
+ defaultValue: null,
+ });
+
+ expect(oldValueString).toBe('');
+ expect(output).toContain('style={{');
+ expect(output).toContain('opacity: 0.3');
+});
+
+test('updateSequenceProps should remove nested property when value equals default', async () => {
+ const {output, oldValueString} = await updateSequenceProps({
+ input: nestedInput,
+ nodePath: lineColumnToNodePath(nestedInput, 7),
+ key: 'style.opacity',
+ value: 1,
+ enumPaths: [],
+ defaultValue: 1,
+ });
+
+ expect(oldValueString).toBe('0.5');
+ expect(output).not.toContain('opacity');
+ // Other properties should remain
+ expect(output).toContain('scale: 2');
+});
+
+test('updateSequenceProps should remove entire style attribute when object becomes empty', async () => {
+ // First remove scale, leaving only opacity
+ const singlePropInput = `import React from 'react';
+
+export const Example: React.FC = () => {
+ return <div style={{opacity: 0.5}} />;
+};
+`;
+
+ const {output, oldValueString} = await updateSequenceProps({
+ input: singlePropInput,
+ nodePath: lineColumnToNodePath(singlePropInput, 4),
+ key: 'style.opacity',
+ value: 1,
+ enumPaths: [],
+ defaultValue: 1,
+ });
+
+ expect(oldValueString).toBe('0.5');
+ expect(output).not.toContain('style');
+});
+
+test('updateSequenceProps should report default as oldValueString for missing nested property', async () => {
+ const {oldValueString} = await updateSequenceProps({
+ input: nestedInput,
+ nodePath: lineColumnToNodePath(nestedInput, 8),
+ key: 'style.opacity',
+ value: 0.5,
+ enumPaths: [],
+ defaultValue: 1,
+ });
+
+ expect(oldValueString).toBe('1');
+});
diff --git a/packages/studio-server/src/test/update-sequence-props.test.ts b/packages/studio-server/src/test/update-sequence-props.test.ts
index 30e6f4e6c8..3d3dc3c2c0 100644
--- a/packages/studio-server/src/test/update-sequence-props.test.ts
+++ b/packages/studio-server/src/test/update-sequence-props.test.ts
@@ -1,90 +1,6 @@
import {expect, test} from 'bun:test';
-import path from 'node:path';
-import type {Expression} from '@babel/types';
-import {parseAst} from '../codemods/parse-ast';
import {updateSequenceProps} from '../codemods/update-sequence-props';
-import {
- extractStaticValue,
- isStaticValue,
-} from '../preview-server/routes/can-update-sequence-props';
-import {computeSequencePropsStatus} from '../preview-server/routes/can-update-sequence-props';
-
-const parseExpression = (code: string): Expression => {
- const ast = parseAst(`a = ${code}`);
- const stmt = ast.program.body[0];
- if (
- stmt.type !== 'ExpressionStatement' ||
- stmt.expression.type !== 'AssignmentExpression'
- ) {
- throw new Error('Unexpected AST');
- }
-
- return stmt.expression.right;
-};
-
-test('Static values should be detected as static', () => {
- expect(isStaticValue(parseExpression('42'))).toBe(true);
- expect(isStaticValue(parseExpression('"hello"'))).toBe(true);
- expect(isStaticValue(parseExpression('true'))).toBe(true);
- expect(isStaticValue(parseExpression('false'))).toBe(true);
- expect(isStaticValue(parseExpression('null'))).toBe(true);
- expect(isStaticValue(parseExpression('-1'))).toBe(true);
- expect(isStaticValue(parseExpression('[1, 2, 3]'))).toBe(true);
- expect(isStaticValue(parseExpression('{a: 1, b: "c"}'))).toBe(true);
- expect(isStaticValue(parseExpression('[]'))).toBe(true);
- expect(isStaticValue(parseExpression('{}'))).toBe(true);
-});
-
-test('Computed values should be detected as computed', () => {
- expect(isStaticValue(parseExpression('1 + 2'))).toBe(false);
- expect(isStaticValue(parseExpression('Math.random()'))).toBe(false);
- expect(isStaticValue(parseExpression('someVar'))).toBe(false);
- expect(isStaticValue(parseExpression('foo()'))).toBe(false);
- expect(isStaticValue(parseExpression('a ? b : c'))).toBe(false);
- // eslint-disable-next-line no-template-curly-in-string
- expect(isStaticValue(parseExpression('`template ${"x"}`'))).toBe(false);
-});
-
-test('extractStaticValue should extract values from AST nodes', () => {
- expect(extractStaticValue(parseExpression('42'))).toBe(42);
- expect(extractStaticValue(parseExpression('"hello"'))).toBe('hello');
- expect(extractStaticValue(parseExpression('true'))).toBe(true);
- expect(extractStaticValue(parseExpression('false'))).toBe(false);
- expect(extractStaticValue(parseExpression('null'))).toBe(null);
- expect(extractStaticValue(parseExpression('-1'))).toBe(-1);
- expect(extractStaticValue(parseExpression('[1, 2, 3]'))).toEqual([1, 2, 3]);
- expect(extractStaticValue(parseExpression('{a: 1, b: "c"}'))).toEqual({
- a: 1,
- b: 'c',
- });
- expect(extractStaticValue(parseExpression('[]'))).toEqual([]);
- expect(extractStaticValue(parseExpression('{}'))).toEqual({});
-});
-
-test('canUpdateSequenceProps should flag computed props', () => {
- const result = computeSequencePropsStatus({
- fileName: path.join(__dirname, 'snapshots', 'light-leak-computed.txt'),
- line: 8,
- keys: ['durationInFrames', 'seed', 'hueShift', 'nonExistentProp'],
- remotionRoot: '/',
- });
-
- expect(result.canUpdate).toBe(true);
- if (!result.canUpdate) {
- throw new Error('Expected canUpdate to be true');
- }
-
- expect(result.props.durationInFrames).toEqual({
- canUpdate: true,
- codeValue: 60,
- });
- expect(result.props.hueShift).toEqual({canUpdate: true, codeValue: 30});
- expect(result.props.seed).toEqual({canUpdate: false, reason: 'computed'});
- expect(result.props.nonExistentProp).toEqual({
- canUpdate: true,
- codeValue: undefined,
- });
-});
+import {lineColumnToNodePath} from './test-utils';
const lightLeakInput = `import {LightLeak} from '@remotion/light-leaks';
import React from 'react';
@@ -103,7 +19,7 @@ export const LightLeakExample: React.FC = () => {
test('updateSequenceProps should update a number value', async () => {
const {output, oldValueString} = await updateSequenceProps({
input: lightLeakInput,
- targetLine: 8,
+ nodePath: lineColumnToNodePath(lightLeakInput, 8),
key: 'hueShift',
value: 90,
enumPaths: [],
@@ -119,7 +35,7 @@ test('updateSequenceProps should update a number value', async () => {
test('updateSequenceProps should update durationInFrames', async () => {
const {output, oldValueString} = await updateSequenceProps({
input: lightLeakInput,
- targetLine: 9,
+ nodePath: lineColumnToNodePath(lightLeakInput, 9),
key: 'durationInFrames',
value: 120,
enumPaths: [],
@@ -135,7 +51,7 @@ test('updateSequenceProps should update durationInFrames', async () => {
test('updateSequenceProps should add a new attribute', async () => {
const {output, oldValueString} = await updateSequenceProps({
input: lightLeakInput,
- targetLine: 9,
+ nodePath: lineColumnToNodePath(lightLeakInput, 9),
key: 'speed',
value: 2,
enumPaths: [],
@@ -149,7 +65,7 @@ test('updateSequenceProps should add a new attribute', async () => {
test('updateSequenceProps should remove attribute when value equals default', async () => {
const {output, oldValueString} = await updateSequenceProps({
input: lightLeakInput,
- targetLine: 9,
+ nodePath: lineColumnToNodePath(lightLeakInput, 9),
key: 'hueShift',
value: 0,
enumPaths: [],
@@ -165,7 +81,7 @@ test('updateSequenceProps should remove attribute when value equals default', as
test('updateSequenceProps should set boolean true as shorthand', async () => {
const {output} = await updateSequenceProps({
input: lightLeakInput,
- targetLine: 8,
+ nodePath: lineColumnToNodePath(lightLeakInput, 8),
key: 'loop',
value: true,
enumPaths: [],
@@ -180,7 +96,7 @@ test('updateSequenceProps should set boolean true as shorthand', async () => {
test('updateSequenceProps should report oldValueString for computed expressions', async () => {
const {oldValueString} = await updateSequenceProps({
input: lightLeakInput,
- targetLine: 8,
+ nodePath: lineColumnToNodePath(lightLeakInput, 8),
key: 'seed',
value: 5,
enumPaths: [],
@@ -193,7 +109,7 @@ test('updateSequenceProps should report oldValueString for computed expressions'
test('updateSequenceProps should report default as oldValueString for missing attribute', async () => {
const {oldValueString} = await updateSequenceProps({
input: lightLeakInput,
- targetLine: 8,
+ nodePath: lineColumnToNodePath(lightLeakInput, 8),
key: 'speed',
value: 2,
enumPaths: [],
@@ -203,11 +119,11 @@ test('updateSequenceProps should report default as oldValueString for missing at
expect(oldValueString).toBe('1');
});
-test('updateSequenceProps should throw for non-existent line', async () => {
+test('updateSequenceProps should throw for non-existent nodePath', async () => {
await expect(
updateSequenceProps({
input: lightLeakInput,
- targetLine: 999,
+ nodePath: ['program', 'body', 999],
key: 'hueShift',
value: 90,
enumPaths: [],
@@ -217,214 +133,3 @@ test('updateSequenceProps should throw for non-existent line', async () => {
'Could not find a JSX element at the specified line to update',
);
});
-
-// --- Nested prop (dotted key) tests ---
-
-const nestedInput = `import React from 'react';
-import {AbsoluteFill} from 'remotion';
-
-export const Example: React.FC = () => {
- return (
- <AbsoluteFill>
- <div style={{opacity: 0.5, scale: 2}} />
- <div />
- </AbsoluteFill>
- );
-};
-`;
-
-test('updateSequenceProps should update a nested style property', async () => {
- const {output, oldValueString} = await updateSequenceProps({
- input: nestedInput,
- targetLine: 7,
- key: 'style.opacity',
- value: 0.8,
- enumPaths: [],
- defaultValue: null,
- });
-
- expect(oldValueString).toBe('0.5');
- expect(output).toContain('opacity: 0.8');
- expect(output).toContain('scale: 2');
-});
-
-test('updateSequenceProps should add a nested property to existing object', async () => {
- const {output, oldValueString} = await updateSequenceProps({
- input: nestedInput,
- targetLine: 7,
- key: 'style.rotate',
- value: 45,
- enumPaths: [],
- defaultValue: null,
- });
-
- expect(oldValueString).toBe('');
- expect(output).toContain('rotate: 45');
- // Existing properties should be preserved
- expect(output).toContain('opacity: 0.5');
- expect(output).toContain('scale: 2');
-});
-
-test('updateSequenceProps should create style attribute when it does not exist', async () => {
- const {output, oldValueString} = await updateSequenceProps({
- input: nestedInput,
- targetLine: 8,
- key: 'style.opacity',
- value: 0.3,
- enumPaths: [],
- defaultValue: null,
- });
-
- expect(oldValueString).toBe('');
- expect(output).toContain('style={{');
- expect(output).toContain('opacity: 0.3');
-});
-
-test('updateSequenceProps should remove nested property when value equals default', async () => {
- const {output, oldValueString} = await updateSequenceProps({
- input: nestedInput,
- targetLine: 7,
- key: 'style.opacity',
- value: 1,
- enumPaths: [],
- defaultValue: 1,
- });
-
- expect(oldValueString).toBe('0.5');
- expect(output).not.toContain('opacity');
- // Other properties should remain
- expect(output).toContain('scale: 2');
-});
-
-test('updateSequenceProps should remove entire style attribute when object becomes empty', async () => {
- // First remove scale, leaving only opacity
- const singlePropInput = `import React from 'react';
-
-export const Example: React.FC = () => {
- return <div style={{opacity: 0.5}} />;
-};
-`;
-
- const {output, oldValueString} = await updateSequenceProps({
- input: singlePropInput,
- targetLine: 4,
- key: 'style.opacity',
- value: 1,
- enumPaths: [],
- defaultValue: 1,
- });
-
- expect(oldValueString).toBe('0.5');
- expect(output).not.toContain('style');
-});
-
-test('updateSequenceProps should report default as oldValueString for missing nested property', async () => {
- const {oldValueString} = await updateSequenceProps({
- input: nestedInput,
- targetLine: 8,
- key: 'style.opacity',
- value: 0.5,
- enumPaths: [],
- defaultValue: 1,
- });
-
- expect(oldValueString).toBe('1');
-});
-
-// --- computeSequencePropsStatus nested prop tests ---
-
-test('computeSequencePropsStatus should detect static nested props', () => {
- const result = computeSequencePropsStatus({
- fileName: path.join(__dirname, 'snapshots', 'nested-props.txt'),
- line: 7,
- keys: ['style.opacity', 'style.scale'],
- remotionRoot: '/',
- });
-
- expect(result.canUpdate).toBe(true);
- if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
-
- expect(result.props['style.opacity']).toEqual({
- canUpdate: true,
- codeValue: 0.5,
- });
- expect(result.props['style.scale']).toEqual({
- canUpdate: true,
- codeValue: 2,
- });
-});
-
-test('computeSequencePropsStatus should flag computed nested props', () => {
- const result = computeSequencePropsStatus({
- fileName: path.join(__dirname, 'snapshots', 'nested-props.txt'),
- line: 8,
- keys: ['style.opacity', 'style.scale'],
- remotionRoot: '/',
- });
-
- expect(result.canUpdate).toBe(true);
- if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
-
- // opacity uses getOpacity() β€” computed
- expect(result.props['style.opacity']).toEqual({
- canUpdate: false,
- reason: 'computed',
- });
- // scale is static
- expect(result.props['style.scale']).toEqual({
- canUpdate: true,
- codeValue: 2,
- });
-});
-
-test('computeSequencePropsStatus should flag computed when parent is not an object', () => {
- const result = computeSequencePropsStatus({
- fileName: path.join(__dirname, 'snapshots', 'nested-props.txt'),
- line: 9,
- keys: ['style.opacity'],
- remotionRoot: '/',
- });
-
- expect(result.canUpdate).toBe(true);
- if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
-
- // style={dynamicStyles} β€” entire parent is computed
- expect(result.props['style.opacity']).toEqual({
- canUpdate: false,
- reason: 'computed',
- });
-});
-
-test('computeSequencePropsStatus should report unset nested props as undefined', () => {
- const result = computeSequencePropsStatus({
- fileName: path.join(__dirname, 'snapshots', 'nested-props.txt'),
- line: 7,
- keys: ['style.rotate'],
- remotionRoot: '/',
- });
-
- expect(result.canUpdate).toBe(true);
- if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
-
- expect(result.props['style.rotate']).toEqual({
- canUpdate: true,
- codeValue: undefined,
- });
-});
-
-test('computeSequencePropsStatus should report unset when parent attribute missing', () => {
- const result = computeSequencePropsStatus({
- fileName: path.join(__dirname, 'snapshots', 'nested-props.txt'),
- line: 10,
- keys: ['style.opacity'],
- remotionRoot: '/',
- });
-
- expect(result.canUpdate).toBe(true);
- if (!result.canUpdate) throw new Error('Expected canUpdate to be true');
-
- expect(result.props['style.opacity']).toEqual({
- canUpdate: true,
- codeValue: undefined,
- });
-});
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index 4960aef437..f5356d0043 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -18,6 +18,8 @@ import type {ProjectInfo} from './project-info';
import type {RequiredChromiumOptions} from './render-job';
import type {EnumPath} from './stringify-default-props';
+export type SequenceNodePath = Array<string | number>;
+
export type OpenInFileExplorerRequest = {
directory: string;
};
@@ -194,8 +196,7 @@ export type CanUpdateDefaultPropsResponse =
export type CanUpdateSequencePropsRequest = {
fileName: string;
- line: number;
- column: number;
+ nodePath: SequenceNodePath;
keys: string[];
};
@@ -211,8 +212,7 @@ export type SubscribeToSequencePropsResponse = CanUpdateSequencePropsResponse;
export type UnsubscribeFromSequencePropsRequest = {
fileName: string;
- line: number;
- column: number;
+ nodePath: SequenceNodePath;
clientId: string;
};
@@ -220,6 +220,7 @@ export type CanUpdateSequencePropsResponse =
| {
canUpdate: true;
props: Record<string, CanUpdateSequencePropStatus>;
+ nodePath: SequenceNodePath;
}
| {
canUpdate: false;
@@ -228,8 +229,7 @@ export type CanUpdateSequencePropsResponse =
export type SaveSequencePropsRequest = {
fileName: string;
- line: number;
- column: number;
+ nodePath: SequenceNodePath;
key: string;
value: string;
enumPaths: EnumPath[];
diff --git a/packages/studio-shared/src/event-source-event.ts b/packages/studio-shared/src/event-source-event.ts
index 714654559c..169388afd1 100644
--- a/packages/studio-shared/src/event-source-event.ts
+++ b/packages/studio-shared/src/event-source-event.ts
@@ -1,5 +1,8 @@
import type {StaticFile} from 'remotion';
-import type {CanUpdateSequencePropsResponse} from './api-requests';
+import type {
+ CanUpdateSequencePropsResponse,
+ SequenceNodePath,
+} from './api-requests';
import type {CompletedClientRender, RenderJob} from './render-job';
export type EventSourceEvent =
@@ -47,7 +50,6 @@ export type EventSourceEvent =
| {
type: 'sequence-props-updated';
fileName: string;
- line: number;
- column: number;
+ nodePath: SequenceNodePath;
result: CanUpdateSequencePropsResponse;
};
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index 08f49b8e5e..5aa21acf17 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -28,6 +28,7 @@ export {
RestartStudioResponse,
SaveSequencePropsRequest,
SaveSequencePropsResponse,
+ SequenceNodePath,
SimpleDiff,
SubscribeToFileExistenceRequest,
SubscribeToFileExistenceResponse,
diff --git a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
index 19212bc099..a208a9c3c2 100644
--- a/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
+++ b/packages/studio/src/components/Timeline/TimelineExpandedSection.tsx
@@ -1,3 +1,4 @@
+import type {SequenceNodePath} from '@remotion/studio-shared';
import React, {useMemo} from 'react';
import type {TSequence} from 'remotion';
import type {
@@ -32,7 +33,8 @@ export const TimelineExpandedSection: React.FC<{
readonly sequence: TSequence;
readonly originalLocation: OriginalPosition | null;
readonly nestedDepth: number;
-}> = ({sequence, originalLocation, nestedDepth}) => {
+ readonly nodePath: SequenceNodePath | null;
+}> = ({sequence, originalLocation, nestedDepth, nodePath}) => {
const overrideId = sequence.controls?.overrideId ?? sequence.id;
const schemaFields = useMemo(
() => getSchemaFields(sequence.controls),
@@ -79,6 +81,7 @@ export const TimelineExpandedSection: React.FC<{
overrideId={overrideId}
validatedLocation={validatedLocation}
nestedDepth={nestedDepth}
+ nodePath={nodePath}
/>
</React.Fragment>
);
diff --git a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
index 513af7bc37..a3b18c9a04 100644
--- a/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
+++ b/packages/studio/src/components/Timeline/TimelineFieldRow.tsx
@@ -1,3 +1,4 @@
+import type {SequenceNodePath} from '@remotion/studio-shared';
import React, {useCallback, useContext, useMemo} from 'react';
import {Internals} from 'remotion';
import type {CanUpdateSequencePropStatus} from 'remotion';
@@ -38,7 +39,8 @@ export const TimelineFieldRow: React.FC<{
readonly overrideId: string;
readonly validatedLocation: CodePosition | null;
readonly nestedDepth: number;
-}> = ({field, overrideId, validatedLocation, nestedDepth}) => {
+ readonly nodePath: SequenceNodePath | null;
+}> = ({field, overrideId, validatedLocation, nestedDepth, nodePath}) => {
const {
setDragOverrides,
clearDragOverrides,
@@ -67,7 +69,7 @@ export const TimelineFieldRow: React.FC<{
const onSave = useCallback(
(key: string, value: unknown): Promise<void> => {
- if (!propStatuses || !validatedLocation) {
+ if (!propStatuses || !validatedLocation || !nodePath) {
return Promise.reject(new Error('Cannot save'));
}
@@ -83,15 +85,14 @@ export const TimelineFieldRow: React.FC<{
return callApi('/api/save-sequence-props', {
fileName: validatedLocation.source,
- line: validatedLocation.line,
- column: validatedLocation.column,
+ nodePath,
key,
value: JSON.stringify(value),
enumPaths: [],
defaultValue,
}).then(() => undefined);
},
- [propStatuses, validatedLocation, field.fieldSchema.default],
+ [propStatuses, validatedLocation, nodePath, field.fieldSchema.default],
);
const onDragValueChange = useCallback(
diff --git a/packages/studio/src/components/Timeline/TimelineListItem.tsx b/packages/studio/src/components/Timeline/TimelineListItem.tsx
index a66d1559dd..369a051bdc 100644
--- a/packages/studio/src/components/Timeline/TimelineListItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineListItem.tsx
@@ -55,7 +55,7 @@ export const TimelineListItem: React.FC<{
const {expandedTracks, toggleTrack} = useContext(ExpandedTracksContext);
const originalLocation = useResolvedStack(sequence.stack ?? null);
- useSequencePropsSubscription(sequence, originalLocation);
+ const nodePath = useSequencePropsSubscription(sequence, originalLocation);
const isExpanded =
visualModeEnabled && (expandedTracks[sequence.id] ?? false);
@@ -154,6 +154,7 @@ export const TimelineListItem: React.FC<{
sequence={sequence}
originalLocation={originalLocation}
nestedDepth={nestedDepth}
+ nodePath={nodePath}
/>
) : null}
</>
diff --git a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
index c12bc4fcf1..92064b3fae 100644
--- a/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
+++ b/packages/studio/src/components/Timeline/use-sequence-props-subscription.ts
@@ -1,4 +1,4 @@
-import type {EventSourceEvent} from '@remotion/studio-shared';
+import type {EventSourceEvent, SequenceNodePath} from '@remotion/studio-shared';
import {useCallback, useContext, useEffect, useMemo, useRef} from 'react';
import {Internals, type CanUpdateSequencePropStatus} from 'remotion';
import type {TSequence} from 'remotion';
@@ -10,7 +10,7 @@ import {callApi} from '../call-api';
export const useSequencePropsSubscription = (
sequence: TSequence,
originalLocation: OriginalPosition | null,
-): void => {
+): SequenceNodePath | null => {
const {setCodeValues} = useContext(Internals.VisualModeOverridesContext);
const overrideId = sequence.controls?.overrideId ?? null;
@@ -67,6 +67,16 @@ export const useSequencePropsSubscription = (
const currentLocationColumn = useRef(locationColumn);
currentLocationColumn.current = locationColumn;
+ const nodePathRef = useRef<SequenceNodePath | null>(null);
+ const isMountedRef = useRef(true);
+
+ useEffect(() => {
+ isMountedRef.current = true;
+ return () => {
+ isMountedRef.current = false;
+ };
+ }, []);
+
useEffect(() => {
if (
!clientId ||
@@ -98,25 +108,37 @@ export const useSequencePropsSubscription = (
}
if (result.canUpdate) {
+ nodePathRef.current = result.nodePath;
setPropStatusesForSequence(result.props);
} else {
+ nodePathRef.current = null;
setPropStatusesForSequence(null);
}
})
- .catch(() => {
+ .catch((err) => {
+ nodePathRef.current = null;
+ Internals.Log.error(err);
setPropStatusesForSequence(null);
});
return () => {
- setPropStatusesForSequence(null);
- callApi('/api/unsubscribe-from-sequence-props', {
- fileName: locationSource,
- line: locationLine,
- column: locationColumn,
- clientId,
- }).catch(() => {
- // Ignore unsubscribe errors
- });
+ const currentNodePath = nodePathRef.current;
+ // Only clear props on true unmount, not on re-subscribe due to
+ // line number changes β€” avoids flicker while re-subscribing.
+ if (!isMountedRef.current) {
+ setPropStatusesForSequence(null);
+ }
+
+ nodePathRef.current = null;
+ if (currentNodePath) {
+ callApi('/api/unsubscribe-from-sequence-props', {
+ fileName: locationSource,
+ nodePath: currentNodePath,
+ clientId,
+ }).catch(() => {
+ // Ignore unsubscribe errors
+ });
+ }
};
}, [
clientId,
@@ -139,8 +161,8 @@ export const useSequencePropsSubscription = (
if (
event.fileName !== currentLocationSource.current ||
- event.line !== currentLocationLine.current ||
- event.column !== currentLocationColumn.current
+ !nodePathRef.current ||
+ JSON.stringify(event.nodePath) !== JSON.stringify(nodePathRef.current)
) {
return;
}
@@ -163,4 +185,6 @@ export const useSequencePropsSubscription = (
subscribeToEvent,
setPropStatusesForSequence,
]);
+
+ return nodePathRef.current;
};