Skip to content

🎥 Make videos programmatically with React

Restore composition navigation on undo and redo

Igor Samokhovets3b4b6ae74b89
diff --git a/packages/browser-studio/e2e/browser-studio.test.ts b/packages/browser-studio/e2e/browser-studio.test.ts
index 842440141d..603a29bb8c 100644
--- a/packages/browser-studio/e2e/browser-studio.test.ts
+++ b/packages/browser-studio/e2e/browser-studio.test.ts
@@ -393,6 +393,84 @@ test('loads Browser Studio, opens external links, and can add, delete, and dupli
}),
)
.toContain('id="MyComp1"');
+
+ await studio.getByRole('button', {name: /^Undo/}).click();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/MyComp');
+ await expect
+ .poll(() =>
+ page.evaluate(() => {
+ const browserWindow = window as typeof window & {
+ __browserStudioProject: {files: Record<string, string>};
+ };
+ return browserWindow.__browserStudioProject.files[
+ '/project/src/Composition.tsx'
+ ];
+ }),
+ )
+ .not.toContain('id="MyComp1"');
+
+ await studio.getByRole('button', {name: /^Redo/}).click();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/MyComp1');
+ await expect(page).toHaveTitle(
+ 'MyComp1 / template-blank - Remotion Studio',
+ {timeout: 5000},
+ );
+ 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('id="MyComp1"');
+
+ const duplicatedComposition = studio.locator('[data-compname="MyComp1"]');
+ await duplicatedComposition.click({button: 'right'});
+ await studio.getByText('Delete...', {exact: true}).click();
+ await expect(studio.getByText('Delete composition')).toBeVisible();
+ await studio.getByRole('button', {name: /^Delete from /}).click();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/MyComp');
+ await expect
+ .poll(() =>
+ page.evaluate(() => {
+ const browserWindow = window as typeof window & {
+ __browserStudioProject: {files: Record<string, string>};
+ };
+ return browserWindow.__browserStudioProject.files[
+ '/project/src/Composition.tsx'
+ ];
+ }),
+ )
+ .not.toContain('id="MyComp1"');
+
+ await studio.getByRole('button', {name: /^Undo/}).click();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/MyComp1');
+ await expect(duplicatedComposition).toBeVisible();
+
+ await studio.getByRole('button', {name: /^Redo/}).click();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/MyComp');
+ await expect(duplicatedComposition).toHaveCount(0);
+
+ await composition.click({button: 'right'});
+ await studio.getByText('Delete...', {exact: true}).click();
+ await studio.getByRole('button', {name: /^Delete from /}).click();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/');
+ await expect(composition).toHaveCount(0);
+ await expect(
+ studio.locator('.remotion-studio-composition-container'),
+ ).toHaveCount(0);
+
+ await studio.getByRole('button', {name: /^Undo/}).click();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/MyComp');
+ await expect(composition).toBeVisible();
+
+ await studio.getByRole('button', {name: /^Redo/}).click();
+ await expect.poll(() => new URL(page.url()).search).toBe('?/');
+ await expect(composition).toHaveCount(0);
})(),
pageError,
]);
diff --git a/packages/browser-studio/src/browser-studio-operations.ts b/packages/browser-studio/src/browser-studio-operations.ts
index 64cdec4d98..e1b9527d6e 100644
--- a/packages/browser-studio/src/browser-studio-operations.ts
+++ b/packages/browser-studio/src/browser-studio-operations.ts
@@ -633,6 +633,7 @@ export const createBrowserStudioOperations = ({
effectMutations,
});
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: label,
mutate: () => result.project,
@@ -887,6 +888,7 @@ export const createBrowserStudioOperations = ({
sequenceNodePath: request.sequenceNodePath.nodePath,
});
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
@@ -949,6 +951,7 @@ export const createBrowserStudioOperations = ({
})),
);
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: updates.map((update) => update.absolutePath).join(', '),
nodePathMutationFiles: null,
@@ -1007,6 +1010,7 @@ export const createBrowserStudioOperations = ({
})),
);
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: updates.map((update) => update.absolutePath).join(', '),
nodePathMutationFiles: null,
@@ -1057,6 +1061,7 @@ export const createBrowserStudioOperations = ({
type: request.type,
});
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
@@ -1084,6 +1089,7 @@ export const createBrowserStudioOperations = ({
toIndex: request.toIndex,
});
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
@@ -1132,6 +1138,7 @@ export const createBrowserStudioOperations = ({
files: {...project.files, [absolutePath]: result.output},
};
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
@@ -1189,6 +1196,7 @@ export const createBrowserStudioOperations = ({
files: {...project.files, ...Object.fromEntries(outputByPath)},
};
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: request.undoLabel,
nodePathMutationFiles: null,
@@ -1237,6 +1245,7 @@ export const createBrowserStudioOperations = ({
project,
});
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: 'Install packages',
mutate: () => nextProject,
@@ -1292,6 +1301,7 @@ export const createBrowserStudioOperations = ({
},
};
const nodePathMutation = controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: updates.map(({fileName}) => fileName).join(', '),
mutate: () => nextProject,
@@ -1357,6 +1367,7 @@ export const createBrowserStudioOperations = ({
},
};
const nodePathMutation = controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: updates.map(({fileName}) => fileName).join(', '),
mutate: () => nextProject,
@@ -1394,6 +1405,7 @@ export const createBrowserStudioOperations = ({
splitFrame,
});
const nodePathMutation = controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: absolutePath,
mutate: () => ({
@@ -1425,6 +1437,7 @@ export const createBrowserStudioOperations = ({
codemod,
dryRun,
symbolicatedStack,
+ undoRedoNavigation,
}) => {
try {
if (codemod.type === 'apply-visual-control') {
@@ -1471,6 +1484,7 @@ export const createBrowserStudioOperations = ({
if (!dryRun) {
controller.applyMutation({
+ undoRedoNavigation,
timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
@@ -1507,6 +1521,7 @@ export const createBrowserStudioOperations = ({
formatFile: formatCodemodFile,
});
const nodePathMutation = controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: absolutePath,
mutate: () => ({
@@ -1781,7 +1796,7 @@ export const createBrowserStudioOperations = ({
};
const duplicateComposition: BrowserStudioOperations['duplicateComposition'] =
- async ({codemod, dryRun}) => {
+ async ({codemod, dryRun, undoRedoNavigation}) => {
try {
const project = getProject();
const compositionFile = getCompositionFile({
@@ -1811,6 +1826,7 @@ export const createBrowserStudioOperations = ({
if (!dryRun) {
controller.applyMutation({
+ undoRedoNavigation,
timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
@@ -1852,6 +1868,7 @@ export const createBrowserStudioOperations = ({
formatInline,
});
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: absolutePath,
nodePathMutationFiles: null,
@@ -1882,6 +1899,7 @@ export const createBrowserStudioOperations = ({
formatFile: formatCodemodFile,
});
const nodePathMutation = controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName: absolutePath,
mutate: () => ({
@@ -1933,6 +1951,7 @@ export const createBrowserStudioOperations = ({
wrapInSequence: null,
});
const nodePathMutation = controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection:
result.insertedNodePath === null
? null
@@ -2196,6 +2215,7 @@ export const createBrowserStudioOperations = ({
}
const nodePathMutation = controller.applyMutation({
+ undoRedoNavigation: request.undoRedoNavigation,
timelineSelection: null,
fileName: insertion.filePath,
mutate: () => nextProject,
@@ -2330,6 +2350,7 @@ export const createBrowserStudioOperations = ({
const firstTarget = request.edits[0] ?? request.captionPatches?.[0];
controller.applyMutation({
+ undoRedoNavigation: null,
timelineSelection: null,
fileName:
firstTarget?.fileName ??
diff --git a/packages/browser-studio/src/browser-studio-project-controller.ts b/packages/browser-studio/src/browser-studio-project-controller.ts
index 8f3ad5ce8a..6e2f755891 100644
--- a/packages/browser-studio/src/browser-studio-project-controller.ts
+++ b/packages/browser-studio/src/browser-studio-project-controller.ts
@@ -5,6 +5,7 @@ import type {
RedoResponse,
SequenceNodePathMutation,
SequenceNodePathRemapping,
+ UndoRedoNavigation,
UndoResponse,
} from '@remotion/studio-shared';
import {
@@ -27,6 +28,7 @@ type HistoryEntry = {
after: VirtualProject;
fileName: string;
nodePathMutationFiles: ProjectNodePathMutationFiles | null;
+ undoRedoNavigation: UndoRedoNavigation | null;
};
type ProjectMutation = {
@@ -34,6 +36,7 @@ type ProjectMutation = {
mutate: (project: VirtualProject) => VirtualProject;
nodePathMutationFiles: ProjectNodePathMutationFiles | null;
timelineSelection: SequenceNodePathMutation['timelineSelection'];
+ undoRedoNavigation: UndoRedoNavigation | null;
};
const MAX_HISTORY_ENTRIES = 100;
@@ -528,6 +531,7 @@ export const createBrowserStudioProjectController = ({
mutate,
nodePathMutationFiles,
timelineSelection,
+ undoRedoNavigation,
}: ProjectMutation) => {
const before = getProject();
const after = mutate(before);
@@ -537,7 +541,13 @@ export const createBrowserStudioProjectController = ({
}
const discardedProjects: VirtualProject[] = [];
- undoStack.push({before, after, fileName, nodePathMutationFiles});
+ undoStack.push({
+ before,
+ after,
+ fileName,
+ nodePathMutationFiles,
+ undoRedoNavigation,
+ });
if (undoStack.length > MAX_HISTORY_ENTRIES) {
const discarded = undoStack.shift();
if (discarded) {
@@ -583,7 +593,11 @@ export const createBrowserStudioProjectController = ({
nodePathMutationFiles: files ?? null,
timelineSelection: null,
});
- return Promise.resolve({success: true, nodePathMutation});
+ return Promise.resolve({
+ success: true,
+ nodePathMutation,
+ route: entry.undoRedoNavigation?.undoRoute ?? null,
+ });
};
const redo = (): Promise<RedoResponse> => {
@@ -599,7 +613,11 @@ export const createBrowserStudioProjectController = ({
nodePathMutationFiles: entry.nodePathMutationFiles,
timelineSelection: null,
});
- return Promise.resolve({success: true, nodePathMutation});
+ return Promise.resolve({
+ success: true,
+ nodePathMutation,
+ route: entry.undoRedoNavigation?.redoRoute ?? null,
+ });
};
return {
@@ -617,6 +635,7 @@ export const createBrowserStudioProjectController = ({
fileName: canonicalPath,
nodePathMutationFiles: null,
timelineSelection: null,
+ undoRedoNavigation: null,
mutate: (project) => {
const nextPublicFiles = getCanonicalPublicFiles(project);
delete nextPublicFiles[canonicalPath];
@@ -674,6 +693,7 @@ export const createBrowserStudioProjectController = ({
fileName: oldPath,
nodePathMutationFiles: null,
timelineSelection: null,
+ undoRedoNavigation: null,
mutate: (project) => {
const nextPublicFiles = getCanonicalPublicFiles(project);
nextPublicFiles[newPath] = nextPublicFiles[oldPath];
@@ -727,6 +747,7 @@ export const createBrowserStudioProjectController = ({
fileName: canonicalPath,
nodePathMutationFiles: null,
timelineSelection: null,
+ undoRedoNavigation: null,
mutate: (project) => ({
...project,
publicFileStorage: storage ?? project.publicFileStorage,
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 ab3645b07a..8298a648e3 100644
--- a/packages/browser-studio/src/test/browser-studio-operations.test.ts
+++ b/packages/browser-studio/src/test/browser-studio-operations.test.ts
@@ -629,11 +629,13 @@ export const Root = () => <Composition id="MyComp" component={Component} duratio
expect(await operations.undo()).toEqual({
success: true,
nodePathMutation: null,
+ route: null,
});
expect(currentProject.files[fileName]).toContain('from={10}');
expect(await operations.redo()).toEqual({
success: true,
nodePathMutation: null,
+ route: null,
});
expect(currentProject.files[fileName]).toContain('from={15}');
@@ -675,6 +677,7 @@ export const Root = () => <Composition id="MyComp" component={Component} duratio
expect(await operations.undo()).toEqual({
success: true,
nodePathMutation: null,
+ route: null,
});
expect(currentProject.files[fileName]).not.toContain('style={{rotate:');
@@ -1152,6 +1155,7 @@ test('renames a composition by resolving the file from the composition id', asyn
newId: 'RenamedComp',
},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!result.success) {
@@ -1184,6 +1188,7 @@ test('updates composition metadata in Browser Studio', async () => {
newWidth: 1920,
},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!result.success) {
@@ -1206,6 +1211,7 @@ test('deletes a composition and supports a dry run', async () => {
const dryRunResult = await operations.applyCodemod({
codemod: {type: 'delete-composition', idToDelete: 'MyComp'},
dryRun: true,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!dryRunResult.success) {
@@ -1220,6 +1226,7 @@ test('deletes a composition and supports a dry run', async () => {
const result = await operations.applyCodemod({
codemod: {type: 'delete-composition', idToDelete: 'MyComp'},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!result.success) {
@@ -1252,6 +1259,7 @@ test('creates a composition with a component file in the root file', async () =>
const result = await operations.applyCodemod({
codemod,
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!result.success) {
@@ -1269,6 +1277,7 @@ test('creates a composition with a component file in the root file', async () =>
const conflict = await operations.applyCodemod({
codemod: {...codemod, newId: 'FreshComp2'},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
expect(conflict).toEqual({
@@ -1330,6 +1339,7 @@ test('imports a Canvas Capture as an interactive composition', async () => {
},
},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!result.success) {
@@ -1363,6 +1373,7 @@ test('creates, renames and deletes a folder in Browser Studio', async () => {
const createResult = await operations.applyCodemod({
codemod: {type: 'new-folder', folderName: 'my-folder', parentName: null},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!createResult.success) {
@@ -1381,6 +1392,7 @@ test('creates, renames and deletes a folder in Browser Studio', async () => {
newName: 'renamed-folder',
},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!renameResult.success) {
@@ -1398,6 +1410,7 @@ test('creates, renames and deletes a folder in Browser Studio', async () => {
parentName: null,
},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
});
if (!deleteResult.success) {
@@ -1441,6 +1454,7 @@ export const Root = () => {
parentName: null,
},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: {
originalFileName: 'src/Root.tsx',
originalFunctionName: null,
@@ -1707,6 +1721,7 @@ test('reports structured failures for unsupported codemods', async () => {
await operations.applyCodemod({
codemod: {type: 'apply-visual-control', changes: []},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
}),
).toEqual({
@@ -1718,6 +1733,7 @@ test('reports structured failures for unsupported codemods', async () => {
await operations.applyCodemod({
codemod: {type: 'delete-composition', idToDelete: 'MissingComp'},
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: null,
}),
).toEqual({
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 329ba0caad..2e7793faf7 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
@@ -188,11 +188,19 @@ test('mutates virtual files, emits events, and preserves undo and redo history',
});
expect(project.publicFiles?.['renamed.bin']).toBeUndefined();
- expect(await undo()).toEqual({success: true, nodePathMutation: null});
+ expect(await undo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(project.publicFiles?.['renamed.bin']).toEqual(
new Uint8Array([0, 127, 128, 255]),
);
- expect(await undo()).toEqual({success: true, nodePathMutation: null});
+ expect(await undo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(project.publicFiles?.['nested/upload.bin']).toEqual(
new Uint8Array([0, 127, 128, 255]),
);
@@ -270,11 +278,13 @@ test('downloads CORS-enabled remote assets and rejects failed cross-origin fetch
expect(await operations.undo()).toEqual({
nodePathMutation: null,
+ route: null,
success: true,
});
expect(project.publicFiles?.['remote-logo.gif']).toBeUndefined();
expect(await operations.redo()).toEqual({
nodePathMutation: null,
+ route: null,
success: true,
});
expect(project.publicFiles?.['remote-logo.gif']).toEqual(gif);
@@ -310,6 +320,10 @@ test('previews and duplicates compositions as an undoable project mutation', asy
resolveDependencies: null,
});
const request = {
+ undoRedoNavigation: {
+ undoRoute: '/MyComp',
+ redoRoute: '/MyCompCopy',
+ },
codemod: {
type: 'duplicate-composition' as const,
idToDuplicate: 'MyComp',
@@ -325,6 +339,7 @@ test('previews and duplicates compositions as an undoable project mutation', asy
const preview = await operations.duplicateComposition({
...request,
dryRun: true,
+ undoRedoNavigation: null,
});
expect(preview.success).toBe(true);
if (!preview.success) {
@@ -350,10 +365,20 @@ test('previews and duplicates compositions as an undoable project mutation', asy
expect(await operations.undo()).toEqual({
success: true,
nodePathMutation: null,
+ route: '/MyComp',
});
expect(project.files['/project/src/Composition.tsx']).toBe(
initialProject.files['/project/src/Composition.tsx'],
);
+ expect(await operations.redo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: '/MyCompCopy',
+ });
+ expect(project.files['/project/src/Composition.tsx']).toContain(
+ 'id="MyCompCopy"',
+ );
+ expect((await operations.undo()).success).toBe(true);
const failure = await operations.duplicateComposition({
...request,
@@ -452,6 +477,7 @@ export const LowerThird = () => <Rect width={640} height={180} />;
from: 12,
overwriteExisting: false,
position: {x: 24, y: 48},
+ undoRedoNavigation: null,
newComposition: null,
});
if (!inserted.success) {
@@ -506,6 +532,7 @@ export const LowerThird = () => <Rect width={640} height={180} />;
from: null,
overwriteExisting: false,
position: null,
+ undoRedoNavigation: null,
newComposition: null,
};
expect(await operations.insertElement(installRequest)).toMatchObject({
@@ -601,6 +628,10 @@ test('installs an Element into a new composition as one undoable mutation', asyn
from: null,
overwriteExisting: false,
position: null,
+ undoRedoNavigation: {
+ undoRoute: '/MyComp',
+ redoRoute: '/ElementScene',
+ },
newComposition: {
codemod: {
type: 'new-composition',
@@ -633,7 +664,10 @@ test('installs an Element into a new composition as one undoable mutation', asyn
);
const installedProject = project;
- expect((await operations.undo()).success).toBe(true);
+ expect(await operations.undo()).toMatchObject({
+ success: true,
+ route: '/MyComp',
+ });
expect(project.files['/project/src/Root.tsx']).toBe(
initialProject.files['/project/src/Root.tsx'],
);
@@ -646,7 +680,10 @@ test('installs an Element into a new composition as one undoable mutation', asyn
reason: 'Nothing to undo',
});
- expect((await operations.redo()).success).toBe(true);
+ expect(await operations.redo()).toMatchObject({
+ success: true,
+ route: '/ElementScene',
+ });
expect(areBrowserStudioProjectsEqual(project, installedProject)).toBe(true);
});
@@ -702,6 +739,7 @@ test('installs component-owned Element timing and initial props', async () => {
from: 30,
overwriteExisting: false,
position: {x: 24, y: 48},
+ undoRedoNavigation: null,
newComposition: null,
});
if (!inserted.success) {
@@ -786,6 +824,7 @@ test('rejects contradictory component-owned Element initial props', async () =>
from: 30,
overwriteExisting: false,
position: {x: 24, y: 48},
+ undoRedoNavigation: null,
newComposition: null,
});
@@ -834,6 +873,7 @@ test('installs packages as an undoable project mutation and reports structured f
expect(await operations.undo()).toEqual({
success: true,
nodePathMutation: null,
+ route: null,
});
expect(project.files['/project/package.json']).toBe(
initialProject.files['/project/package.json'],
@@ -841,6 +881,7 @@ test('installs packages as an undoable project mutation and reports structured f
expect(await operations.redo()).toEqual({
success: true,
nodePathMutation: null,
+ route: null,
});
expect(project.files['/project/package.json']).toContain(
'"@remotion/google-fonts": "4.0.999"',
diff --git a/packages/example/e2e/studio-protocol.test.mts b/packages/example/e2e/studio-protocol.test.mts
index 0a5d4370b6..96eb3b4a30 100644
--- a/packages/example/e2e/studio-protocol.test.mts
+++ b/packages/example/e2e/studio-protocol.test.mts
@@ -719,6 +719,10 @@ const CloseupPlaceholder = () => {
).toContainText('Protocol Element', {timeout: 30_000});
await studioPage.getByRole('button', {name: /^Undo/}).click();
+ await expect(studioPage).toHaveURL(`${studioUrl}/MyComp`, {
+ timeout: 30_000,
+ });
+ await expect(studioPage).toHaveTitle(/MyComp/);
await expect.poll(() => fs.existsSync(newCompositionFile)).toBe(false);
expect(fs.existsSync(newCompositionElementFile)).toBe(false);
expect(
@@ -726,6 +730,10 @@ const CloseupPlaceholder = () => {
).not.toContain('id="ProtocolElementScene"');
await studioPage.getByRole('button', {name: /^Redo/}).click();
+ await expect(studioPage).toHaveURL(`${studioUrl}/ProtocolElementScene`, {
+ timeout: 30_000,
+ });
+ await expect(studioPage).toHaveTitle(/ProtocolElementScene/);
await expect.poll(() => fs.existsSync(newCompositionFile)).toBe(true);
expect(fs.existsSync(newCompositionElementFile)).toBe(true);
expect(
diff --git a/packages/example/e2e/studio.test.mts b/packages/example/e2e/studio.test.mts
index fb5d3b8e13..bfa245e3bd 100644
--- a/packages/example/e2e/studio.test.mts
+++ b/packages/example/e2e/studio.test.mts
@@ -1443,6 +1443,7 @@ test.describe('visual mode', () => {
exampleDir,
'src/NewlyCreatedComposition.tsx',
);
+ const originalRootSource = fs.readFileSync(rootFile, 'utf8');
try {
await page.goto(`${STUDIO_URL}/schema-test`);
@@ -1495,12 +1496,36 @@ test.describe('visual mode', () => {
const compositionPosition = rootContents.indexOf(`id="${compositionId}"`);
expect(compositionPosition).toBeGreaterThan(folderStart);
expect(compositionPosition).toBeLessThan(folderEnd);
+ await expect.poll(() => fs.existsSync(compositionFile)).toBe(true);
+
+ await page.getByRole('button', {name: /^Undo/}).click();
+ await expect(page).toHaveURL(`${STUDIO_URL}/schema-test`, {
+ timeout: 15_000,
+ });
+ await expect(page).toHaveTitle(/schema-test/);
+ await expect
+ .poll(() => fs.readFileSync(rootFile, 'utf8'))
+ .toBe(originalRootSource);
+ await expect.poll(() => fs.existsSync(compositionFile)).toBe(false);
+
+ await page.getByRole('button', {name: /^Redo/}).click();
+ await expect(page).toHaveURL(`${STUDIO_URL}/${compositionId}`, {
+ timeout: 15_000,
+ });
+ await expect(page).toHaveTitle(new RegExp(compositionId));
+ await expect
+ .poll(() => fs.readFileSync(rootFile, 'utf8'))
+ .toContain(`id="${compositionId}"`);
+ await expect.poll(() => fs.existsSync(compositionFile)).toBe(true);
} finally {
const undoButton = page.getByRole('button', {name: /^Undo/});
if ((await undoButton.count()) > 0 && (await undoButton.isEnabled())) {
await undoButton.click();
await expect.poll(() => fs.existsSync(compositionFile)).toBe(false);
}
+
+ fs.writeFileSync(rootFile, originalRootSource);
+ fs.rmSync(compositionFile, {force: true});
}
});
diff --git a/packages/studio-server/src/preview-server/routes/add-keyframes.ts b/packages/studio-server/src/preview-server/routes/add-keyframes.ts
index c213d0823c..387e584b3b 100644
--- a/packages/studio-server/src/preview-server/routes/add-keyframes.ts
+++ b/packages/studio-server/src/preview-server/routes/add-keyframes.ts
@@ -278,6 +278,7 @@ export const addKeyframes = async ({
? 'sequence-props'
: 'effect-props',
suppressHmrOnFileRestore: true,
+ undoRedoNavigation: null,
});
for (const snapshot of snapshots) {
diff --git a/packages/studio-server/src/preview-server/routes/apply-codemod.ts b/packages/studio-server/src/preview-server/routes/apply-codemod.ts
index 298903f777..8d9c23f829 100644
--- a/packages/studio-server/src/preview-server/routes/apply-codemod.ts
+++ b/packages/studio-server/src/preview-server/routes/apply-codemod.ts
@@ -19,7 +19,6 @@ import {formatLogFileLocation} from '../format-log-file-location';
import {getProjectInfo} from '../project-info';
import {
printUndoHint,
- pushToUndoStack,
pushTransactionToUndoStack,
suppressUndoStackInvalidation,
} from '../undo-stack';
@@ -210,7 +209,7 @@ export const applyCodemodHandler: ApiHandler<
ApplyCodemodRequest,
ApplyCodemodResponse
> = ({
- input: {codemod, dryRun, symbolicatedStack},
+ input: {codemod, dryRun, symbolicatedStack, undoRedoNavigation},
logLevel,
remotionRoot,
entryPoint,
@@ -289,35 +288,21 @@ export const applyCodemodHandler: ApiHandler<
logLine: 1,
nodePathRemappings: null,
});
- pushTransactionToUndoStack({
- snapshots,
- logLevel,
- remotionRoot,
- description: {
- undoMessage,
- redoMessage,
- },
- entryType,
- suppressHmrOnFileRestore: false,
- });
- } else {
- pushToUndoStack({
- filePath,
- oldContents: input,
- newContents: null,
- logLevel,
- remotionRoot,
- logLine,
- description: {
- undoMessage,
- redoMessage,
- },
- entryType,
- suppressHmrOnFileRestore: false,
- nodePathRemappings: null,
- });
}
+ pushTransactionToUndoStack({
+ snapshots,
+ logLevel,
+ remotionRoot,
+ description: {
+ undoMessage,
+ redoMessage,
+ },
+ entryType,
+ suppressHmrOnFileRestore: false,
+ undoRedoNavigation,
+ });
+
suppressUndoStackInvalidation(filePath);
if (componentFilePath) {
suppressUndoStackInvalidation(componentFilePath);
diff --git a/packages/studio-server/src/preview-server/routes/batch-update-keyframe-settings.ts b/packages/studio-server/src/preview-server/routes/batch-update-keyframe-settings.ts
index 694efe79f9..b187ef7f9b 100644
--- a/packages/studio-server/src/preview-server/routes/batch-update-keyframe-settings.ts
+++ b/packages/studio-server/src/preview-server/routes/batch-update-keyframe-settings.ts
@@ -233,6 +233,7 @@ export const batchUpdateKeyframeSettings = async ({
},
entryType: sequenceKeyframes.length > 0 ? 'sequence-props' : 'effect-props',
suppressHmrOnFileRestore: true,
+ undoRedoNavigation: null,
});
for (const snapshot of snapshots) {
diff --git a/packages/studio-server/src/preview-server/routes/delete-keyframes.ts b/packages/studio-server/src/preview-server/routes/delete-keyframes.ts
index 652c834bb9..5db3fb8097 100644
--- a/packages/studio-server/src/preview-server/routes/delete-keyframes.ts
+++ b/packages/studio-server/src/preview-server/routes/delete-keyframes.ts
@@ -290,6 +290,7 @@ export const deleteKeyframes = async ({
? 'sequence-props'
: 'effect-props',
suppressHmrOnFileRestore: true,
+ undoRedoNavigation: null,
});
for (const snapshot of snapshots) {
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 77e15c73e0..01a9719024 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
@@ -97,6 +97,7 @@ export const duplicateJsxNodeHandler: ApiHandler<
},
entryType: 'duplicate-jsx-node',
suppressHmrOnFileRestore: false,
+ undoRedoNavigation: null,
});
for (const update of updates) {
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 a1f8a17e52..77a6c0dda9 100644
--- a/packages/studio-server/src/preview-server/routes/insert-element.ts
+++ b/packages/studio-server/src/preview-server/routes/insert-element.ts
@@ -67,6 +67,7 @@ export const insertElementHandler: ApiHandler<
from,
position,
overwriteExisting,
+ undoRedoNavigation,
newComposition,
},
entryPoint,
@@ -408,6 +409,7 @@ export const insertElementHandler: ApiHandler<
},
entryType: 'insert-jsx-element',
suppressHmrOnFileRestore: false,
+ undoRedoNavigation,
});
if (compositionCreation !== null) {
suppressUndoStackInvalidation(compositionCreation.registrationFilePath);
diff --git a/packages/studio-server/src/preview-server/routes/move-keyframes.ts b/packages/studio-server/src/preview-server/routes/move-keyframes.ts
index 10f9d8364f..2fec512ba9 100644
--- a/packages/studio-server/src/preview-server/routes/move-keyframes.ts
+++ b/packages/studio-server/src/preview-server/routes/move-keyframes.ts
@@ -302,6 +302,7 @@ export const moveKeyframes = async ({
? 'sequence-props'
: 'effect-props',
suppressHmrOnFileRestore: true,
+ undoRedoNavigation: null,
});
for (const snapshot of snapshots) {
diff --git a/packages/studio-server/src/preview-server/routes/save-multiple-effect-props.ts b/packages/studio-server/src/preview-server/routes/save-multiple-effect-props.ts
index 7912fa0f10..34a7845e17 100644
--- a/packages/studio-server/src/preview-server/routes/save-multiple-effect-props.ts
+++ b/packages/studio-server/src/preview-server/routes/save-multiple-effect-props.ts
@@ -162,6 +162,7 @@ export const saveMultipleEffectPropsHandler: ApiHandler<
},
entryType: 'effect-props',
suppressHmrOnFileRestore: true,
+ undoRedoNavigation: null,
});
for (const [absolutePath, output] of outputByPath) {
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 d1f102e3c8..422e520ed3 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
@@ -625,6 +625,7 @@ export const saveSequencePropsHandler: ApiHandler<
description: {undoMessage, redoMessage},
entryType: 'sequence-props',
suppressHmrOnFileRestore: suppressHmr,
+ undoRedoNavigation: null,
});
for (const [absolutePath, output] of outputByPath) {
diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.ts
index 990ca3fbaa..7d65aa4b8d 100644
--- a/packages/studio-server/src/preview-server/undo-stack.ts
+++ b/packages/studio-server/src/preview-server/undo-stack.ts
@@ -4,6 +4,7 @@ import {RenderInternals} from '@remotion/renderer';
import type {
RedoResponse,
SequenceNodePathRemapping,
+ UndoRedoNavigation,
UndoResponse,
} from '@remotion/studio-shared';
import {parseAst} from '../codemods/parse-ast';
@@ -71,6 +72,7 @@ type UndoEntry = {
/** When true, undo/redo file restores call `suppressBundlerUpdateForFile` (skip HMR refresh). */
suppressHmrOnFileRestore: boolean;
entryType: UndoEntryType;
+ undoRedoNavigation: UndoRedoNavigation | null;
};
const MAX_ENTRIES = 100;
@@ -110,11 +112,13 @@ const makeUndoEntry = ({
description,
entryType,
suppressHmrOnFileRestore,
+ undoRedoNavigation,
}: {
snapshots: UndoEntrySnapshot[];
description: UndoEntryDescription;
entryType: UndoEntryType;
suppressHmrOnFileRestore: boolean;
+ undoRedoNavigation: UndoRedoNavigation | null;
}): UndoEntry => {
if (snapshots.length === 0) {
throw new Error('Cannot create an undo entry without snapshots');
@@ -127,6 +131,7 @@ const makeUndoEntry = ({
description,
entryType,
suppressHmrOnFileRestore,
+ undoRedoNavigation,
};
};
@@ -168,6 +173,7 @@ export function pushToUndoStack({
description,
entryType,
suppressHmrOnFileRestore,
+ undoRedoNavigation: null,
});
}
@@ -178,6 +184,7 @@ export function pushTransactionToUndoStack({
description,
entryType,
suppressHmrOnFileRestore,
+ undoRedoNavigation,
}: {
snapshots: Array<{
filePath: string;
@@ -191,6 +198,7 @@ export function pushTransactionToUndoStack({
description: UndoEntryDescription;
entryType: UndoEntryType;
suppressHmrOnFileRestore: boolean;
+ undoRedoNavigation: UndoRedoNavigation | null;
}) {
storedLogLevel = logLevel;
storedRemotionRoot = remotionRoot;
@@ -200,6 +208,7 @@ export function pushTransactionToUndoStack({
description,
entryType,
suppressHmrOnFileRestore,
+ undoRedoNavigation,
});
undoStack.push(entry);
if (undoStack.length > MAX_ENTRIES) {
@@ -263,6 +272,7 @@ export function pushToRedoStack({
description,
entryType,
suppressHmrOnFileRestore,
+ undoRedoNavigation: null,
});
redoStack.push(entry);
if (redoStack.length > MAX_ENTRIES) {
@@ -431,6 +441,7 @@ export function popUndo(): UndoResponse {
description: entry.description,
entryType: entry.entryType,
suppressHmrOnFileRestore: entry.suppressHmrOnFileRestore,
+ undoRedoNavigation: entry.undoRedoNavigation,
}),
);
if (redoStack.length > MAX_ENTRIES) {
@@ -499,7 +510,11 @@ export function popUndo(): UndoResponse {
}
broadcastState();
- return {success: true, nodePathMutation};
+ return {
+ success: true,
+ nodePathMutation,
+ route: entry.undoRedoNavigation?.undoRoute ?? null,
+ };
}
export function popRedo(): RedoResponse {
@@ -528,6 +543,7 @@ export function popRedo(): RedoResponse {
description: entry.description,
entryType: entry.entryType,
suppressHmrOnFileRestore: entry.suppressHmrOnFileRestore,
+ undoRedoNavigation: entry.undoRedoNavigation,
}),
);
if (undoStack.length > MAX_ENTRIES) {
@@ -587,7 +603,11 @@ export function popRedo(): RedoResponse {
}
broadcastState();
- return {success: true, nodePathMutation};
+ return {
+ success: true,
+ nodePathMutation,
+ route: entry.undoRedoNavigation?.redoRoute ?? null,
+ };
}
/*
diff --git a/packages/studio-server/src/test/add-keyframes.test.ts b/packages/studio-server/src/test/add-keyframes.test.ts
index 7d056743f8..5f289d68e0 100644
--- a/packages/studio-server/src/test/add-keyframes.test.ts
+++ b/packages/studio-server/src/test/add-keyframes.test.ts
@@ -145,10 +145,18 @@ test('addKeyframes batches sequence and effect adds into one undo entry', async
);
expect(getUndoStack()).toHaveLength(1);
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(input);
- expect(popRedo()).toEqual({success: true, nodePathMutation: null});
+ expect(popRedo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(output);
} finally {
clearUndoStackForTests();
diff --git a/packages/studio-server/src/test/apply-codemod.test.ts b/packages/studio-server/src/test/apply-codemod.test.ts
index 6284c977c2..0be8f3deeb 100644
--- a/packages/studio-server/src/test/apply-codemod.test.ts
+++ b/packages/studio-server/src/test/apply-codemod.test.ts
@@ -411,6 +411,7 @@ const runCompositionCodemodUndoRedoTest = async ({
input: {
codemod,
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: {
originalFunctionName: null,
originalFileName: 'Root.tsx',
@@ -554,6 +555,7 @@ test('applyCodemodHandler pushes composition moves to undo and redo stacks', asy
parentName: 'Other',
} satisfies RecastCodemod,
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: {
originalFunctionName: null,
originalFileName: 'Root.tsx',
@@ -617,6 +619,7 @@ test('applyCodemodHandler pushes composition moves to root to undo and redo stac
parentName: null,
} satisfies RecastCodemod,
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: {
originalFunctionName: null,
originalFileName: 'Root.tsx',
@@ -688,6 +691,7 @@ test('applyCodemodHandler creates new composition files with undo and redo', asy
newWidth: 1920,
} satisfies RecastCodemod,
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: {
originalFunctionName: null,
originalFileName: 'Root.tsx',
@@ -812,6 +816,7 @@ test('applyCodemodHandler creates an interactive Canvas Capture composition', as
newWidth: 1280,
} satisfies RecastCodemod,
dryRun: false,
+ undoRedoNavigation: null,
symbolicatedStack: {
originalFunctionName: null,
originalFileName: 'Root.tsx',
diff --git a/packages/studio-server/src/test/batch-update-keyframe-settings.test.ts b/packages/studio-server/src/test/batch-update-keyframe-settings.test.ts
index f26baaa39c..3bc285ac07 100644
--- a/packages/studio-server/src/test/batch-update-keyframe-settings.test.ts
+++ b/packages/studio-server/src/test/batch-update-keyframe-settings.test.ts
@@ -125,11 +125,19 @@ test('batches sequence and effect easing changes into one undo entry', async ()
expect(effectOutput).toContain('easing: [Easing.bezier(0.42, 0, 1, 1)]');
expect(getUndoStack()).toHaveLength(1);
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(sequenceFilePath, 'utf-8')).toBe(input);
expect(readFileSync(effectFilePath, 'utf-8')).toBe(input);
- expect(popRedo()).toEqual({success: true, nodePathMutation: null});
+ expect(popRedo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(sequenceFilePath, 'utf-8')).toBe(sequenceOutput);
expect(readFileSync(effectFilePath, 'utf-8')).toBe(effectOutput);
} finally {
diff --git a/packages/studio-server/src/test/delete-keyframes.test.ts b/packages/studio-server/src/test/delete-keyframes.test.ts
index 0ad0df9974..90abee5a4e 100644
--- a/packages/studio-server/src/test/delete-keyframes.test.ts
+++ b/packages/studio-server/src/test/delete-keyframes.test.ts
@@ -117,10 +117,18 @@ test('deleteKeyframes batches sequence and effect deletes into one undo entry',
expect(output).toContain('amount: 0.6');
expect(getUndoStack()).toHaveLength(1);
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(input);
- expect(popRedo()).toEqual({success: true, nodePathMutation: null});
+ expect(popRedo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(output);
} finally {
clearUndoStackForTests();
diff --git a/packages/studio-server/src/test/insert-element.test.ts b/packages/studio-server/src/test/insert-element.test.ts
index 17c863a3e7..86ef893a67 100644
--- a/packages/studio-server/src/test/insert-element.test.ts
+++ b/packages/studio-server/src/test/insert-element.test.ts
@@ -152,6 +152,7 @@ const makeFixture = () => {
from: null,
overwriteExisting,
position: null,
+ undoRedoNavigation: null,
newComposition: null,
});
};
@@ -293,6 +294,7 @@ test('invalidates a new-composition install after an external component edit', a
from: null,
overwriteExisting: false,
position: null,
+ undoRedoNavigation: null,
newComposition: {
codemod: {
type: 'new-composition',
@@ -397,6 +399,7 @@ test('installs structured initial props on a component-owned Sequence', async ()
from: 30,
overwriteExisting: false,
position: {x: 120, y: 80},
+ undoRedoNavigation: null,
newComposition: null,
});
@@ -454,6 +457,7 @@ test('rejects contradictory component-owned installation props', async () => {
from: 30,
overwriteExisting: false,
position: {x: 120, y: 80},
+ undoRedoNavigation: null,
newComposition: null,
});
expect(response).toMatchObject({success: false, type: 'error'});
@@ -482,6 +486,7 @@ test('keeps wrapped installation and passes initial props to its child', async (
from: 12,
overwriteExisting: false,
position: {x: 40, y: 50},
+ undoRedoNavigation: null,
newComposition: null,
});
if (!response.success) {
@@ -520,6 +525,7 @@ test('materializes independent props for two component-owned copies', async () =
from: 0,
overwriteExisting: false,
position: null,
+ undoRedoNavigation: null,
newComposition: null,
});
expect(first.success).toBe(true);
@@ -532,6 +538,7 @@ test('materializes independent props for two component-owned copies', async () =
from: 30,
overwriteExisting: false,
position: null,
+ undoRedoNavigation: null,
newComposition: null,
});
expect(second.success).toBe(true);
@@ -574,6 +581,7 @@ test('installs independent named copies into the same and another composition',
from: null,
position: null,
overwriteExisting: false,
+ undoRedoNavigation: null,
newComposition: null,
};
expect((await fixture.callHandlerWithInput(input)).success).toBe(true);
@@ -703,6 +711,7 @@ test.each(['../outside', 'nested/name', 'Uppercase', '', 'name.element.tsx'])(
from: null,
position: null,
overwriteExisting: false,
+ undoRedoNavigation: null,
newComposition: null,
}),
).toMatchObject({success: false, type: 'error'});
diff --git a/packages/studio-server/src/test/save-multiple-effect-props.test.ts b/packages/studio-server/src/test/save-multiple-effect-props.test.ts
index 12e1b0e976..72b944b16c 100644
--- a/packages/studio-server/src/test/save-multiple-effect-props.test.ts
+++ b/packages/studio-server/src/test/save-multiple-effect-props.test.ts
@@ -125,9 +125,17 @@ export const Comp = () => {
expect(response.results).toHaveLength(2);
expect(getUndoStack()).toHaveLength(1);
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(input);
- expect(popRedo()).toEqual({success: true, nodePathMutation: null});
+ expect(popRedo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(output);
} finally {
clearUndoStackForTests();
diff --git a/packages/studio-server/src/test/save-sequence-props.test.ts b/packages/studio-server/src/test/save-sequence-props.test.ts
index 79df6618a3..220c058060 100644
--- a/packages/studio-server/src/test/save-sequence-props.test.ts
+++ b/packages/studio-server/src/test/save-sequence-props.test.ts
@@ -173,7 +173,11 @@ export const Comp = () => {
expect(completionLog).toMatch(/^\[\d+ms\] /);
expect(completionLog).toContain('Comp.tsx:4');
expect(getUndoStack()).toHaveLength(1);
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(input);
} finally {
clearUndoStackForTests();
@@ -310,7 +314,11 @@ test('saveSequenceProps saves inline caption patches as an undoable source edit'
expect(getUndoStack()).toHaveLength(1);
expect(getUndoStack()[0]?.suppressHmrOnFileRestore).toBe(false);
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(input);
} finally {
clearUndoStackForTests();
@@ -419,7 +427,11 @@ export const Comp = () => {
expect(output).toContain('interpolate(frame, [10, 30], [0, 1])');
expect(getUndoStack()).toHaveLength(1);
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(input);
} finally {
clearUndoStackForTests();
@@ -534,7 +546,11 @@ export const Comp = () => {
expect(output).toContain("['3px 4px', '23px 44px']");
expect(getUndoStack()).toHaveLength(1);
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: null,
+ });
expect(readFileSync(filePath, 'utf-8')).toBe(input);
} finally {
clearUndoStackForTests();
diff --git a/packages/studio-server/src/test/undo-stack.test.ts b/packages/studio-server/src/test/undo-stack.test.ts
index f0b6929007..42f95e35e2 100644
--- a/packages/studio-server/src/test/undo-stack.test.ts
+++ b/packages/studio-server/src/test/undo-stack.test.ts
@@ -58,13 +58,25 @@ test('undo and redo restore every file in a transaction', () => {
},
entryType: 'sequence-props',
suppressHmrOnFileRestore: true,
+ undoRedoNavigation: {
+ undoRoute: '/Before',
+ redoRoute: '/After',
+ },
});
- expect(popUndo()).toEqual({success: true, nodePathMutation: null});
+ expect(popUndo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: '/Before',
+ });
expect(readFileSync(firstFile, 'utf-8')).toBe('old first');
expect(readFileSync(secondFile, 'utf-8')).toBe('old second');
- expect(popRedo()).toEqual({success: true, nodePathMutation: null});
+ expect(popRedo()).toEqual({
+ success: true,
+ nodePathMutation: null,
+ route: '/After',
+ });
expect(readFileSync(firstFile, 'utf-8')).toBe('new first');
expect(readFileSync(secondFile, 'utf-8')).toBe('new second');
} finally {
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index cd2157158b..6c555f373b 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -304,10 +304,16 @@ export type UpdateDefaultPropsResponse =
stack: string;
};
+export type UndoRedoNavigation = {
+ undoRoute: string;
+ redoRoute: string;
+};
+
export type ApplyCodemodRequest = {
codemod: RecastCodemod;
dryRun: boolean;
symbolicatedStack: SymbolicatedStackFrame | null;
+ undoRedoNavigation: UndoRedoNavigation | null;
};
export type SimpleDiff = {
@@ -1046,6 +1052,7 @@ export type InsertElementRequest = {
from: number | null;
position: InsertableCompositionElementPosition | null;
overwriteExisting: boolean;
+ undoRedoNavigation: UndoRedoNavigation | null;
newComposition: {
codemod: Extract<RecastCodemod, {type: 'new-composition'}>;
symbolicatedStack: SymbolicatedStackFrame | null;
@@ -1245,6 +1252,7 @@ export type UndoResponse =
| {
success: true;
nodePathMutation: SequenceNodePathMutation | null;
+ route: string | null;
}
| {
success: false;
@@ -1256,6 +1264,7 @@ export type RedoResponse =
| {
success: true;
nodePathMutation: SequenceNodePathMutation | null;
+ route: string | null;
}
| {
success: false;
diff --git a/packages/studio-shared/src/browser-studio-operations.ts b/packages/studio-shared/src/browser-studio-operations.ts
index 0e4aed619c..9f711cde21 100644
--- a/packages/studio-shared/src/browser-studio-operations.ts
+++ b/packages/studio-shared/src/browser-studio-operations.ts
@@ -34,6 +34,7 @@ import type {
InsertElementRequest,
InsertElementResponse,
InstallPackageRequest,
+ UndoRedoNavigation,
InstallableElement,
MoveKeyframesRequest,
MoveKeyframesResponse,
@@ -84,6 +85,7 @@ export type WriteStaticFileRequest = {
export type DuplicateCompositionRequest = {
codemod: Extract<RecastCodemod, {type: 'duplicate-composition'}>;
dryRun: boolean;
+ undoRedoNavigation: UndoRedoNavigation | null;
};
export type DuplicateCompositionResponse =
diff --git a/packages/studio-shared/src/index.ts b/packages/studio-shared/src/index.ts
index ea318ff60c..8a6512621a 100644
--- a/packages/studio-shared/src/index.ts
+++ b/packages/studio-shared/src/index.ts
@@ -142,6 +142,7 @@ export {
SubscribeToSequencePropsBatchResponse,
SubscribeToSequencePropsRequest,
SubscribeToSequencePropsResponse,
+ UndoRedoNavigation,
UndoRequest,
UndoResponse,
UnsubscribeFromDefaultPropsRequest,
diff --git a/packages/studio/src/components/CompositionSelector.tsx b/packages/studio/src/components/CompositionSelector.tsx
index c2a5b5a3aa..f9e9712fa5 100644
--- a/packages/studio/src/components/CompositionSelector.tsx
+++ b/packages/studio/src/components/CompositionSelector.tsx
@@ -351,6 +351,7 @@ export const CompositionSelector: React.FC = () => {
signal: controller.signal,
symbolicatedStack:
compositionSelectorDragDataToSymbolicatedStack(dragData),
+ undoRedoNavigation: null,
});
if (result.success) {
diff --git a/packages/studio/src/components/CompositionSelectorItem.tsx b/packages/studio/src/components/CompositionSelectorItem.tsx
index 57f6145d0c..3dc82abb0f 100644
--- a/packages/studio/src/components/CompositionSelectorItem.tsx
+++ b/packages/studio/src/components/CompositionSelectorItem.tsx
@@ -626,6 +626,7 @@ export const CompositionSelectorItem: React.FC<{
signal: new AbortController().signal,
symbolicatedStack:
compositionSelectorDragDataToSymbolicatedStack(dragData),
+ undoRedoNavigation: null,
});
if (result.success) {
diff --git a/packages/studio/src/components/ElementInstallConfirmation.tsx b/packages/studio/src/components/ElementInstallConfirmation.tsx
index ba5f80fc95..f3ec8fad7a 100644
--- a/packages/studio/src/components/ElementInstallConfirmation.tsx
+++ b/packages/studio/src/components/ElementInstallConfirmation.tsx
@@ -24,6 +24,7 @@ import {
hoverableStyle,
} from '../helpers/hoverable';
import {resolvedStackToSymbolicated} from '../helpers/resolved-stack-to-symbolicated';
+import {getRoute} from '../helpers/url-state';
import {useCreateComposition} from '../helpers/use-create-composition';
import {validateCompositionName} from '../helpers/validate-new-comp-data';
import type {
@@ -735,6 +736,13 @@ export const ElementInstallConfirmation: React.FC<{
from: mode === 'new-composition' ? null : request.from,
overwriteExisting,
position: mode === 'new-composition' ? null : request.position,
+ undoRedoNavigation:
+ mode === 'new-composition'
+ ? {
+ undoRoute: getRoute(),
+ redoRoute: `/${newCompositionId}`,
+ }
+ : null,
newComposition:
mode === 'new-composition'
? {
diff --git a/packages/studio/src/components/InspectorPanel/CompositionMetadata.tsx b/packages/studio/src/components/InspectorPanel/CompositionMetadata.tsx
index bdea90231a..ccdb654aec 100644
--- a/packages/studio/src/components/InspectorPanel/CompositionMetadata.tsx
+++ b/packages/studio/src/components/InspectorPanel/CompositionMetadata.tsx
@@ -369,6 +369,7 @@ export const CompositionMetadata: React.FC<{
dryRun: false,
signal: new AbortController().signal,
symbolicatedStack,
+ undoRedoNavigation: null,
})
.then((result) => {
if (!result.success) {
diff --git a/packages/studio/src/components/NewComposition/CodemodFooter.tsx b/packages/studio/src/components/NewComposition/CodemodFooter.tsx
index 2292adc574..3626dd7557 100644
--- a/packages/studio/src/components/NewComposition/CodemodFooter.tsx
+++ b/packages/studio/src/components/NewComposition/CodemodFooter.tsx
@@ -153,6 +153,7 @@ export const CodemodFooter: React.FC<{
dryRun: true,
symbolicatedStack,
signal,
+ undoRedoNavigation: null,
});
if (res.success) {
diff --git a/packages/studio/src/components/NewComposition/DeleteComposition.tsx b/packages/studio/src/components/NewComposition/DeleteComposition.tsx
index c29298c10d..b5a1dd35fe 100644
--- a/packages/studio/src/components/NewComposition/DeleteComposition.tsx
+++ b/packages/studio/src/components/NewComposition/DeleteComposition.tsx
@@ -1,5 +1,9 @@
import type {RecastCodemod} from '@remotion/studio-shared';
-import React, {useCallback, useContext, useMemo} from 'react';
+import React, {useCallback, useContext, useMemo, useRef} from 'react';
+import type {_InternalTypes} from 'remotion';
+import {Internals} from 'remotion';
+import {getRoute, pushUrl} from '../../helpers/url-state';
+import {useSelectComposition} from '../InitialCompositionLoader';
import {inlineCodeSnippet} from '../Menu/styles';
import {ModalFooterContainer} from '../ModalFooter';
import {ModalHeader} from '../ModalHeader';
@@ -28,6 +32,12 @@ const DeleteCompositionLoaded: React.FC<{
const {unresolved} = context;
const compositionStack = unresolved.stack ?? null;
+ const {compositions} = useContext(Internals.CompositionManager);
+ const {setCanvasContent} = useContext(Internals.CompositionSetters);
+ const selectComposition = useSelectComposition();
+ const navigationAfterDelete = useRef<
+ _InternalTypes['AnyComposition'] | null | undefined
+ >(undefined);
const codemod: RecastCodemod = useMemo(() => {
return {
@@ -40,6 +50,20 @@ const DeleteCompositionLoaded: React.FC<{
e.preventDefault();
}, []);
+ const onSuccess = useCallback(() => {
+ if (navigationAfterDelete.current === undefined) {
+ return;
+ }
+
+ if (navigationAfterDelete.current === null) {
+ pushUrl('/');
+ setCanvasContent(null);
+ return;
+ }
+
+ selectComposition(navigationAfterDelete.current, true);
+ }, [selectComposition, setCanvasContent]);
+
return (
<>
<ModalHeader title={'Delete composition'} />
@@ -67,15 +91,29 @@ const DeleteCompositionLoaded: React.FC<{
codemod={codemod}
stack={compositionStack}
valid
- onSuccess={null}
- applyCodemod={({signal, symbolicatedStack}) =>
- applyCodemod({
+ onSuccess={onSuccess}
+ applyCodemod={({signal, symbolicatedStack}) => {
+ const currentRoute = getRoute();
+ const isSelected = currentRoute === `/${compositionId}`;
+ const fallback = isSelected
+ ? (compositions.find(({id}) => id !== compositionId) ?? null)
+ : undefined;
+ navigationAfterDelete.current = fallback;
+
+ return applyCodemod({
codemod,
dryRun: false,
signal,
symbolicatedStack,
- })
- }
+ undoRedoNavigation:
+ fallback === undefined
+ ? null
+ : {
+ undoRoute: currentRoute,
+ redoRoute: fallback === null ? '/' : `/${fallback.id}`,
+ },
+ });
+ }}
applyCodemodForPreview={null}
/>
</ModalFooterContainer>
diff --git a/packages/studio/src/components/NewComposition/DeleteFolder.tsx b/packages/studio/src/components/NewComposition/DeleteFolder.tsx
index 96ec1fb337..b63633673a 100644
--- a/packages/studio/src/components/NewComposition/DeleteFolder.tsx
+++ b/packages/studio/src/components/NewComposition/DeleteFolder.tsx
@@ -64,6 +64,7 @@ export const DeleteFolder: React.FC<{
dryRun: false,
signal,
symbolicatedStack,
+ undoRedoNavigation: null,
})
}
applyCodemodForPreview={null}
diff --git a/packages/studio/src/components/NewComposition/DuplicateComposition.tsx b/packages/studio/src/components/NewComposition/DuplicateComposition.tsx
index e2a7600b4a..c707e946a6 100644
--- a/packages/studio/src/components/NewComposition/DuplicateComposition.tsx
+++ b/packages/studio/src/components/NewComposition/DuplicateComposition.tsx
@@ -2,7 +2,7 @@ import type {RecastCodemod} from '@remotion/studio-shared';
import type {ChangeEventHandler} from 'react';
import React, {useCallback, useContext, useMemo, useState} from 'react';
import {Internals} from 'remotion';
-import {pushUrl} from '../../helpers/url-state';
+import {getRoute, pushUrl} from '../../helpers/url-state';
import {
validateCompositionDimension,
validateCompositionName,
@@ -382,6 +382,10 @@ const DuplicateCompositionLoaded: React.FC<{
dryRun: false,
signal,
symbolicatedStack,
+ undoRedoNavigation: {
+ undoRoute: getRoute(),
+ redoRoute: `/${newId}`,
+ },
})
}
applyCodemodForPreview={({signal, symbolicatedStack}) =>
@@ -390,6 +394,7 @@ const DuplicateCompositionLoaded: React.FC<{
dryRun: true,
signal,
symbolicatedStack,
+ undoRedoNavigation: null,
})
}
/>
diff --git a/packages/studio/src/components/NewComposition/NewFolder.tsx b/packages/studio/src/components/NewComposition/NewFolder.tsx
index 3c7021572c..fc3dc085a5 100644
--- a/packages/studio/src/components/NewComposition/NewFolder.tsx
+++ b/packages/studio/src/components/NewComposition/NewFolder.tsx
@@ -190,6 +190,7 @@ export const NewFolder: React.FC<{
dryRun: false,
signal,
symbolicatedStack,
+ undoRedoNavigation: null,
})
}
applyCodemodForPreview={null}
diff --git a/packages/studio/src/components/NewComposition/RenameFolder.tsx b/packages/studio/src/components/NewComposition/RenameFolder.tsx
index 7417b56dfa..cb80376a84 100644
--- a/packages/studio/src/components/NewComposition/RenameFolder.tsx
+++ b/packages/studio/src/components/NewComposition/RenameFolder.tsx
@@ -136,6 +136,7 @@ export const RenameFolder: React.FC<{
dryRun: false,
signal,
symbolicatedStack,
+ undoRedoNavigation: null,
})
}
applyCodemodForPreview={null}
diff --git a/packages/studio/src/components/NewComposition/duplicate-composition-api.ts b/packages/studio/src/components/NewComposition/duplicate-composition-api.ts
index 6d64885fee..9b431d61f5 100644
--- a/packages/studio/src/components/NewComposition/duplicate-composition-api.ts
+++ b/packages/studio/src/components/NewComposition/duplicate-composition-api.ts
@@ -2,6 +2,7 @@ import type {
DuplicateCompositionResponse,
RecastCodemod,
SymbolicatedStackFrame,
+ UndoRedoNavigation,
} from '@remotion/studio-shared';
import {getBrowserStudioOperations} from '../../helpers/browser-studio-operations';
import {applyCodemod} from '../RenderQueue/actions';
@@ -11,21 +12,28 @@ export const duplicateComposition = ({
dryRun,
signal,
symbolicatedStack,
+ undoRedoNavigation,
}: {
codemod: Extract<RecastCodemod, {type: 'duplicate-composition'}>;
dryRun: boolean;
signal: AbortSignal;
symbolicatedStack: SymbolicatedStackFrame | null;
+ undoRedoNavigation: UndoRedoNavigation | null;
}): Promise<DuplicateCompositionResponse> => {
const browserStudioOperations = getBrowserStudioOperations();
if (browserStudioOperations === null) {
- return applyCodemod({codemod, dryRun, signal, symbolicatedStack}).then(
- (result) => (result.success ? result : {...result, stack: ''}),
- );
+ return applyCodemod({
+ codemod,
+ dryRun,
+ signal,
+ symbolicatedStack,
+ undoRedoNavigation,
+ }).then((result) => (result.success ? result : {...result, stack: ''}));
}
return browserStudioOperations.duplicateComposition({
codemod,
dryRun,
+ undoRedoNavigation,
});
};
diff --git a/packages/studio/src/components/RenderQueue/actions.ts b/packages/studio/src/components/RenderQueue/actions.ts
index 205871edf8..cfee777e3b 100644
--- a/packages/studio/src/components/RenderQueue/actions.ts
+++ b/packages/studio/src/components/RenderQueue/actions.ts
@@ -351,16 +351,19 @@ export const applyCodemod = ({
dryRun,
symbolicatedStack,
signal,
+ undoRedoNavigation,
}: {
codemod: RecastCodemod;
dryRun: boolean;
symbolicatedStack: ApplyCodemodRequest['symbolicatedStack'];
signal: AbortController['signal'];
+ undoRedoNavigation: ApplyCodemodRequest['undoRedoNavigation'];
}) => {
const body: ApplyCodemodRequest = {
codemod,
dryRun,
symbolicatedStack,
+ undoRedoNavigation,
};
const browserStudioOperations = getBrowserStudioOperations();
if (browserStudioOperations !== null) {
diff --git a/packages/studio/src/components/UndoRedoButtons.tsx b/packages/studio/src/components/UndoRedoButtons.tsx
index 146c23a04e..69f905b79b 100644
--- a/packages/studio/src/components/UndoRedoButtons.tsx
+++ b/packages/studio/src/components/UndoRedoButtons.tsx
@@ -9,6 +9,7 @@ import React, {
import {getBrowserStudioOperations} from '../helpers/browser-studio-operations';
import {StudioServerConnectionCtx} from '../helpers/client-id';
import {WHITE_ALPHA_80} from '../helpers/colors';
+import {pushUrl} from '../helpers/url-state';
import {
areKeyboardShortcutsDisabled,
useKeybinding,
@@ -60,6 +61,11 @@ export const UndoRedoButtons: React.FC = () => {
? browserStudioOperations.undo()
: callApi('/api/undo', {});
promise
+ .then((response) => {
+ if (response.success && response.route !== null) {
+ pushUrl(response.route);
+ }
+ })
.catch(() => {
// Ignore errors
})
@@ -79,6 +85,11 @@ export const UndoRedoButtons: React.FC = () => {
? browserStudioOperations.redo()
: callApi('/api/redo', {});
promise
+ .then((response) => {
+ if (response.success && response.route !== null) {
+ pushUrl(response.route);
+ }
+ })
.catch(() => {
// Ignore errors
})
diff --git a/packages/studio/src/components/import-assets.ts b/packages/studio/src/components/import-assets.ts
index c0bf4946bc..240c4a277d 100644
--- a/packages/studio/src/components/import-assets.ts
+++ b/packages/studio/src/components/import-assets.ts
@@ -1328,6 +1328,7 @@ export const insertElement = async ({
position,
from,
overwriteExisting,
+ undoRedoNavigation,
newComposition,
}: {
installationName: string | null;
@@ -1338,6 +1339,7 @@ export const insertElement = async ({
position: InsertableCompositionElementPosition | null;
from: number | null;
overwriteExisting: boolean;
+ undoRedoNavigation: InsertElementRequest['undoRedoNavigation'];
newComposition: InsertElementRequest['newComposition'];
}) => {
try {
@@ -1354,6 +1356,7 @@ export const insertElement = async ({
from,
overwriteExisting,
position,
+ undoRedoNavigation,
newComposition,
});
diff --git a/packages/studio/src/helpers/use-create-composition.ts b/packages/studio/src/helpers/use-create-composition.ts
index 7302fac5ea..a38e163e79 100644
--- a/packages/studio/src/helpers/use-create-composition.ts
+++ b/packages/studio/src/helpers/use-create-composition.ts
@@ -8,6 +8,7 @@ import type {_InternalTypes} from 'remotion';
import {useSelectComposition} from '../components/InitialCompositionLoader';
import {applyCodemod} from '../components/RenderQueue/actions';
import {slugifyName} from './slugify-name';
+import {getRoute} from './url-state';
import {
validateCompositionDimension,
validateCompositionName,
@@ -147,6 +148,10 @@ export const useCreateComposition = ({
dryRun: false,
signal,
symbolicatedStack,
+ undoRedoNavigation: {
+ undoRoute: getRoute(),
+ redoRoute: `/${compositionId}`,
+ },
});
if (result.success) {
diff --git a/packages/studio/src/helpers/use-rename-composition.ts b/packages/studio/src/helpers/use-rename-composition.ts
index d073ead9e4..8047fd49d7 100644
--- a/packages/studio/src/helpers/use-rename-composition.ts
+++ b/packages/studio/src/helpers/use-rename-composition.ts
@@ -6,7 +6,7 @@ import {useCallback, useMemo} from 'react';
import type {_InternalTypes} from 'remotion';
import {applyCodemod} from '../components/RenderQueue/actions';
import {slugifyName} from './slugify-name';
-import {pushUrl} from './url-state';
+import {getRoute, pushUrl} from './url-state';
import {validateCompositionName} from './validate-new-comp-data';
export const useRenameComposition = ({
@@ -64,15 +64,20 @@ export const useRenameComposition = ({
signal: AbortSignal;
symbolicatedStack: SymbolicatedStackFrame | null;
}) => {
+ const nextCompositionId = slugifyName(newCompositionId);
const result = await applyCodemod({
codemod: getCodemod(newCompositionId),
dryRun: false,
signal,
symbolicatedStack,
+ undoRedoNavigation: {
+ undoRoute: getRoute(),
+ redoRoute: `/${nextCompositionId}`,
+ },
});
if (result.success) {
- pushUrl(`/${slugifyName(newCompositionId)}`);
+ pushUrl(`/${nextCompositionId}`);
}
return result;