Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Fix selection of inserted compositions after Fast Refresh

JonnyBurgere27e0a9b3d48
diff --git a/packages/browser-studio/e2e/browser-studio.test.ts b/packages/browser-studio/e2e/browser-studio.test.ts
index 22401b43e7..3cf49b9190 100644
--- a/packages/browser-studio/e2e/browser-studio.test.ts
+++ b/packages/browser-studio/e2e/browser-studio.test.ts
@@ -82,6 +82,46 @@ test('runs Browser Studio in Safari', async ({page}) => {
).toBeVisible();
});
+test('selects a composition inserted from the Add composition dialog', async ({
+ page,
+}) => {
+ await page.goto('/');
+ const studio = page.frameLocator('iframe');
+ const composition = studio.locator('[data-compname="MyComp"]');
+ await expect(composition).toBeVisible();
+ await studio.getByRole('button', {name: 'More composition actions'}).click();
+ await studio
+ .getByRole('button', {name: 'New composition...', exact: true})
+ .click();
+ await studio.getByPlaceholder('Composition ID').fill('MyComp1');
+ await studio.getByRole('button', {name: /^Add to /}).click();
+ await expect(studio.locator('[data-compname="MyComp1"]')).toBeVisible();
+
+ await page.goBack();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/MyComp');
+ await studio.locator('[data-sidebar-toggle="right"]').click();
+ await studio.getByRole('button', {name: 'Add composition...'}).click();
+ await studio.getByPlaceholder('Search compositions...').fill('MyComp1');
+ await page.keyboard.press('Enter');
+
+ await expect
+ .poll(() =>
+ page.evaluate(() => {
+ const browserWindow = window as typeof window & {
+ __browserStudioProject: {files: Record<string, string>};
+ };
+ return browserWindow.__browserStudioProject.files[
+ '/project/src/Composition.tsx'
+ ];
+ }),
+ )
+ .toContain('name="MyComp1"');
+ const insertedComposition = studio
+ .locator('[data-timeline-marquee-item]')
+ .first();
+ await expect(insertedComposition).toHaveCSS('opacity', '1');
+});
+
test('loads Browser Studio, opens external links, and can add, delete, and duplicate', async ({
page,
}) => {
diff --git a/packages/browser-studio/src/browser-studio-operations.ts b/packages/browser-studio/src/browser-studio-operations.ts
index e261a8c810..4ed2524662 100644
--- a/packages/browser-studio/src/browser-studio-operations.ts
+++ b/packages/browser-studio/src/browser-studio-operations.ts
@@ -634,6 +634,7 @@ export const createBrowserStudioOperations = ({
effectMutations,
});
controller.applyMutation({
+ timelineSelection: null,
fileName: label,
mutate: () => result.project,
nodePathMutationFiles: null,
@@ -888,6 +889,7 @@ export const createBrowserStudioOperations = ({
sequenceNodePath: request.sequenceNodePath.nodePath,
});
controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
mutate: () => ({
@@ -950,6 +952,7 @@ export const createBrowserStudioOperations = ({
})),
);
controller.applyMutation({
+ timelineSelection: null,
fileName: updates.map((update) => update.absolutePath).join(', '),
nodePathMutationFiles: null,
mutate: () => ({
@@ -1008,6 +1011,7 @@ export const createBrowserStudioOperations = ({
})),
);
controller.applyMutation({
+ timelineSelection: null,
fileName: updates.map((update) => update.absolutePath).join(', '),
nodePathMutationFiles: null,
mutate: () => ({
@@ -1058,6 +1062,7 @@ export const createBrowserStudioOperations = ({
type: request.type,
});
controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
mutate: () => ({
@@ -1085,6 +1090,7 @@ export const createBrowserStudioOperations = ({
toIndex: request.toIndex,
});
controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
mutate: () => ({
@@ -1133,6 +1139,7 @@ export const createBrowserStudioOperations = ({
files: {...project.files, [absolutePath]: result.output},
};
controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
mutate: () => nextProject,
@@ -1190,6 +1197,7 @@ export const createBrowserStudioOperations = ({
files: {...project.files, ...Object.fromEntries(outputByPath)},
};
controller.applyMutation({
+ timelineSelection: null,
fileName: request.undoLabel,
nodePathMutationFiles: null,
mutate: () => nextProject,
@@ -1237,6 +1245,7 @@ export const createBrowserStudioOperations = ({
project,
});
controller.applyMutation({
+ timelineSelection: null,
fileName: 'Install packages',
mutate: () => nextProject,
nodePathMutationFiles: null,
@@ -1291,6 +1300,7 @@ export const createBrowserStudioOperations = ({
},
};
const nodePathMutation = controller.applyMutation({
+ timelineSelection: null,
fileName: updates.map(({fileName}) => fileName).join(', '),
mutate: () => nextProject,
nodePathMutationFiles: updates.map(({fileName, result}) => ({
@@ -1355,6 +1365,7 @@ export const createBrowserStudioOperations = ({
},
};
const nodePathMutation = controller.applyMutation({
+ timelineSelection: null,
fileName: updates.map(({fileName}) => fileName).join(', '),
mutate: () => nextProject,
nodePathMutationFiles: updates.map(({fileName, result}) => ({
@@ -1391,6 +1402,7 @@ export const createBrowserStudioOperations = ({
splitFrame,
});
const nodePathMutation = controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
mutate: () => ({
...project,
@@ -1473,6 +1485,7 @@ export const createBrowserStudioOperations = ({
if (!dryRun) {
controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
mutate: () => ({...project, files}),
@@ -1508,6 +1521,7 @@ export const createBrowserStudioOperations = ({
formatFile: formatCodemodFile,
});
const nodePathMutation = controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
mutate: () => ({
...project,
@@ -1811,6 +1825,7 @@ export const createBrowserStudioOperations = ({
if (!dryRun) {
controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
mutate: () => ({
@@ -1851,6 +1866,7 @@ export const createBrowserStudioOperations = ({
formatInline,
});
controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
mutate: () => ({
@@ -1880,6 +1896,7 @@ export const createBrowserStudioOperations = ({
formatFile: formatCodemodFile,
});
const nodePathMutation = controller.applyMutation({
+ timelineSelection: null,
fileName: absolutePath,
mutate: () => ({
...project,
@@ -1930,6 +1947,14 @@ export const createBrowserStudioOperations = ({
wrapInSequence: null,
});
const nodePathMutation = controller.applyMutation({
+ timelineSelection:
+ result.insertedNodePath === null
+ ? null
+ : {
+ absolutePath: result.filePath,
+ compositionId: request.compositionId,
+ nodePath: result.insertedNodePath,
+ },
fileName: result.filePath,
mutate: () => result.project,
nodePathMutationFiles: [
@@ -2116,6 +2141,7 @@ export const createBrowserStudioOperations = ({
project: projectWithElement,
});
const nodePathMutation = controller.applyMutation({
+ timelineSelection: null,
fileName: insertion.filePath,
mutate: () => nextProject,
nodePathMutationFiles: [
@@ -2249,6 +2275,7 @@ export const createBrowserStudioOperations = ({
const firstTarget = request.edits[0] ?? request.captionPatches?.[0];
controller.applyMutation({
+ timelineSelection: null,
fileName:
firstTarget?.fileName ??
sequenceMutations[0]?.fileName ??
diff --git a/packages/browser-studio/src/browser-studio-project-controller.ts b/packages/browser-studio/src/browser-studio-project-controller.ts
index ed8ae6548f..8f3ad5ce8a 100644
--- a/packages/browser-studio/src/browser-studio-project-controller.ts
+++ b/packages/browser-studio/src/browser-studio-project-controller.ts
@@ -33,6 +33,7 @@ type ProjectMutation = {
fileName: string;
mutate: (project: VirtualProject) => VirtualProject;
nodePathMutationFiles: ProjectNodePathMutationFiles | null;
+ timelineSelection: SequenceNodePathMutation['timelineSelection'];
};
const MAX_HISTORY_ENTRIES = 100;
@@ -489,10 +490,12 @@ export const createBrowserStudioProjectController = ({
previousProject,
nextProject,
nodePathMutationFiles,
+ timelineSelection,
}: {
previousProject: VirtualProject;
nextProject: VirtualProject;
nodePathMutationFiles: ProjectNodePathMutationFiles | null;
+ timelineSelection: SequenceNodePathMutation['timelineSelection'];
}): SequenceNodePathMutation | null => {
const publicFilesChanged = updatePublicFileRevisions(
previousProject,
@@ -502,6 +505,7 @@ export const createBrowserStudioProjectController = ({
? {
mutationId: `${nodePathMutationSessionId}:${++nodePathMutationCounter}`,
files: nodePathMutationFiles,
+ timelineSelection,
}
: null;
if (nodePathMutation) {
@@ -523,6 +527,7 @@ export const createBrowserStudioProjectController = ({
fileName,
mutate,
nodePathMutationFiles,
+ timelineSelection,
}: ProjectMutation) => {
const before = getProject();
const after = mutate(before);
@@ -549,6 +554,7 @@ export const createBrowserStudioProjectController = ({
previousProject: before,
nextProject: after,
nodePathMutationFiles,
+ timelineSelection,
});
queueProjectGarbageCollections(discardedProjects);
@@ -575,6 +581,7 @@ export const createBrowserStudioProjectController = ({
previousProject: getProject(),
nextProject: entry.before,
nodePathMutationFiles: files ?? null,
+ timelineSelection: null,
});
return Promise.resolve({success: true, nodePathMutation});
};
@@ -590,6 +597,7 @@ export const createBrowserStudioProjectController = ({
previousProject: getProject(),
nextProject: entry.after,
nodePathMutationFiles: entry.nodePathMutationFiles,
+ timelineSelection: null,
});
return Promise.resolve({success: true, nodePathMutation});
};
@@ -608,6 +616,7 @@ export const createBrowserStudioProjectController = ({
applyMutation({
fileName: canonicalPath,
nodePathMutationFiles: null,
+ timelineSelection: null,
mutate: (project) => {
const nextPublicFiles = getCanonicalPublicFiles(project);
delete nextPublicFiles[canonicalPath];
@@ -664,6 +673,7 @@ export const createBrowserStudioProjectController = ({
applyMutation({
fileName: oldPath,
nodePathMutationFiles: null,
+ timelineSelection: null,
mutate: (project) => {
const nextPublicFiles = getCanonicalPublicFiles(project);
nextPublicFiles[newPath] = nextPublicFiles[oldPath];
@@ -716,6 +726,7 @@ export const createBrowserStudioProjectController = ({
applyMutation({
fileName: canonicalPath,
nodePathMutationFiles: null,
+ timelineSelection: null,
mutate: (project) => ({
...project,
publicFileStorage: storage ?? project.publicFileStorage,
diff --git a/packages/browser-studio/src/virtual-files.ts b/packages/browser-studio/src/virtual-files.ts
index d1b75dd9f8..41829ee4a6 100644
--- a/packages/browser-studio/src/virtual-files.ts
+++ b/packages/browser-studio/src/virtual-files.ts
@@ -38,6 +38,25 @@ const getInjectedReactRefreshFiles = () => {
return __BROWSER_STUDIO_REACT_REFRESH_FILES__;
};
+const notifyOnRefresh = `import {REACT_REFRESH_FINISHED_EVENT} from '@remotion/studio-shared';
+
+const RemotionRefreshRuntime = require('react-refresh/runtime');
+RemotionRefreshRuntime.__remotionReactRefreshWrapped ??= null;
+
+if (RemotionRefreshRuntime.__remotionReactRefreshWrapped === null) {
+ const originalPerformReactRefresh = RemotionRefreshRuntime.performReactRefresh;
+ RemotionRefreshRuntime.__remotionReactRefreshWrapped = true;
+ RemotionRefreshRuntime.performReactRefresh = () => {
+ const result = originalPerformReactRefresh();
+ if (result !== null) {
+ window.dispatchEvent(new Event(REACT_REFRESH_FINISHED_EVENT));
+ }
+
+ return result;
+ };
+}
+`;
+
const setupSequenceStackTraces = `import React from 'react';
import * as RefreshRuntime from 'react-refresh/runtime';
import {Internals} from 'remotion';
@@ -167,7 +186,7 @@ export const getBrowserStudioVirtualFiles = (): Record<string, string> => {
return {
[browserStudioVirtualFilePaths.browserRequireShim]: browserRequireShim,
- [browserStudioVirtualFilePaths.reactRefreshEntry]: reactRefreshFiles.entry,
+ [browserStudioVirtualFilePaths.reactRefreshEntry]: `${reactRefreshFiles.entry}\n${notifyOnRefresh}`,
[browserStudioVirtualFilePaths.reactRefreshRuntime]:
reactRefreshFiles.runtime,
[browserStudioVirtualFilePaths.reactRefreshUtils]: reactRefreshFiles.utils,
diff --git a/packages/example/e2e/studio.test.mts b/packages/example/e2e/studio.test.mts
index ba292b8365..cd0d088df7 100644
--- a/packages/example/e2e/studio.test.mts
+++ b/packages/example/e2e/studio.test.mts
@@ -4268,4 +4268,55 @@ export const SequenceShiftRepro = () => {
);
expect(shortVideoTag).toContain('from={45}');
});
+
+ test('should select an added composition before the codemod response arrives', async ({
+ page,
+ }) => {
+ await page.goto(`${STUDIO_URL}/effect-keyframe-e2e`);
+ await expect(
+ page.getByRole('button', {name: '0', exact: true}),
+ ).toBeVisible({timeout: 15_000});
+ if (!(await page.getByRole('button', {name: 'Inspector'}).isVisible())) {
+ await page.locator('[data-sidebar-toggle="right"]').click();
+ }
+
+ let releaseResponse = () => undefined;
+ const responseCanBeReleased = new Promise<void>((resolve) => {
+ releaseResponse = resolve;
+ });
+ let markResponseAsHeld = () => undefined;
+ const responseIsHeld = new Promise<void>((resolve) => {
+ markResponseAsHeld = resolve;
+ });
+ let markResponseAsReleased = () => undefined;
+ const responseIsReleased = new Promise<void>((resolve) => {
+ markResponseAsReleased = resolve;
+ });
+ await page.route('**/api/insert-jsx-element', async (route) => {
+ const response = await route.fetch();
+ markResponseAsHeld();
+ await responseCanBeReleased;
+ await route.fulfill({response});
+ markResponseAsReleased();
+ });
+
+ try {
+ await page.getByRole('button', {name: 'Add composition...'}).click();
+ await page
+ .getByPlaceholder('Search compositions...')
+ .fill('package-absolute-fill');
+ await page.keyboard.press('Enter');
+ await responseIsHeld;
+
+ await expect(
+ page.locator(
+ '[data-timeline-marquee-item][title="package-absolute-fill"]',
+ ),
+ ).toHaveCSS('opacity', '1', {timeout: 30_000});
+ } finally {
+ releaseResponse();
+ await responseIsReleased;
+ await page.unroute('**/api/insert-jsx-element');
+ }
+ });
});
diff --git a/packages/studio-server/src/preview-server/routes/delete-jsx-node.ts b/packages/studio-server/src/preview-server/routes/delete-jsx-node.ts
index a3bec79ef3..332dd68008 100644
--- a/packages/studio-server/src/preview-server/routes/delete-jsx-node.ts
+++ b/packages/studio-server/src/preview-server/routes/delete-jsx-node.ts
@@ -94,6 +94,7 @@ export const deleteJsxNodeHandler: ApiHandler<
absolutePath: update.absolutePath,
remappings: update.nodePathRemappings,
})),
+ null,
);
for (const update of updates) {
diff --git a/packages/studio-server/src/preview-server/routes/duplicate-jsx-node.ts b/packages/studio-server/src/preview-server/routes/duplicate-jsx-node.ts
index 68ce824bba..77e15c73e0 100644
--- a/packages/studio-server/src/preview-server/routes/duplicate-jsx-node.ts
+++ b/packages/studio-server/src/preview-server/routes/duplicate-jsx-node.ts
@@ -74,6 +74,7 @@ export const duplicateJsxNodeHandler: ApiHandler<
absolutePath: update.absolutePath,
remappings: update.nodePathRemappings,
})),
+ null,
);
const duplicatedNodeDescription =
nodes.length === 1
diff --git a/packages/studio-server/src/preview-server/routes/insert-element.ts b/packages/studio-server/src/preview-server/routes/insert-element.ts
index 981dc4ac84..5a82899d7e 100644
--- a/packages/studio-server/src/preview-server/routes/insert-element.ts
+++ b/packages/studio-server/src/preview-server/routes/insert-element.ts
@@ -205,12 +205,15 @@ export const insertElementHandler: ApiHandler<
throw new Error('Element source changed during installation');
}
- const nodePathMutation = broadcastSequenceNodePathMutation([
- {
- absolutePath: inserted.fileName,
- remappings: inserted.nodePathRemappings,
- },
- ]);
+ const nodePathMutation = broadcastSequenceNodePathMutation(
+ [
+ {
+ absolutePath: inserted.fileName,
+ remappings: inserted.nodePathRemappings,
+ },
+ ],
+ null,
+ );
pushTransactionToUndoStack({
snapshots: [
diff --git a/packages/studio-server/src/preview-server/routes/insert-jsx-element.ts b/packages/studio-server/src/preview-server/routes/insert-jsx-element.ts
index cf9c7f472e..040a795527 100644
--- a/packages/studio-server/src/preview-server/routes/insert-jsx-element.ts
+++ b/packages/studio-server/src/preview-server/routes/insert-jsx-element.ts
@@ -258,12 +258,21 @@ export const insertJsxElementHandler: ApiHandler<
from,
prettierConfigOverride: null,
});
- const nodePathMutation = broadcastSequenceNodePathMutation([
- {
- absolutePath: fileName,
- remappings: nodePathRemappings,
- },
- ]);
+ const nodePathMutation = broadcastSequenceNodePathMutation(
+ [
+ {
+ absolutePath: fileName,
+ remappings: nodePathRemappings,
+ },
+ ],
+ insertedNodePath === null
+ ? null
+ : {
+ absolutePath: fileName,
+ compositionId,
+ nodePath: insertedNodePath,
+ },
+ );
if (insertedNodePath === null) {
RenderInternals.Log.warn(
{indent: false, logLevel},
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 1b6c5030ec..c1019d2468 100644
--- a/packages/studio-server/src/preview-server/routes/reorder-sequence.ts
+++ b/packages/studio-server/src/preview-server/routes/reorder-sequence.ts
@@ -51,12 +51,15 @@ export const reorderSequenceHandler: ApiHandler<
targetNodePath: targetNodePath.nodePath,
position,
});
- const nodePathMutation = broadcastSequenceNodePathMutation([
- {
- absolutePath,
- remappings: nodePathRemappings,
- },
- ]);
+ const nodePathMutation = broadcastSequenceNodePathMutation(
+ [
+ {
+ absolutePath,
+ remappings: nodePathRemappings,
+ },
+ ],
+ null,
+ );
pushToUndoStack({
filePath: absolutePath,
diff --git a/packages/studio-server/src/preview-server/routes/split-jsx-sequence.ts b/packages/studio-server/src/preview-server/routes/split-jsx-sequence.ts
index a9f5fc3963..1bf1667dcf 100644
--- a/packages/studio-server/src/preview-server/routes/split-jsx-sequence.ts
+++ b/packages/studio-server/src/preview-server/routes/split-jsx-sequence.ts
@@ -49,12 +49,15 @@ export const splitJsxSequenceHandler: ApiHandler<
sequenceKeys,
splitFrame,
});
- const nodePathMutation = broadcastSequenceNodePathMutation([
- {
- absolutePath,
- remappings: nodePathRemappings,
- },
- ]);
+ const nodePathMutation = broadcastSequenceNodePathMutation(
+ [
+ {
+ absolutePath,
+ remappings: nodePathRemappings,
+ },
+ ],
+ null,
+ );
pushToUndoStack({
filePath: absolutePath,
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 fd5ed483ef..e5c614435a 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
@@ -44,12 +44,15 @@ export const splitVideoFromAudioHandler: ApiHandler<
input: fileContents,
nodePath,
});
- const nodePathMutation = broadcastSequenceNodePathMutation([
- {
- absolutePath,
- remappings: nodePathRemappings,
- },
- ]);
+ const nodePathMutation = broadcastSequenceNodePathMutation(
+ [
+ {
+ absolutePath,
+ remappings: nodePathRemappings,
+ },
+ ],
+ null,
+ );
pushToUndoStack({
filePath: absolutePath,
diff --git a/packages/studio-server/src/preview-server/sequence-node-path-mutation.ts b/packages/studio-server/src/preview-server/sequence-node-path-mutation.ts
index 475e23e367..15b9665dd1 100644
--- a/packages/studio-server/src/preview-server/sequence-node-path-mutation.ts
+++ b/packages/studio-server/src/preview-server/sequence-node-path-mutation.ts
@@ -13,10 +13,12 @@ export const broadcastSequenceNodePathMutation = (
absolutePath: string;
remappings: SequenceNodePathRemapping[];
}>,
+ timelineSelection: SequenceNodePathMutation['timelineSelection'],
): SequenceNodePathMutation => {
mutationCounter++;
const mutation: SequenceNodePathMutation = {
mutationId: `${mutationSessionId}:${mutationCounter}`,
+ timelineSelection,
files,
};
diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.ts
index 144c8cf978..990ca3fbaa 100644
--- a/packages/studio-server/src/preview-server/undo-stack.ts
+++ b/packages/studio-server/src/preview-server/undo-stack.ts
@@ -455,7 +455,7 @@ export function popUndo(): UndoResponse {
];
});
const nodePathMutation =
- files.length === 0 ? null : broadcastSequenceNodePathMutation(files);
+ files.length === 0 ? null : broadcastSequenceNodePathMutation(files, null);
for (const snapshot of entry.snapshots) {
suppressUndoStackInvalidation(snapshot.filePath);
@@ -547,7 +547,7 @@ export function popRedo(): RedoResponse {
];
});
const nodePathMutation =
- files.length === 0 ? null : broadcastSequenceNodePathMutation(files);
+ files.length === 0 ? null : broadcastSequenceNodePathMutation(files, null);
for (const snapshot of snapshotsWithNewContents) {
suppressUndoStackInvalidation(snapshot.filePath);
diff --git a/packages/studio-server/src/test/jsx-node-path-mutation-routes.test.ts b/packages/studio-server/src/test/jsx-node-path-mutation-routes.test.ts
index 04e2e15e6c..7e33f76299 100644
--- a/packages/studio-server/src/test/jsx-node-path-mutation-routes.test.ts
+++ b/packages/studio-server/src/test/jsx-node-path-mutation-routes.test.ts
@@ -230,6 +230,15 @@ test('JSX structure routes broadcast and return node path mutations before writi
assertMutation({before, mutation: insertResponse.nodePathMutation});
forwardMutationFiles.push(insertResponse.nodePathMutation.files);
+ if (insertResponse.insertedNodePath === null) {
+ throw new Error('Expected the inserted node path');
+ }
+
+ expect(insertResponse.nodePathMutation.timelineSelection).toEqual({
+ absolutePath: filePath,
+ compositionId: 'insert',
+ nodePath: insertResponse.insertedNodePath.nodePath,
+ });
for (let i = 0; i < 4; i++) {
before = readFileSync(filePath, 'utf-8');
@@ -241,6 +250,7 @@ test('JSX structure routes broadcast and return node path mutations before writi
expect(undoResponse.nodePathMutation.files).toEqual(
invertMutationFiles(forwardMutationFiles[3 - i]),
);
+ expect(undoResponse.nodePathMutation.timelineSelection).toBeNull();
assertMutation({before, mutation: undoResponse.nodePathMutation});
}
@@ -256,6 +266,7 @@ test('JSX structure routes broadcast and return node path mutations before writi
expect(redoResponse.nodePathMutation.files).toEqual(
forwardMutationFiles[i],
);
+ expect(redoResponse.nodePathMutation.timelineSelection).toBeNull();
assertMutation({before, mutation: redoResponse.nodePathMutation});
}
} finally {
diff --git a/packages/studio-shared/src/sequence-node-path-mutation.ts b/packages/studio-shared/src/sequence-node-path-mutation.ts
index 054b2e8f51..78a3bfe2a4 100644
--- a/packages/studio-shared/src/sequence-node-path-mutation.ts
+++ b/packages/studio-shared/src/sequence-node-path-mutation.ts
@@ -9,6 +9,11 @@ export type SequenceNodePathRemapping = {
export type SequenceNodePathMutation = {
mutationId: string;
+ timelineSelection: {
+ compositionId: string;
+ absolutePath: string;
+ nodePath: SequenceNodePath;
+ } | null;
files: Array<{
absolutePath: string;
remappings: SequenceNodePathRemapping[];
diff --git a/packages/studio/src/components/import-assets.ts b/packages/studio/src/components/import-assets.ts
index d6cf56d171..d40495a0f5 100644
--- a/packages/studio/src/components/import-assets.ts
+++ b/packages/studio/src/components/import-assets.ts
@@ -701,14 +701,6 @@ const insertCompositionElement = async ({
return false;
}
- if (result.insertedNodePath !== null) {
- requestInsertedElementSelection({
- compositionId,
- nodePath: result.insertedNodePath,
- notification: null,
- });
- }
-
return true;
};
diff --git a/packages/studio/src/helpers/sequence-node-path-mutations.ts b/packages/studio/src/helpers/sequence-node-path-mutations.ts
index d4a8a131e4..6621f5a4d6 100644
--- a/packages/studio/src/helpers/sequence-node-path-mutations.ts
+++ b/packages/studio/src/helpers/sequence-node-path-mutations.ts
@@ -1,4 +1,5 @@
import type {SequenceNodePathMutation} from '@remotion/studio-shared';
+import {requestInsertedElementSelection} from './inserted-element-selection';
const pendingMutations: SequenceNodePathMutation[] = [];
const seenMutationIds = new Set<string>();
@@ -12,6 +13,16 @@ export const queueSequenceNodePathMutation = (
seenMutationIds.add(mutation.mutationId);
pendingMutations.push(mutation);
+ if (mutation.timelineSelection !== null) {
+ requestInsertedElementSelection({
+ compositionId: mutation.timelineSelection.compositionId,
+ nodePath: {
+ absolutePath: mutation.timelineSelection.absolutePath,
+ nodePath: mutation.timelineSelection.nodePath,
+ },
+ notification: null,
+ });
+ }
};
export const queueSequenceNodePathMutationFromApiResponse = (
diff --git a/packages/studio/src/test/browser-studio-duplicate-jsx-node.test.ts b/packages/studio/src/test/browser-studio-duplicate-jsx-node.test.ts
index 697201efb3..4771390fe8 100644
--- a/packages/studio/src/test/browser-studio-duplicate-jsx-node.test.ts
+++ b/packages/studio/src/test/browser-studio-duplicate-jsx-node.test.ts
@@ -28,7 +28,11 @@ test('routes JSX duplication through Browser Studio', async () => {
receivedRequests.push(request);
return Promise.resolve({
success: true,
- nodePathMutation: {files: [], mutationId: 'test-mutation'},
+ nodePathMutation: {
+ files: [],
+ mutationId: 'test-mutation',
+ timelineSelection: null,
+ },
});
},
}),
diff --git a/packages/studio/src/test/sequence-props-observer.test.tsx b/packages/studio/src/test/sequence-props-observer.test.tsx
index 4d9369b6e4..2718b19b85 100644
--- a/packages/studio/src/test/sequence-props-observer.test.tsx
+++ b/packages/studio/src/test/sequence-props-observer.test.tsx
@@ -47,6 +47,7 @@ test('refreshes prop statuses for inserted and in-place updated nodes', () => {
queueSequenceNodePathMutation({
mutationId: 'inserted-runtime-path-test',
+ timelineSelection: null,
files: [
{
absolutePath,