Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Fix Visual Editing after splitting multiple items

JonnyBurgeraa32a236ab78
diff --git a/packages/browser-studio/src/browser-studio-operations.ts b/packages/browser-studio/src/browser-studio-operations.ts
index f06a94404b..7748e8ed3f 100644
--- a/packages/browser-studio/src/browser-studio-operations.ts
+++ b/packages/browser-studio/src/browser-studio-operations.ts
@@ -174,7 +174,12 @@ const insertIntoProject = async ({
filePath: result.insertedNode.filePath,
insertedNodePath: result.insertedNode.nodePath,
nodePathRemappings: result.nodePathRemappings.map(
- ({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath}),
+ ({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ }),
),
};
};
@@ -189,7 +194,12 @@ const getNodePathMutationFiles = (result: CodemodNodeResult) =>
absolutePath,
remappings: result.nodePathRemappings
.filter(({filePath}) => filePath === absolutePath)
- .map(({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath})),
+ .map(({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ })),
}));
const getStructuredError = (error: unknown) => ({
diff --git a/packages/browser-studio/src/browser-studio-project-controller.ts b/packages/browser-studio/src/browser-studio-project-controller.ts
index e8af78aaa6..efc658962e 100644
--- a/packages/browser-studio/src/browser-studio-project-controller.ts
+++ b/packages/browser-studio/src/browser-studio-project-controller.ts
@@ -622,6 +622,12 @@ export const createBrowserStudioProjectController = ({
(remapping): SequenceNodePathRemapping => ({
oldNodePath: remapping.newNodePath,
newNodePath: remapping.oldNodePath,
+ ...(remapping.newJsxName === undefined
+ ? {}
+ : {oldJsxName: remapping.newJsxName}),
+ ...(remapping.oldJsxName === undefined
+ ? {}
+ : {newJsxName: remapping.oldJsxName}),
}),
),
}));
diff --git a/packages/browser-studio/src/test/browser-studio-operations.test.ts b/packages/browser-studio/src/test/browser-studio-operations.test.ts
index 4b7ffc6194..8ac19b74e3 100644
--- a/packages/browser-studio/src/test/browser-studio-operations.test.ts
+++ b/packages/browser-studio/src/test/browser-studio-operations.test.ts
@@ -311,14 +311,14 @@ export const Root = () => <Composition id="MyComp" component={Component} duratio
{
absolutePath: fileName,
remappings: expect.arrayContaining([
- {
+ expect.objectContaining({
oldNodePath: subscription.nodePath.nodePath,
newNodePath: expect.any(Array),
- },
- {
+ }),
+ expect.objectContaining({
oldNodePath: null,
newNodePath: expect.any(Array),
- },
+ }),
]),
},
]);
diff --git a/packages/browser-studio/src/test/browser-studio-project-operations.test.ts b/packages/browser-studio/src/test/browser-studio-project-operations.test.ts
index 7312a85700..59a5fe8e82 100644
--- a/packages/browser-studio/src/test/browser-studio-project-operations.test.ts
+++ b/packages/browser-studio/src/test/browser-studio-project-operations.test.ts
@@ -164,6 +164,12 @@ test('mutates virtual files, emits events, and preserves undo and redo history',
remappings: file.remappings.map((remapping) => ({
oldNodePath: remapping.newNodePath,
newNodePath: remapping.oldNodePath,
+ ...(remapping.newJsxName === undefined
+ ? {}
+ : {oldJsxName: remapping.newJsxName}),
+ ...(remapping.oldJsxName === undefined
+ ? {}
+ : {newJsxName: remapping.oldJsxName}),
})),
})),
);
@@ -204,10 +210,10 @@ test('mutates virtual files, emits events, and preserves undo and redo history',
{
absolutePath: '/project/src/Composition.tsx',
remappings: expect.arrayContaining([
- {
+ expect.objectContaining({
oldNodePath: insertResult.insertedNodePath.nodePath,
newNodePath: null,
- },
+ }),
]),
},
]);
diff --git a/packages/codemods/src/get-node-path-remappings.ts b/packages/codemods/src/get-node-path-remappings.ts
index a486c61b08..e8b69270ad 100644
--- a/packages/codemods/src/get-node-path-remappings.ts
+++ b/packages/codemods/src/get-node-path-remappings.ts
@@ -8,6 +8,7 @@ import {getReadOnlySourceSnapshot} from './sequence-props-snapshot';
export type CapturedJsxNodePath = {
node: JSXOpeningElement;
nodePath: SequenceNodePath;
+ jsxName: string;
signature: string;
// The opening element of the closest enclosing JSX element, if any.
parentNode: JSXOpeningElement | null;
@@ -32,6 +33,7 @@ export const captureJsxNodePaths = (ast: File): CapturedJsxNodePath[] => {
captured.push({
node: path.node as JSXOpeningElement,
nodePath: getNodePathForRecastPath(path, ast),
+ jsxName: recast.prettyPrint(path.node.name).code,
signature: recast.prettyPrint(path.node as JSXOpeningElement).code,
parentNode,
});
@@ -63,26 +65,31 @@ export const getNodePathRemappings = ({
});
const {ast: finalAst} = getReadOnlySourceSnapshot(output);
- const finalNodePaths: SequenceNodePath[] = [];
+ const finalNodes: Array<{nodePath: SequenceNodePath; jsxName: string}> = [];
recast.visit(finalAst, {
visitJSXOpeningElement(path) {
- finalNodePaths.push(getNodePathForRecastPath(path, finalAst));
+ finalNodes.push({
+ nodePath: getNodePathForRecastPath(path, finalAst),
+ jsxName: recast.prettyPrint(path.node.name).code,
+ });
return this.traverse(path);
},
});
- if (nodesAfterMutation.length !== finalNodePaths.length) {
+ if (nodesAfterMutation.length !== finalNodes.length) {
throw new Error('Could not map JSX node paths after modifying JSX nodes');
}
const finalNodePathByNode = new Map<JSXOpeningElement, SequenceNodePath>();
+ const finalJsxNameByNode = new Map<JSXOpeningElement, string>();
for (let i = 0; i < nodesAfterMutation.length; i++) {
- finalNodePathByNode.set(nodesAfterMutation[i], finalNodePaths[i]);
+ finalNodePathByNode.set(nodesAfterMutation[i], finalNodes[i].nodePath);
+ finalJsxNameByNode.set(nodesAfterMutation[i], finalNodes[i].jsxName);
}
const capturedNodes = new Set(captured.map(({node}) => node));
const nodePathRemappings: SequenceNodePathRemapping[] = captured.flatMap(
- ({node, nodePath, signature}) => {
+ ({node, nodePath, jsxName, signature}) => {
const newNodePath = finalNodePathByNode.get(node) ?? null;
if (
newNodePath !== null &&
@@ -92,7 +99,17 @@ export const getNodePathRemappings = ({
return [];
}
- return [{oldNodePath: nodePath, newNodePath}];
+ return [
+ {
+ oldNodePath: nodePath,
+ newNodePath,
+ oldJsxName: jsxName,
+ newJsxName:
+ newNodePath === null
+ ? null
+ : (finalJsxNameByNode.get(node) ?? null),
+ },
+ ];
},
);
@@ -106,7 +123,12 @@ export const getNodePathRemappings = ({
throw new Error('Could not map inserted JSX node path');
}
- nodePathRemappings.push({oldNodePath: null, newNodePath});
+ nodePathRemappings.push({
+ oldNodePath: null,
+ newNodePath,
+ oldJsxName: null,
+ newJsxName: finalJsxNameByNode.get(node) ?? null,
+ });
}
return {finalNodePathByNode, nodePathRemappings};
diff --git a/packages/codemods/src/node-references.ts b/packages/codemods/src/node-references.ts
index 81415804e6..9ed6fbe382 100644
--- a/packages/codemods/src/node-references.ts
+++ b/packages/codemods/src/node-references.ts
@@ -1,3 +1,4 @@
+import type {SequenceNodePathRemapping} from '@remotion/studio-shared';
import type {SequenceNodePath} from 'remotion';
import type {CodemodProject, CodemodResult} from './codemod-project';
import {getCodemodResult} from './codemod-project';
@@ -10,10 +11,8 @@ export type NodeReference = {
nodePath: SequenceNodePath;
};
-export type NodePathRemapping = {
+export type NodePathRemapping = SequenceNodePathRemapping & {
filePath: string;
- oldNodePath: SequenceNodePath | null;
- newNodePath: SequenceNodePath | null;
};
export type CodemodNodeResult = CodemodResult & {
@@ -27,10 +26,7 @@ export type CodemodInsertionResult = CodemodNodeResult & {
export type NodeSourceEdit = {
filePath: string;
output: string;
- nodePathRemappings: {
- oldNodePath: SequenceNodePath | null;
- newNodePath: SequenceNodePath | null;
- }[];
+ nodePathRemappings: SequenceNodePathRemapping[];
};
export const getInsertedNodeReferences = (
diff --git a/packages/codemods/src/test/duplicate-jsx-node.test.ts b/packages/codemods/src/test/duplicate-jsx-node.test.ts
index 0c4aa15cc6..2493a4df71 100644
--- a/packages/codemods/src/test/duplicate-jsx-node.test.ts
+++ b/packages/codemods/src/test/duplicate-jsx-node.test.ts
@@ -45,10 +45,14 @@ test('duplicateNodes remaps following JSX siblings', async () => {
{
oldNodePath: lineContainingToNodePath(input, 'name="following"'),
newNodePath: lineContainingToNodePath(output, 'name="following"'),
+ oldJsxName: 'span',
+ newJsxName: 'span',
},
{
oldNodePath: null,
newNodePath: lineContainingToNodePath(output, 'name="duplicate-copy"'),
+ oldJsxName: null,
+ newJsxName: 'span',
},
]);
});
diff --git a/packages/codemods/src/test/reorder-sequence.test.ts b/packages/codemods/src/test/reorder-sequence.test.ts
index ed6d569a6f..9179ee038a 100644
--- a/packages/codemods/src/test/reorder-sequence.test.ts
+++ b/packages/codemods/src/test/reorder-sequence.test.ts
@@ -91,14 +91,20 @@ export const Comp=()=>{
{
oldNodePath: sequenceContaining(input, "name='a'"),
newNodePath: sequenceContaining(output, "name='a'"),
+ oldJsxName: 'Sequence',
+ newJsxName: 'Sequence',
},
{
oldNodePath: sequenceContaining(input, "name='b'"),
newNodePath: sequenceContaining(output, "name='b'"),
+ oldJsxName: 'Sequence',
+ newJsxName: 'Sequence',
},
{
oldNodePath: sequenceContaining(input, "name='c'"),
newNodePath: sequenceContaining(output, "name='c'"),
+ oldJsxName: 'Sequence',
+ newJsxName: 'Sequence',
},
]);
});
diff --git a/packages/codemods/src/test/split-jsx-sequence.test.ts b/packages/codemods/src/test/split-jsx-sequence.test.ts
index a6c900af5e..da514c04b6 100644
--- a/packages/codemods/src/test/split-jsx-sequence.test.ts
+++ b/packages/codemods/src/test/split-jsx-sequence.test.ts
@@ -161,14 +161,20 @@ test('splitJsxSequence remaps following JSX siblings', async () => {
{
oldNodePath: lineContainingToNodePath(input, 'name="split"'),
newNodePath: lineContainingToNodePath(output, 'name="split"'),
+ oldJsxName: 'Sequence',
+ newJsxName: 'Sequence',
},
{
oldNodePath: lineContainingToNodePath(input, 'name="following"'),
newNodePath: lineContainingToNodePath(output, 'name="following"'),
+ oldJsxName: 'Sequence',
+ newJsxName: 'Sequence',
},
{
oldNodePath: null,
newNodePath: lineContainingToNodePath(output, 'from={30}'),
+ oldJsxName: null,
+ newJsxName: 'Sequence',
},
]);
});
diff --git a/packages/codemods/src/test/split-video-from-audio.test.ts b/packages/codemods/src/test/split-video-from-audio.test.ts
index b7c6369d7b..ef0b45378b 100644
--- a/packages/codemods/src/test/split-video-from-audio.test.ts
+++ b/packages/codemods/src/test/split-video-from-audio.test.ts
@@ -89,14 +89,20 @@ export const Comp=()=>(
{
oldNodePath: lineContainingToNodePath(input, '<Video'),
newNodePath: lineContainingToNodePath(output, '<Video'),
+ oldJsxName: 'Video',
+ newJsxName: 'Video',
},
{
oldNodePath: lineContainingToNodePath(input, '<div'),
newNodePath: lineContainingToNodePath(output, '<div'),
+ oldJsxName: 'div',
+ newJsxName: 'div',
},
{
oldNodePath: null,
newNodePath: lineContainingToNodePath(output, '<Audio'),
+ oldJsxName: null,
+ newJsxName: 'Audio',
},
]);
});
diff --git a/packages/studio-server/src/preview-server/routes/delete-nodes.ts b/packages/studio-server/src/preview-server/routes/delete-nodes.ts
index 7efa6d8982..0769abac69 100644
--- a/packages/studio-server/src/preview-server/routes/delete-nodes.ts
+++ b/packages/studio-server/src/preview-server/routes/delete-nodes.ts
@@ -80,7 +80,12 @@ export const deleteNodesHandler: ApiHandler<
const output = result.changes[0]?.nextContents ?? fileContents;
const {nodeLabels, logLines} = result.editDetails[0];
const nodePathRemappings = result.nodePathRemappings.map(
- ({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath}),
+ ({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ }),
);
return {
diff --git a/packages/studio-server/src/preview-server/routes/duplicate-nodes.ts b/packages/studio-server/src/preview-server/routes/duplicate-nodes.ts
index 0942847653..f673f8b4af 100644
--- a/packages/studio-server/src/preview-server/routes/duplicate-nodes.ts
+++ b/packages/studio-server/src/preview-server/routes/duplicate-nodes.ts
@@ -63,7 +63,12 @@ export const duplicateNodesHandler: ApiHandler<
const output = result.changes[0]?.nextContents ?? fileContents;
const {nodeLabels, logLines} = result.editDetails[0];
const nodePathRemappings = result.nodePathRemappings.map(
- ({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath}),
+ ({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ }),
);
return {
diff --git a/packages/studio-server/src/preview-server/routes/move-composition.ts b/packages/studio-server/src/preview-server/routes/move-composition.ts
index b7ec602ad3..f91f1e1fd3 100644
--- a/packages/studio-server/src/preview-server/routes/move-composition.ts
+++ b/packages/studio-server/src/preview-server/routes/move-composition.ts
@@ -96,7 +96,12 @@ export const moveCompositionHandler: ApiHandler<
absolutePath,
remappings: result.nodePathRemappings
.filter((remapping) => remapping.filePath === absolutePath)
- .map(({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath})),
+ .map(({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ })),
}));
const nodePathMutation =
mutationFiles.length === 0
diff --git a/packages/studio-server/src/preview-server/routes/move-folder.ts b/packages/studio-server/src/preview-server/routes/move-folder.ts
index c9b9f90c37..fb0140f7b4 100644
--- a/packages/studio-server/src/preview-server/routes/move-folder.ts
+++ b/packages/studio-server/src/preview-server/routes/move-folder.ts
@@ -96,7 +96,12 @@ export const moveFolderHandler: ApiHandler<
absolutePath,
remappings: result.nodePathRemappings
.filter((remapping) => remapping.filePath === absolutePath)
- .map(({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath})),
+ .map(({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ })),
}));
const nodePathMutation =
mutationFiles.length === 0
diff --git a/packages/studio-server/src/preview-server/routes/precompose-jsx-nodes.ts b/packages/studio-server/src/preview-server/routes/precompose-jsx-nodes.ts
index 111a22d4e7..ea08284332 100644
--- a/packages/studio-server/src/preview-server/routes/precompose-jsx-nodes.ts
+++ b/packages/studio-server/src/preview-server/routes/precompose-jsx-nodes.ts
@@ -138,7 +138,12 @@ export const precomposeJsxNodesHandler: ApiHandler<
absolutePath: filePath,
remappings: result.nodePathRemappings
.filter((remapping) => remapping.filePath === filePath)
- .map(({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath})),
+ .map(({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ })),
}));
const mutationFiles = remappingsByFile.filter(
({remappings}) => remappings.length > 0,
diff --git a/packages/studio-server/src/preview-server/routes/reorder-sequence.ts b/packages/studio-server/src/preview-server/routes/reorder-sequence.ts
index 4a9c322b97..1d12530bb4 100644
--- a/packages/studio-server/src/preview-server/routes/reorder-sequence.ts
+++ b/packages/studio-server/src/preview-server/routes/reorder-sequence.ts
@@ -52,7 +52,12 @@ export const reorderSequenceHandler: ApiHandler<
const output = result.changes[0]?.nextContents ?? fileContents;
const {sequenceLabel, logLine} = result.editDetails[0];
const nodePathRemappings = result.nodePathRemappings.map(
- ({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath}),
+ ({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ }),
);
const nodePathMutation = broadcastSequenceNodePathMutation(
[
diff --git a/packages/studio-server/src/preview-server/routes/replace-video-source.ts b/packages/studio-server/src/preview-server/routes/replace-video-source.ts
index 33fad31f50..8486d5e7c8 100644
--- a/packages/studio-server/src/preview-server/routes/replace-video-source.ts
+++ b/packages/studio-server/src/preview-server/routes/replace-video-source.ts
@@ -50,7 +50,12 @@ export const replaceVideoSourceHandler: ApiHandler<
const output = result.changes[0]?.nextContents ?? fileContents;
const {logLine} = result;
const nodePathRemappings = result.nodePathRemappings.map(
- ({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath}),
+ ({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ }),
);
const nodePathMutation = broadcastSequenceNodePathMutation(
[{absolutePath, remappings: nodePathRemappings}],
diff --git a/packages/studio-server/src/preview-server/routes/split-sequences.ts b/packages/studio-server/src/preview-server/routes/split-sequences.ts
index a43e47ac15..752a376948 100644
--- a/packages/studio-server/src/preview-server/routes/split-sequences.ts
+++ b/packages/studio-server/src/preview-server/routes/split-sequences.ts
@@ -65,7 +65,12 @@ export const splitSequencesHandler: ApiHandler<
const output = result.changes[0]?.nextContents ?? fileContents;
const {nodeLabels, logLines} = result.editDetails[0];
const nodePathRemappings = result.nodePathRemappings.map(
- ({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath}),
+ ({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ }),
);
return {
diff --git a/packages/studio-server/src/preview-server/routes/split-video-from-audio.ts b/packages/studio-server/src/preview-server/routes/split-video-from-audio.ts
index d702a62de4..b00b3343f2 100644
--- a/packages/studio-server/src/preview-server/routes/split-video-from-audio.ts
+++ b/packages/studio-server/src/preview-server/routes/split-video-from-audio.ts
@@ -46,7 +46,12 @@ export const splitVideoFromAudioHandler: ApiHandler<
const output = result.changes[0]?.nextContents ?? fileContents;
const {formatted, nodeLabel, logLine} = result.editDetails[0];
const nodePathRemappings = result.nodePathRemappings.map(
- ({oldNodePath, newNodePath}) => ({oldNodePath, newNodePath}),
+ ({oldNodePath, newNodePath, oldJsxName, newJsxName}) => ({
+ oldNodePath,
+ newNodePath,
+ oldJsxName,
+ newJsxName,
+ }),
);
const nodePathMutation = broadcastSequenceNodePathMutation(
[
diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.ts
index 28068e6862..f35e53d6ac 100644
--- a/packages/studio-server/src/preview-server/undo-stack.ts
+++ b/packages/studio-server/src/preview-server/undo-stack.ts
@@ -463,6 +463,12 @@ export function popUndo(): UndoResponse {
(remapping): SequenceNodePathRemapping => ({
oldNodePath: remapping.newNodePath,
newNodePath: remapping.oldNodePath,
+ ...(remapping.newJsxName === undefined
+ ? {}
+ : {oldJsxName: remapping.newJsxName}),
+ ...(remapping.oldJsxName === undefined
+ ? {}
+ : {newJsxName: remapping.oldJsxName}),
}),
),
},
diff --git a/packages/studio-server/src/test/delete-nodes.test.ts b/packages/studio-server/src/test/delete-nodes.test.ts
index 4f46a294aa..8fd762fd7d 100644
--- a/packages/studio-server/src/test/delete-nodes.test.ts
+++ b/packages/studio-server/src/test/delete-nodes.test.ts
@@ -146,14 +146,20 @@ test('deleting a JSX node broadcasts node path mutations for all clients', async
{
oldNodePath: lineColumnToNodePath(interactiveSiblings, 6),
newNodePath: null,
+ oldJsxName: 'Interactive.Div',
+ newJsxName: null,
},
{
oldNodePath: lineColumnToNodePath(interactiveSiblings, 7),
newNodePath: lineColumnToNodePath(output, 6),
+ oldJsxName: 'Interactive.Div',
+ newJsxName: 'Interactive.Div',
},
{
oldNodePath: lineColumnToNodePath(interactiveSiblings, 8),
newNodePath: lineColumnToNodePath(output, 7),
+ oldJsxName: 'Interactive.Div',
+ newJsxName: 'Interactive.Div',
},
],
},
@@ -188,14 +194,20 @@ test('deleting a JSX node broadcasts node path mutations for all clients', async
{
oldNodePath: null,
newNodePath: lineColumnToNodePath(interactiveSiblings, 6),
+ oldJsxName: null,
+ newJsxName: 'Interactive.Div',
},
{
oldNodePath: lineColumnToNodePath(output, 6),
newNodePath: lineColumnToNodePath(interactiveSiblings, 7),
+ oldJsxName: 'Interactive.Div',
+ newJsxName: 'Interactive.Div',
},
{
oldNodePath: lineColumnToNodePath(output, 7),
newNodePath: lineColumnToNodePath(interactiveSiblings, 8),
+ oldJsxName: 'Interactive.Div',
+ newJsxName: 'Interactive.Div',
},
],
},
diff --git a/packages/studio-server/src/test/node-path-mutation-routes.test.ts b/packages/studio-server/src/test/node-path-mutation-routes.test.ts
index c4ca03f5fe..88eb32cd03 100644
--- a/packages/studio-server/src/test/node-path-mutation-routes.test.ts
+++ b/packages/studio-server/src/test/node-path-mutation-routes.test.ts
@@ -118,6 +118,12 @@ test('JSX structure routes broadcast and return node path mutations before writi
remappings: file.remappings.map((remapping) => ({
oldNodePath: remapping.newNodePath,
newNodePath: remapping.oldNodePath,
+ ...(remapping.newJsxName === undefined
+ ? {}
+ : {oldJsxName: remapping.newJsxName}),
+ ...(remapping.oldJsxName === undefined
+ ? {}
+ : {newJsxName: remapping.oldJsxName}),
})),
}));
diff --git a/packages/studio-server/src/test/split-sequences.test.ts b/packages/studio-server/src/test/split-sequences.test.ts
index 14fe9feac5..13c2f0ce5d 100644
--- a/packages/studio-server/src/test/split-sequences.test.ts
+++ b/packages/studio-server/src/test/split-sequences.test.ts
@@ -8,7 +8,7 @@ import {
} from '../file-watcher';
import {setLiveEventsListener} from '../preview-server/live-events';
import {splitSequencesHandler} from '../preview-server/routes/split-sequences';
-import {getUndoStack} from '../preview-server/undo-stack';
+import {getUndoStack, popUndo} from '../preview-server/undo-stack';
import {lineContainingToNodePath} from './test-utils';
const wrap = (
@@ -75,7 +75,7 @@ test('splitSequencesHandler writes success and failure responses', async () => {
clearUndoStack();
const entryPoint = path.join(remotionRoot, 'Root.tsx');
const input = wrap(
- '<AbsoluteFill name="one" from={0} durationInFrames={50} />\n\t\t\t<AbsoluteFill name="two" from={10} durationInFrames={50} />',
+ '<AbsoluteFill name="one" from={0} durationInFrames={50} />\n\t\t\t<Solid name="two" from={10} durationInFrames={50} />',
);
writeFileSync(entryPoint, input);
@@ -107,10 +107,46 @@ test('splitSequencesHandler writes success and failure responses', async () => {
'<AbsoluteFill name="one" from={30} durationInFrames={20} trimBefore={30} />',
);
expect(readFileSync(entryPoint, 'utf-8')).toContain(
- '<AbsoluteFill name="two" from={30} durationInFrames={30} trimBefore={20} />',
+ '<Solid name="two" from={30} durationInFrames={30} trimBefore={20} />',
);
+ if (!success.success) {
+ throw new Error(success.reason);
+ }
+
+ const originalSolidPath = lineContainingToNodePath(input, 'name="two"');
+ const [{remappings}] = success.nodePathMutation.files;
+ expect(
+ remappings.find(
+ (remapping) =>
+ JSON.stringify(remapping.oldNodePath) ===
+ JSON.stringify(originalSolidPath),
+ ),
+ ).toMatchObject({oldJsxName: 'Solid', newJsxName: 'Solid'});
+ expect(
+ remappings.find(
+ (remapping) =>
+ remapping.oldNodePath === null &&
+ JSON.stringify(remapping.newNodePath) ===
+ JSON.stringify(originalSolidPath),
+ ),
+ ).toMatchObject({oldJsxName: null, newJsxName: 'AbsoluteFill'});
expect(getUndoStack().length).toBe(1);
+ const undo = popUndo();
+ expect(undo.success).toBe(true);
+ if (!undo.success || undo.nodePathMutation === null) {
+ throw new Error('Expected undo to include a node path mutation');
+ }
+
+ expect(readFileSync(entryPoint, 'utf-8')).toBe(input);
+ expect(
+ undo.nodePathMutation.files[0].remappings.find(
+ (remapping) =>
+ JSON.stringify(remapping.oldNodePath) ===
+ JSON.stringify(originalSolidPath) && remapping.newNodePath === null,
+ ),
+ ).toMatchObject({oldJsxName: 'AbsoluteFill', newJsxName: null});
+
const failure = await splitSequencesHandler(
getHandlerOptions({
input: {
diff --git a/packages/studio-shared/src/sequence-node-path-mutation.ts b/packages/studio-shared/src/sequence-node-path-mutation.ts
index 78a3bfe2a4..2ad25046be 100644
--- a/packages/studio-shared/src/sequence-node-path-mutation.ts
+++ b/packages/studio-shared/src/sequence-node-path-mutation.ts
@@ -5,6 +5,10 @@ export type SequenceNodePathRemapping = {
oldNodePath: SequenceNodePath | null;
/** `null` means the JSX node was deleted by this mutation. */
newNodePath: SequenceNodePath | null;
+ /** JSX tag before the mutation. Older mutation producers may omit it. */
+ oldJsxName?: string | null;
+ /** JSX tag after the mutation. Older mutation producers may omit it. */
+ newJsxName?: string | null;
};
export type SequenceNodePathMutation = {
diff --git a/packages/studio/src/components/Timeline/SequencePropsObserver.tsx b/packages/studio/src/components/Timeline/SequencePropsObserver.tsx
index 50cddb0f44..f11e2a9052 100644
--- a/packages/studio/src/components/Timeline/SequencePropsObserver.tsx
+++ b/packages/studio/src/components/Timeline/SequencePropsObserver.tsx
@@ -107,19 +107,24 @@ export const SequencePropsObserver = () => {
}
// Prop statuses follow source nodes to their new paths. Override IDs
- // normally follow React's runtime instances, which may be reused at an
- // old path. If the old path has no runtime replacement, move its mapping
- // to the new source path and resubscribe without remounting the instance.
- const runtimeNodePathIsSource = file.remappings.some(
+ // normally follow React's runtime instances, which may be reused when the
+ // same JSX component takes over an old path. A different component remounts,
+ // so move the old mapping with its source node and resubscribe instead.
+ const runtimeNodePathSource = file.remappings.find(
(item) =>
item.oldNodePath !== null &&
JSON.stringify(item.oldNodePath) === previousNodePathString,
);
- const runtimeNodePathIsDestination = file.remappings.some(
+ const runtimeNodePathDestination = file.remappings.find(
(item) =>
item.newNodePath !== null &&
JSON.stringify(item.newNodePath) === previousNodePathString,
);
+ const replacementComponentMatches =
+ runtimeNodePathSource?.oldJsxName === undefined ||
+ runtimeNodePathDestination?.newJsxName === undefined ||
+ runtimeNodePathSource.oldJsxName ===
+ runtimeNodePathDestination.newJsxName;
const runtimeNodePathWasInserted = file.remappings.some(
(item) =>
item.oldNodePath === null &&
@@ -133,11 +138,14 @@ export const SequencePropsObserver = () => {
JSON.stringify(item.oldNodePath) === previousNodePathString &&
JSON.stringify(item.newNodePath) === previousNodePathString,
);
- if (runtimeNodePathIsSource) {
- runtimeNodePathExists = runtimeNodePathIsDestination;
+ if (runtimeNodePathSource) {
+ runtimeNodePathExists = Boolean(
+ runtimeNodePathDestination && replacementComponentMatches,
+ );
runtimeNodePathNeedsRefresh =
- runtimeNodePathWasInserted || runtimeNodePathWasUpdated;
- } else if (runtimeNodePathIsDestination) {
+ runtimeNodePathExists &&
+ (runtimeNodePathWasInserted || runtimeNodePathWasUpdated);
+ } else if (runtimeNodePathDestination) {
runtimeNodePathExists = true;
runtimeNodePathNeedsRefresh =
runtimeNodePathWasInserted || runtimeNodePathWasUpdated;
diff --git a/packages/studio/src/test/sequence-props-observer.test.tsx b/packages/studio/src/test/sequence-props-observer.test.tsx
index 732787b390..9156ecd6da 100644
--- a/packages/studio/src/test/sequence-props-observer.test.tsx
+++ b/packages/studio/src/test/sequence-props-observer.test.tsx
@@ -113,9 +113,24 @@ test('refreshes prop statuses for inserted and in-place updated nodes', () => {
{
absolutePath,
remappings: [
- {oldNodePath: [...originalPath], newNodePath: [...originalPath]},
- {oldNodePath: [...insertedPath], newNodePath: [...shiftedPath]},
- {oldNodePath: null, newNodePath: [...insertedPath]},
+ {
+ oldNodePath: [...originalPath],
+ newNodePath: [...originalPath],
+ oldJsxName: 'Card',
+ newJsxName: 'Card',
+ },
+ {
+ oldNodePath: [...insertedPath],
+ newNodePath: [...shiftedPath],
+ oldJsxName: 'Card',
+ newJsxName: 'Card',
+ },
+ {
+ oldNodePath: null,
+ newNodePath: [...insertedPath],
+ oldJsxName: null,
+ newJsxName: 'Card',
+ },
],
},
],
@@ -176,6 +191,98 @@ test('refreshes prop statuses for inserted and in-place updated nodes', () => {
}
});
+test('moves an override when a different JSX component takes over its old path', () => {
+ const absolutePath = '/project/src/Composition.tsx';
+ const originalCaptionsPath = ['body', 3] as const;
+ const movedCaptionsPath = ['body', 5] as const;
+ const originalNodePath: SequencePropsSubscriptionKey = {
+ absolutePath,
+ effectKeys: [],
+ nodePath: [...originalCaptionsPath],
+ sequenceKeys: ['captions', 'from', 'durationInFrames', 'trimBefore'],
+ videoConfigValues: null,
+ };
+ const movedNodePath: SequencePropsSubscriptionKey = {
+ ...originalNodePath,
+ nodePath: [...movedCaptionsPath],
+ };
+ const refreshedOverrideIds: string[] = [];
+ const setOverrideCalls: Array<{
+ overrideId: string;
+ nodePath: SequencePropsSubscriptionKey | null;
+ }> = [];
+ const unsubscribeRefresh = subscribeToSequencePropsRefresh(
+ 'captions-override',
+ () => refreshedOverrideIds.push('captions-override'),
+ );
+
+ queueSequenceNodePathMutation({
+ mutationId: 'different-component-at-old-path-test',
+ timelineSelection: null,
+ files: [
+ {
+ absolutePath,
+ remappings: [
+ {
+ oldNodePath: [...originalCaptionsPath],
+ newNodePath: [...movedCaptionsPath],
+ oldJsxName: 'BasicCaptions',
+ newJsxName: 'BasicCaptions',
+ },
+ {
+ oldNodePath: null,
+ newNodePath: [...originalCaptionsPath],
+ oldJsxName: null,
+ newJsxName: 'Video',
+ },
+ ],
+ },
+ ],
+ });
+
+ try {
+ render(
+ <ObserverTestProviders
+ values={{
+ fastRefresh: {
+ fastRefreshes: 1,
+ manualRefreshes: 0,
+ increaseManualRefreshes: () => undefined,
+ },
+ expandedTracksSetter: {
+ expandParentTracks: () => undefined,
+ toggleTrack: () => undefined,
+ migrateExpandedTracksForSubscriptionKey: () => undefined,
+ } as never,
+ overrideIdsGetter: {
+ overrideIdToNodePathMappings: {
+ 'captions-override': originalNodePath,
+ },
+ },
+ overrideIdsSetter: {
+ setOverrideIdToNodePath: (overrideId, nodePath) =>
+ setOverrideCalls.push({overrideId, nodePath}),
+ },
+ propStatusesRef: {current: {}},
+ visualModeSetters: {
+ remapPropStatuses: () => undefined,
+ setPropStatuses: () => undefined,
+ } as never,
+ }}
+ >
+ <SequencePropsObserver />
+ </ObserverTestProviders>,
+ );
+
+ expect(setOverrideCalls).toEqual([
+ {overrideId: 'captions-override', nodePath: movedNodePath},
+ ]);
+ expect(refreshedOverrideIds).toEqual(['captions-override']);
+ } finally {
+ unsubscribeRefresh();
+ }
+});
+
test('remaps selection and refreshes the subscription after a JSX node path changes', () => {
const absolutePath = '/project/src/BarChart.tsx';
const originalNodePath: SequencePropsSubscriptionKey = {