Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Edit composition metadata in inspector (#9266)

Jonny Burger186bb67a3c25
diff --git a/packages/core/src/ResolveCompositionConfig.tsx b/packages/core/src/ResolveCompositionConfig.tsx
index 679da63da8..6fe6ce4ccf 100644
--- a/packages/core/src/ResolveCompositionConfig.tsx
+++ b/packages/core/src/ResolveCompositionConfig.tsx
@@ -3,6 +3,7 @@ import type {AnyComposition} from './CompositionManager.js';
import {CompositionManager} from './CompositionManagerContext.js';
import {getInputProps} from './config/input-props.js';
import {EditorPropsContext} from './EditorProps.js';
+import type {VideoConfigMetadataSource} from './resolve-video-config.js';
import {useRemotionEnvironment} from './use-remotion-environment.js';
import {validateDimension} from './validation/validate-dimensions.js';
import {validateDurationInFrames} from './validation/validate-duration-in-frames.js';
@@ -30,10 +31,12 @@ type VideoConfigState =
| {
type: 'success';
result: VideoConfig;
+ metadataSource: VideoConfigMetadataSource | null;
}
| {
type: 'success-and-refreshing';
result: VideoConfig;
+ metadataSource: VideoConfigMetadataSource | null;
}
| {
type: 'error';
@@ -72,6 +75,7 @@ export const useResolvedVideoConfig = (
if (currentCompositionMetadata) {
return {
type: 'success',
+ metadataSource: null,
result: {
...currentCompositionMetadata,
id: composition.id,
@@ -103,6 +107,7 @@ export const useResolvedVideoConfig = (
return {
type: 'success',
+ metadataSource: null,
result: {
width: composition.width as number,
height: composition.height as number,
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index c2160640da..3bdf585bb3 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -134,6 +134,7 @@ import {
import {
resolveVideoConfig,
resolveVideoConfigOrCatch,
+ resolveVideoConfigWithMetadataOrCatch,
} from './resolve-video-config.js';
import {
ResolveCompositionContext,
@@ -352,6 +353,7 @@ export const Internals = {
NonceContext,
resolveVideoConfig,
resolveVideoConfigOrCatch,
+ resolveVideoConfigWithMetadataOrCatch,
ResolveCompositionContext,
useResolvedVideoConfig,
resolveCompositionsRef,
diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.ts
index fd5a676b92..5531ccfd15 100644
--- a/packages/core/src/resolve-video-config.ts
+++ b/packages/core/src/resolve-video-config.ts
@@ -99,7 +99,73 @@ type ResolveVideoConfigParams = {
inputProps: Record<string, unknown>;
};
-export const resolveVideoConfig = ({
+export type VideoConfigMetadataSource = {
+ readonly durationInFrames: 'calculate-metadata' | 'composition';
+ readonly fps: 'calculate-metadata' | 'composition';
+ readonly height: 'calculate-metadata' | 'composition';
+ readonly width: 'calculate-metadata' | 'composition';
+};
+
+export type VideoConfigWithMetadata = {
+ readonly metadataSource: VideoConfigMetadataSource;
+ readonly videoConfig: VideoConfig;
+};
+
+const makeVideoConfigWithMetadata = ({
+ calculated,
+ compositionDurationInFrames,
+ compositionFps,
+ compositionHeight,
+ compositionId,
+ compositionWidth,
+ defaultProps,
+ originalProps,
+}: Omit<
+ ResolveVideoConfigParams,
+ 'calculateMetadata' | 'signal' | 'inputProps'
+> & {
+ readonly calculated: CalcMetadataReturnType<Record<string, unknown>> | null;
+ readonly originalProps: Record<string, unknown>;
+}): VideoConfigWithMetadata => {
+ const data = validateCalculated({
+ calculated,
+ compositionDurationInFrames,
+ compositionFps,
+ compositionHeight,
+ compositionWidth,
+ compositionId,
+ });
+
+ return {
+ metadataSource: {
+ durationInFrames:
+ calculated?.durationInFrames === undefined
+ ? 'composition'
+ : 'calculate-metadata',
+ fps: calculated?.fps === undefined ? 'composition' : 'calculate-metadata',
+ height:
+ calculated?.height === undefined ? 'composition' : 'calculate-metadata',
+ width:
+ calculated?.width === undefined ? 'composition' : 'calculate-metadata',
+ },
+ videoConfig: {
+ ...data,
+ id: compositionId,
+ defaultProps: serializeThenDeserializeInStudio(defaultProps ?? {}),
+ props: serializeThenDeserializeInStudio(
+ calculated?.props ?? originalProps,
+ ),
+ defaultCodec: data.defaultCodec ?? null,
+ defaultOutName: data.defaultOutName ?? null,
+ defaultVideoImageFormat: data.defaultVideoImageFormat ?? null,
+ defaultPixelFormat: data.defaultPixelFormat ?? null,
+ defaultProResProfile: data.defaultProResProfile ?? null,
+ defaultSampleRate: data.defaultSampleRate ?? null,
+ },
+ };
+};
+
+export const resolveVideoConfigWithMetadata = ({
calculateMetadata,
signal,
defaultProps,
@@ -109,7 +175,9 @@ export const resolveVideoConfig = ({
compositionFps,
compositionHeight,
compositionWidth,
-}: ResolveVideoConfigParams): VideoConfig | Promise<VideoConfig> => {
+}: ResolveVideoConfigParams):
+ | VideoConfigWithMetadata
+ | Promise<VideoConfigWithMetadata> => {
const calculatedProm = calculateMetadata
? calculateMetadata({
defaultProps,
@@ -126,81 +194,64 @@ export const resolveVideoConfig = ({
'then' in calculatedProm
) {
return calculatedProm.then((c) => {
- const {
- height,
- width,
- durationInFrames,
- fps,
- defaultCodec,
- defaultOutName,
- defaultVideoImageFormat,
- defaultPixelFormat,
- defaultProResProfile,
- defaultSampleRate,
- } = validateCalculated({
+ return makeVideoConfigWithMetadata({
calculated: c,
compositionDurationInFrames,
compositionFps,
compositionHeight,
compositionWidth,
compositionId,
+ defaultProps,
+ originalProps,
});
- return {
- width,
- height,
- fps,
- durationInFrames,
- id: compositionId,
- defaultProps: serializeThenDeserializeInStudio(defaultProps),
- props: serializeThenDeserializeInStudio(c.props ?? originalProps),
- defaultCodec: defaultCodec ?? null,
- defaultOutName: defaultOutName ?? null,
- defaultVideoImageFormat: defaultVideoImageFormat ?? null,
- defaultPixelFormat: defaultPixelFormat ?? null,
- defaultProResProfile: defaultProResProfile ?? null,
- defaultSampleRate: defaultSampleRate ?? null,
- };
});
}
- const data = validateCalculated({
+ return makeVideoConfigWithMetadata({
calculated: calculatedProm,
compositionDurationInFrames,
compositionFps,
compositionHeight,
compositionWidth,
compositionId,
+ defaultProps,
+ originalProps,
});
+};
+
+export const resolveVideoConfig = (
+ params: ResolveVideoConfigParams,
+): VideoConfig | Promise<VideoConfig> => {
+ const resolved = resolveVideoConfigWithMetadata(params);
+ if (typeof resolved === 'object' && 'then' in resolved) {
+ return resolved.then(({videoConfig}) => videoConfig);
+ }
- if (calculatedProm === null) {
+ return resolved.videoConfig;
+};
+
+export const resolveVideoConfigWithMetadataOrCatch = (
+ params: ResolveVideoConfigParams,
+):
+ | {
+ type: 'success';
+ result: VideoConfigWithMetadata | Promise<VideoConfigWithMetadata>;
+ }
+ | {
+ type: 'error';
+ error: Error;
+ } => {
+ try {
return {
- ...data,
- id: compositionId,
- defaultProps: serializeThenDeserializeInStudio(defaultProps ?? {}),
- props: serializeThenDeserializeInStudio(originalProps),
- defaultCodec: null,
- defaultOutName: null,
- defaultVideoImageFormat: null,
- defaultPixelFormat: null,
- defaultProResProfile: null,
- defaultSampleRate: null,
+ type: 'success',
+ result: resolveVideoConfigWithMetadata(params),
+ };
+ } catch (err) {
+ return {
+ type: 'error',
+ error: err as Error,
};
}
-
- return {
- ...data,
- id: compositionId,
- defaultProps: serializeThenDeserializeInStudio(defaultProps ?? {}),
- props: serializeThenDeserializeInStudio(
- calculatedProm.props ?? originalProps,
- ),
- defaultCodec: calculatedProm.defaultCodec ?? null,
- defaultOutName: calculatedProm.defaultOutName ?? null,
- defaultVideoImageFormat: calculatedProm.defaultVideoImageFormat ?? null,
- defaultPixelFormat: calculatedProm.defaultPixelFormat ?? null,
- defaultProResProfile: calculatedProm.defaultProResProfile ?? null,
- defaultSampleRate: calculatedProm.defaultSampleRate ?? null,
- };
};
export const resolveVideoConfigOrCatch = (
diff --git a/packages/core/src/test/composition-validation.test.tsx b/packages/core/src/test/composition-validation.test.tsx
index bffaeb1551..1d329cf8ea 100644
--- a/packages/core/src/test/composition-validation.test.tsx
+++ b/packages/core/src/test/composition-validation.test.tsx
@@ -2,7 +2,10 @@ import {afterEach, describe, expect, test} from 'bun:test';
import {cleanup, render} from '@testing-library/react';
import React from 'react';
import {Composition} from '../Composition.js';
-import {resolveVideoConfig} from '../resolve-video-config.js';
+import {
+ resolveVideoConfig,
+ resolveVideoConfigWithMetadata,
+} from '../resolve-video-config.js';
import {expectToThrow} from './expect-to-throw.js';
afterEach(() => {
@@ -415,3 +418,27 @@ test('should resolve props correctly with no calculateMetadata()', async () => {
c: 'd',
});
});
+
+test('should track which metadata was returned by calculateMetadata()', async () => {
+ const resolved = await resolveVideoConfigWithMetadata({
+ calculateMetadata: () =>
+ Promise.resolve({durationInFrames: 100, fps: 30, width: 1920}),
+ compositionDurationInFrames: 100,
+ compositionFps: 30,
+ compositionHeight: 1080,
+ compositionId: 'test',
+ compositionWidth: 1920,
+ inputProps: {},
+ signal: new AbortController().signal,
+ defaultProps: {},
+ });
+
+ expect(resolved.metadataSource).toEqual({
+ durationInFrames: 'calculate-metadata',
+ fps: 'calculate-metadata',
+ height: 'composition',
+ width: 'calculate-metadata',
+ });
+ expect(resolved.videoConfig.width).toBe(1920);
+ expect(resolved.videoConfig.height).toBe(1080);
+});
diff --git a/packages/shapes/src/test/test-utils.tsx b/packages/shapes/src/test/test-utils.tsx
index 3b45d295e1..0b9150415d 100644
--- a/packages/shapes/src/test/test-utils.tsx
+++ b/packages/shapes/src/test/test-utils.tsx
@@ -46,6 +46,7 @@ const resolveCompositionContext = {
'shape-test': {
result: videoConfig,
type: 'success' as const,
+ metadataSource: null,
},
};
diff --git a/packages/studio-server/src/codemods/recast-mods.ts b/packages/studio-server/src/codemods/recast-mods.ts
index 3639b4046b..85cf52f04f 100644
--- a/packages/studio-server/src/codemods/recast-mods.ts
+++ b/packages/studio-server/src/codemods/recast-mods.ts
@@ -651,6 +651,8 @@ const transformLoneJsxElement = (
compId === transformation.idToDelete) ||
(transformation.type === 'rename-composition' &&
compId === transformation.idToRename) ||
+ (transformation.type === 'update-composition-metadata' &&
+ compId === transformation.idToUpdate) ||
(transformation.type === 'duplicate-composition' &&
compId === transformation.idToDuplicate) ||
(transformation.type === 'delete-folder' &&
@@ -760,6 +762,24 @@ const mapJsxChild = (
];
}
+ if (
+ transformation.type === 'update-composition-metadata' &&
+ compId === transformation.idToUpdate
+ ) {
+ return [
+ changeComposition({
+ jsxElement: c,
+ newCompositionId: null,
+ newCompositionFps: transformation.newFps,
+ newCompositionDurationInFrames: transformation.newDurationInFrames,
+ newCompositionHeight: transformation.newHeight,
+ newCompositionWidth: transformation.newWidth,
+ changesMade,
+ newTagToUse: null,
+ }),
+ ];
+ }
+
if (
transformation.type === 'delete-composition' &&
compId === transformation.idToDelete
@@ -1157,7 +1177,7 @@ const changeComposition = ({
newTagToUse,
}: {
jsxElement: JSXElement;
- newCompositionId: string;
+ newCompositionId: string | null;
newCompositionFps: number | null;
newCompositionDurationInFrames: number | null;
newCompositionHeight: number | null;
@@ -1202,7 +1222,8 @@ const changeComposition = ({
if (
attribute.name.name === 'id' &&
attribute.value &&
- attribute.value.type === 'StringLiteral'
+ attribute.value.type === 'StringLiteral' &&
+ newCompositionId !== null
) {
changesMade.push({
description: 'Replaced composition id',
@@ -1219,7 +1240,8 @@ const changeComposition = ({
attribute.name.name === 'id' &&
attribute.value &&
attribute.value.type === 'JSXExpressionContainer' &&
- attribute.value.expression.type === 'StringLiteral'
+ attribute.value.expression.type === 'StringLiteral' &&
+ newCompositionId !== null
) {
changesMade.push({
description: 'Replaced composition id',
@@ -1237,34 +1259,19 @@ const changeComposition = ({
};
}
- if (
- attribute.name.name === 'fps' &&
- attribute.value &&
- attribute.value.type === 'JSXExpressionContainer' &&
- attribute.value.expression.type === 'NumericLiteral' &&
- newCompositionFps !== null
- ) {
+ if (attribute.name.name === 'fps' && newCompositionFps !== null) {
changesMade.push({
description: 'Replaced FPS',
});
return {
...attribute,
- value: {
- ...attribute.value,
- expression: {
- ...attribute.value.expression,
- value: newCompositionFps,
- },
- },
+ value: b.jsxExpressionContainer(b.numericLiteral(newCompositionFps)),
};
}
if (
attribute.name.name === 'durationInFrames' &&
- attribute.value &&
- attribute.value.type === 'JSXExpressionContainer' &&
- attribute.value.expression.type === 'NumericLiteral' &&
newCompositionDurationInFrames !== null
) {
changesMade.push({
@@ -1273,65 +1280,113 @@ const changeComposition = ({
return {
...attribute,
- value: {
- ...attribute.value,
- expression: {
- ...attribute.value.expression,
- value: newCompositionDurationInFrames,
- },
- },
+ value: b.jsxExpressionContainer(
+ b.numericLiteral(newCompositionDurationInFrames),
+ ),
};
}
- if (
- attribute.name.name === 'width' &&
- attribute.value &&
- attribute.value.type === 'JSXExpressionContainer' &&
- attribute.value.expression.type === 'NumericLiteral' &&
- newCompositionWidth !== null
- ) {
+ if (attribute.name.name === 'width' && newCompositionWidth !== null) {
changesMade.push({
description: 'Replaced width',
});
return {
...attribute,
- value: {
- ...attribute.value,
- expression: {
- ...attribute.value.expression,
- value: newCompositionWidth,
- },
- },
+ value: b.jsxExpressionContainer(
+ b.numericLiteral(newCompositionWidth),
+ ),
};
}
- if (
- attribute.name.name === 'height' &&
- attribute.value &&
- attribute.value.type === 'JSXExpressionContainer' &&
- attribute.value.expression.type === 'NumericLiteral' &&
- newCompositionHeight !== null
- ) {
+ if (attribute.name.name === 'height' && newCompositionHeight !== null) {
changesMade.push({
description: 'Replaced height',
});
return {
...attribute,
- value: {
- ...attribute.value,
- expression: {
- ...attribute.value.expression,
- value: newCompositionHeight,
- },
- },
+ value: b.jsxExpressionContainer(
+ b.numericLiteral(newCompositionHeight),
+ ),
};
}
return attribute;
})
- .filter(Boolean) as JSXAttribute[];
+ .filter(Boolean) as typeof openingElement.attributes;
+
+ if (
+ newCompositionFps !== null &&
+ !attributes.some(
+ (attribute) =>
+ attribute.type === 'JSXAttribute' &&
+ attribute.name.type === 'JSXIdentifier' &&
+ attribute.name.name === 'fps',
+ )
+ ) {
+ changesMade.push({description: 'Added FPS'});
+ attributes.push(
+ jsxAttributeWithExpression(
+ 'fps',
+ b.numericLiteral(newCompositionFps) as Expression,
+ ),
+ );
+ }
+
+ if (
+ newCompositionDurationInFrames !== null &&
+ !attributes.some(
+ (attribute) =>
+ attribute.type === 'JSXAttribute' &&
+ attribute.name.type === 'JSXIdentifier' &&
+ attribute.name.name === 'durationInFrames',
+ )
+ ) {
+ changesMade.push({description: 'Added durationInFrames'});
+ attributes.push(
+ jsxAttributeWithExpression(
+ 'durationInFrames',
+ b.numericLiteral(newCompositionDurationInFrames) as Expression,
+ ),
+ );
+ }
+
+ if (
+ newCompositionWidth !== null &&
+ !attributes.some(
+ (attribute) =>
+ attribute.type === 'JSXAttribute' &&
+ attribute.name.type === 'JSXIdentifier' &&
+ attribute.name.name === 'width',
+ )
+ ) {
+ changesMade.push({description: 'Added width'});
+ attributes.push(
+ jsxAttributeWithExpression(
+ 'width',
+ b.numericLiteral(newCompositionWidth) as Expression,
+ ),
+ );
+ }
+
+ if (
+ newCompositionHeight !== null &&
+ !attributes.some(
+ (attribute) =>
+ attribute.type === 'JSXAttribute' &&
+ attribute.name.type === 'JSXIdentifier' &&
+ attribute.name.name === 'height',
+ )
+ ) {
+ changesMade.push({description: 'Added height'});
+ attributes.push(
+ jsxAttributeWithExpression(
+ 'height',
+ b.numericLiteral(newCompositionHeight) as Expression,
+ ),
+ );
+ }
const newName = newTagToUse ?? name.name;
if (newName !== name.name) {
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 e4ab532934..a49e8c21e4 100644
--- a/packages/studio-server/src/preview-server/routes/apply-codemod.ts
+++ b/packages/studio-server/src/preview-server/routes/apply-codemod.ts
@@ -55,6 +55,10 @@ export const getCodemodLogMessage = (
return `Renamed composition "${codemod.idToRename}" to "${codemod.newId}"`;
}
+ if (codemod.type === 'update-composition-metadata') {
+ return `Updated metadata of composition "${codemod.idToUpdate}"`;
+ }
+
if (codemod.type === 'delete-composition') {
return `Deleted composition "${codemod.idToDelete}"`;
}
@@ -107,6 +111,15 @@ const getCodemodUndoDescription = (codemod: ApplyCodemodRequest['codemod']) => {
};
}
+ if (codemod.type === 'update-composition-metadata') {
+ const label = `metadata of composition "${codemod.idToUpdate}"`;
+ return {
+ undoMessage: `↩️ Update of ${label}`,
+ redoMessage: `↪️ Update of ${label}`,
+ entryType: codemod.type,
+ };
+ }
+
if (codemod.type === 'duplicate-composition') {
const label = `composition "${codemod.idToDuplicate}" to "${codemod.newId}"`;
return {
diff --git a/packages/studio-server/src/preview-server/undo-stack.ts b/packages/studio-server/src/preview-server/undo-stack.ts
index a07d5ba58b..c920c22fc4 100644
--- a/packages/studio-server/src/preview-server/undo-stack.ts
+++ b/packages/studio-server/src/preview-server/undo-stack.ts
@@ -37,6 +37,7 @@ type UndoEntryType =
| 'insert-jsx-element'
| 'delete-composition'
| 'rename-composition'
+ | 'update-composition-metadata'
| 'new-composition'
| 'duplicate-composition'
| 'move-composition-to-folder'
@@ -79,6 +80,7 @@ type UndoEntry = {
| {entryType: 'insert-jsx-element'}
| {entryType: 'delete-composition'}
| {entryType: 'rename-composition'}
+ | {entryType: 'update-composition-metadata'}
| {entryType: 'new-composition'}
| {entryType: 'duplicate-composition'}
| {entryType: 'move-composition-to-folder'}
diff --git a/packages/studio-server/src/test/apply-codemod.test.ts b/packages/studio-server/src/test/apply-codemod.test.ts
index d4040530cd..cdb825dfb3 100644
--- a/packages/studio-server/src/test/apply-codemod.test.ts
+++ b/packages/studio-server/src/test/apply-codemod.test.ts
@@ -198,6 +198,17 @@ test('formats precise log messages for all codemods', () => {
},
expected: 'Renamed composition "Original" to "Renamed"',
},
+ {
+ codemod: {
+ type: 'update-composition-metadata',
+ idToUpdate: 'Original',
+ newDurationInFrames: null,
+ newFps: null,
+ newHeight: null,
+ newWidth: 1920,
+ },
+ expected: 'Updated metadata of composition "Original"',
+ },
{
codemod: {type: 'delete-composition', idToDelete: 'DeleteMe'},
expected: 'Deleted composition "DeleteMe"',
diff --git a/packages/studio-server/src/test/recast-mods.test.ts b/packages/studio-server/src/test/recast-mods.test.ts
index ff7e3fd973..2a2f22fc56 100644
--- a/packages/studio-server/src/test/recast-mods.test.ts
+++ b/packages/studio-server/src/test/recast-mods.test.ts
@@ -108,6 +108,61 @@ test('Rename composition that is the sole return value of a wrapper component',
expect(newContents).toContain('id="Renamed"');
});
+test('Update composition metadata', () => {
+ const {newContents, changesMade} = parseAndApplyCodemod({
+ input: compositionInOwnFile,
+ codeMod: {
+ type: 'update-composition-metadata',
+ idToUpdate: 'NewVideo',
+ newDurationInFrames: 240,
+ newFps: 60,
+ newWidth: 1920,
+ newHeight: 1080,
+ },
+ });
+
+ expect(changesMade).toHaveLength(4);
+ expect(newContents).toContain('width={1920}');
+ expect(newContents).toContain('height={1080}');
+ expect(newContents).toContain('fps={60}');
+ expect(newContents).toContain('durationInFrames={240}');
+});
+
+test('Update a composition dimension that is not a numeric literal', () => {
+ const input = compositionInOwnFile.replace('width={1280}', 'width={WIDTH}');
+ const {newContents} = parseAndApplyCodemod({
+ input,
+ codeMod: {
+ type: 'update-composition-metadata',
+ idToUpdate: 'NewVideo',
+ newDurationInFrames: null,
+ newFps: null,
+ newWidth: 1920,
+ newHeight: null,
+ },
+ });
+
+ expect(newContents).toContain('width={1920}');
+ expect(newContents).not.toContain('width={WIDTH}');
+});
+
+test('Add a missing composition dimension', () => {
+ const input = compositionInOwnFile.replace('\n\t\t\theight={720}', '');
+ const {newContents} = parseAndApplyCodemod({
+ input,
+ codeMod: {
+ type: 'update-composition-metadata',
+ idToUpdate: 'NewVideo',
+ newDurationInFrames: null,
+ newFps: null,
+ newWidth: null,
+ newHeight: 1080,
+ },
+ });
+
+ expect(newContents).toContain('height={1080}');
+});
+
test('Duplicate composition that is the sole return value of a wrapper component', () => {
const {newContents, changesMade} = parseAndApplyCodemod({
input: compositionInOwnFile,
diff --git a/packages/studio-shared/src/codemods.ts b/packages/studio-shared/src/codemods.ts
index e4ae85da61..061c4fccb8 100644
--- a/packages/studio-shared/src/codemods.ts
+++ b/packages/studio-shared/src/codemods.ts
@@ -40,6 +40,14 @@ export type RecastCodemod =
idToRename: string;
newId: string;
}
+ | {
+ type: 'update-composition-metadata';
+ idToUpdate: string;
+ newDurationInFrames: number | null;
+ newFps: number | null;
+ newHeight: number | null;
+ newWidth: number | null;
+ }
| {
type: 'delete-composition';
idToDelete: string;
diff --git a/packages/studio/src/ResolveCompositionConfigInStudio.tsx b/packages/studio/src/ResolveCompositionConfigInStudio.tsx
index b3edf9f836..331d7b12c9 100644
--- a/packages/studio/src/ResolveCompositionConfigInStudio.tsx
+++ b/packages/studio/src/ResolveCompositionConfigInStudio.tsx
@@ -16,11 +16,23 @@ type VideoConfigState =
}
| {
type: 'success';
- result: Record<string, unknown>;
+ result: VideoConfig;
+ metadataSource: {
+ readonly durationInFrames: 'calculate-metadata' | 'composition';
+ readonly fps: 'calculate-metadata' | 'composition';
+ readonly height: 'calculate-metadata' | 'composition';
+ readonly width: 'calculate-metadata' | 'composition';
+ };
}
| {
type: 'success-and-refreshing';
- result: Record<string, unknown>;
+ result: VideoConfig;
+ metadataSource: {
+ readonly durationInFrames: 'calculate-metadata' | 'composition';
+ readonly fps: 'calculate-metadata' | 'composition';
+ readonly height: 'calculate-metadata' | 'composition';
+ readonly width: 'calculate-metadata' | 'composition';
+ };
}
| {
type: 'error';
@@ -110,10 +122,10 @@ export const ResolveCompositionConfigInStudio: React.FC<
const {signal} = controller;
- const result = Internals.resolveVideoConfigOrCatch({
+ const result = Internals.resolveVideoConfigWithMetadataOrCatch({
compositionId,
calculateMetadata: calculateMetadata as Parameters<
- typeof Internals.resolveVideoConfigOrCatch
+ typeof Internals.resolveVideoConfigWithMetadataOrCatch
>[0]['calculateMetadata'],
inputProps: combinedProps,
signal,
@@ -149,6 +161,7 @@ export const ResolveCompositionConfigInStudio: React.FC<
[compositionId]: {
type: 'success-and-refreshing',
result: prev.result,
+ metadataSource: prev.metadataSource,
},
};
}
@@ -170,7 +183,8 @@ export const ResolveCompositionConfigInStudio: React.FC<
...r,
[compositionId]: {
type: 'success',
- result: c,
+ result: c.videoConfig,
+ metadataSource: c.metadataSource,
},
}));
})
@@ -192,7 +206,8 @@ export const ResolveCompositionConfigInStudio: React.FC<
...r,
[compositionId]: {
type: 'success',
- result: promOrNot,
+ result: promOrNot.videoConfig,
+ metadataSource: promOrNot.metadataSource,
},
}));
}
@@ -221,7 +236,7 @@ export const ResolveCompositionConfigInStudio: React.FC<
...(inputProps ?? {}),
};
const controller = new AbortController();
- const result = Internals.resolveVideoConfigOrCatch({
+ const result = Internals.resolveVideoConfigWithMetadataOrCatch({
compositionId: composition.id,
calculateMetadata: composition.calculateMetadata,
inputProps: combinedProps,
@@ -242,11 +257,12 @@ export const ResolveCompositionConfigInStudio: React.FC<
...configs,
[composition.id]: {
type: 'success',
- result: resolved,
+ result: resolved.videoConfig,
+ metadataSource: resolved.metadataSource,
},
}));
- return resolved;
+ return resolved.videoConfig;
},
[allEditorProps, compositions, inputProps],
);
@@ -414,6 +430,12 @@ export const ResolveCompositionConfigInStudio: React.FC<
[curr.id]: {
type: 'success',
result: {...curr, defaultProps: curr.defaultProps ?? {}},
+ metadataSource: {
+ durationInFrames: 'composition',
+ fps: 'composition',
+ height: 'composition',
+ width: 'composition',
+ },
},
};
}, {}),
diff --git a/packages/studio/src/components/CurrentComposition.tsx b/packages/studio/src/components/CurrentComposition.tsx
index 5782cb3db3..6b948e58a1 100644
--- a/packages/studio/src/components/CurrentComposition.tsx
+++ b/packages/studio/src/components/CurrentComposition.tsx
@@ -16,10 +16,8 @@ import {
import {ReactIcon} from '../icons/react';
import {StillIcon} from '../icons/still';
import {FilmIcon} from '../icons/video';
-import {renderFrame} from '../state/render-frame';
import {InlineCompositionName} from './InlineCompositionName';
import {
- INSPECTOR_INFO_HEADER_MIN_HEIGHT,
InspectorInfoHeader,
InspectorInfoSubtitle,
} from './InspectorInfoHeader';
@@ -28,7 +26,7 @@ import {InspectorSourceLocation} from './InspectorSourceLocation';
import {showNotification} from './Notifications/NotificationCenter';
import {useResolvedStack} from './Timeline/use-resolved-stack';
-export const CURRENT_COMPOSITION_HEIGHT = INSPECTOR_INFO_HEADER_MIN_HEIGHT;
+export const CURRENT_COMPOSITION_HEIGHT = 66;
const sourceLocationIconStyle: CSSProperties = {
flexShrink: 0,
@@ -124,7 +122,7 @@ export const CurrentComposition = () => {
);
return (
- <InspectorInfoHeader>
+ <InspectorInfoHeader minHeight={CURRENT_COMPOSITION_HEIGHT}>
{video ? (
<>
<InspectorLocationCopy location={validatedLocation} name={video.id}>
@@ -147,17 +145,9 @@ export const CurrentComposition = () => {
renderIcon={renderReactIcon}
/>
</InspectorLocationCopy>
- <InspectorInfoSubtitle>
- {video.width}x{video.height}
- {isCompositionStill(video) ? null : `, ${video.fps} FPS`}
- </InspectorInfoSubtitle>
{isCompositionStill(video) ? (
<InspectorInfoSubtitle>Still</InspectorInfoSubtitle>
- ) : (
- <InspectorInfoSubtitle>
- Duration {renderFrame(video.durationInFrames, video.fps)}
- </InspectorInfoSubtitle>
- )}
+ ) : null}
</>
) : null}
</InspectorInfoHeader>
diff --git a/packages/studio/src/components/InspectorInfoHeader.tsx b/packages/studio/src/components/InspectorInfoHeader.tsx
index e3201d25b2..77614a3150 100644
--- a/packages/studio/src/components/InspectorInfoHeader.tsx
+++ b/packages/studio/src/components/InspectorInfoHeader.tsx
@@ -52,9 +52,16 @@ const subtitle: React.CSSProperties = {
export const InspectorInfoHeader: React.FC<{
readonly children?: React.ReactNode;
readonly contentSized?: boolean;
-}> = ({children, contentSized = false}) => {
+ readonly minHeight?: number;
+}> = ({children, contentSized = false, minHeight}) => {
+ const style = contentSized
+ ? containerBase
+ : minHeight === undefined
+ ? container
+ : {...containerBase, minHeight};
+
return (
- <div style={contentSized ? containerBase : container}>
+ <div style={style}>
{children === undefined || children === null ? null : (
<div style={row}>
<div style={content}>{children}</div>
diff --git a/packages/studio/src/components/InspectorPanel/CompositionDimensions.tsx b/packages/studio/src/components/InspectorPanel/CompositionDimensions.tsx
new file mode 100644
index 0000000000..65a7d12b5e
--- /dev/null
+++ b/packages/studio/src/components/InspectorPanel/CompositionDimensions.tsx
@@ -0,0 +1,358 @@
+import type {
+ RecastCodemod,
+ SymbolicatedStackFrame,
+} from '@remotion/studio-shared';
+import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
+import {Internals} from 'remotion';
+import {WHITE_ALPHA_40} from '../../helpers/colors';
+import {isCompositionStill} from '../../helpers/is-composition-still';
+import {resolvedStackToSymbolicated} from '../../helpers/resolved-stack-to-symbolicated';
+import {InputDragger} from '../NewComposition/InputDragger';
+import {showNotification} from '../Notifications/NotificationCenter';
+import {applyCodemod} from '../RenderQueue/actions';
+import {useResolvedStack} from '../Timeline/use-resolved-stack';
+import {InspectorDetailRow} from './common';
+import {
+ acceptPendingCompositionMetadataValue,
+ type CompositionMetadataField,
+ failPendingCompositionMetadataValue,
+ type PendingCompositionMetadata,
+ type PendingCompositionMetadataValue,
+ reconcilePendingCompositionMetadata,
+} from './optimistic-composition-metadata';
+import {detailsContainer} from './styles';
+
+const fieldLabels: Record<CompositionMetadataField, string> = {
+ durationInFrames: 'Duration',
+ fps: 'Frame rate',
+ height: 'Height',
+ width: 'Width',
+};
+
+const computedStyle: React.CSSProperties = {
+ color: WHITE_ALPHA_40,
+ fontFamily: 'sans-serif',
+ fontSize: 12,
+ fontStyle: 'italic',
+ lineHeight: '16px',
+ userSelect: 'none',
+};
+
+const dimensionsControls: React.CSSProperties = {
+ alignItems: 'center',
+ display: 'flex',
+ fontFamily: 'sans-serif',
+ fontSize: 12,
+ gap: 4,
+ justifyContent: 'flex-end',
+ lineHeight: '16px',
+ minWidth: 0,
+};
+
+const CompositionMetadataValue: React.FC<{
+ readonly compositionId: string;
+ readonly computed: boolean;
+ readonly disabled: boolean;
+ readonly field: CompositionMetadataField;
+ readonly onPendingValue: (
+ field: CompositionMetadataField,
+ value: PendingCompositionMetadataValue,
+ ) => void;
+ readonly onPendingValueAccepted: (
+ field: CompositionMetadataField,
+ value: PendingCompositionMetadataValue,
+ ) => void;
+ readonly onPendingValueFailed: (
+ field: CompositionMetadataField,
+ value: PendingCompositionMetadataValue,
+ ) => void;
+ readonly pendingValue: PendingCompositionMetadataValue | null;
+ readonly resolvedConfig: object;
+ readonly symbolicatedStack: SymbolicatedStackFrame | null;
+ readonly value: number;
+}> = ({
+ compositionId,
+ computed,
+ disabled,
+ field,
+ onPendingValue,
+ onPendingValueAccepted,
+ onPendingValueFailed,
+ pendingValue,
+ resolvedConfig,
+ symbolicatedStack,
+ value,
+}) => {
+ const [dragValue, setDragValue] = useState<number | null>(null);
+
+ const save = useCallback(
+ (newValue: number) => {
+ if (newValue === (pendingValue?.value ?? value)) {
+ setDragValue(null);
+ return;
+ }
+
+ if (symbolicatedStack === null) {
+ setDragValue(null);
+ showNotification(
+ 'Could not determine where this composition is defined',
+ 2000,
+ );
+ return;
+ }
+
+ const codemod: RecastCodemod = {
+ type: 'update-composition-metadata',
+ idToUpdate: compositionId,
+ newDurationInFrames: field === 'durationInFrames' ? newValue : null,
+ newFps: field === 'fps' ? newValue : null,
+ newHeight: field === 'height' ? newValue : null,
+ newWidth: field === 'width' ? newValue : null,
+ };
+ const optimisticValue: PendingCompositionMetadataValue = {
+ baseline: resolvedConfig,
+ status: 'saving',
+ value: newValue,
+ };
+ onPendingValue(field, optimisticValue);
+ setDragValue(null);
+ applyCodemod({
+ codemod,
+ dryRun: false,
+ signal: new AbortController().signal,
+ symbolicatedStack,
+ })
+ .then((result) => {
+ if (!result.success) {
+ onPendingValueFailed(field, optimisticValue);
+ showNotification(
+ `Could not update composition ${field}: ${result.reason}`,
+ 2000,
+ );
+ return;
+ }
+
+ onPendingValueAccepted(field, optimisticValue);
+ })
+ .catch((error) => {
+ onPendingValueFailed(field, optimisticValue);
+ showNotification(
+ `Could not update composition ${field}: ${(error as Error).message}`,
+ 2000,
+ );
+ });
+ },
+ [
+ compositionId,
+ field,
+ onPendingValue,
+ onPendingValueAccepted,
+ onPendingValueFailed,
+ pendingValue?.value,
+ resolvedConfig,
+ symbolicatedStack,
+ value,
+ ],
+ );
+ const isFps = field === 'fps';
+ const formatValue = useCallback(
+ (newValue: number | string) => {
+ const numberValue = Number(newValue);
+ if (field === 'fps') {
+ return `${numberValue}fps`;
+ }
+
+ const roundedValue = Math.round(numberValue);
+ if (field === 'durationInFrames') {
+ return `${roundedValue} ${roundedValue === 1 ? 'frame' : 'frames'}`;
+ }
+
+ return String(roundedValue);
+ },
+ [field],
+ );
+
+ return computed ? (
+ <span style={computedStyle}>{formatValue(value)}</span>
+ ) : disabled ? (
+ formatValue(value)
+ ) : (
+ <InputDragger
+ aria-label={fieldLabels[field]}
+ type="number"
+ value={dragValue ?? pendingValue?.value ?? value}
+ disabled={pendingValue !== null}
+ status="ok"
+ onValueChange={setDragValue}
+ onValueChangeEnd={save}
+ onTextChange={() => undefined}
+ min={isFps ? 0.01 : 1}
+ step={isFps ? 0.01 : 1}
+ dragDecimalPlaces={isFps ? 2 : 0}
+ formatter={formatValue}
+ rightAlign
+ small
+ />
+ );
+};
+
+export const CompositionDimensions: React.FC<{
+ readonly compositionId: string;
+ readonly disabled: boolean;
+ readonly stack: string | null;
+}> = ({compositionId, disabled, stack}) => {
+ const video = Internals.useVideo();
+ const resolvedVideoConfig = Internals.useResolvedVideoConfig(compositionId);
+ const resolvedConfig =
+ resolvedVideoConfig?.type === 'success' ||
+ resolvedVideoConfig?.type === 'success-and-refreshing'
+ ? resolvedVideoConfig.result
+ : null;
+ const resolvedConfigRef = useRef(resolvedConfig);
+ resolvedConfigRef.current = resolvedConfig;
+ const [pendingValues, setPendingValues] =
+ useState<PendingCompositionMetadata>({});
+ const resolvedLocation = useResolvedStack(stack);
+ const symbolicatedStack = useMemo(
+ () => resolvedStackToSymbolicated(resolvedLocation),
+ [resolvedLocation],
+ );
+ useEffect(() => {
+ if (resolvedConfig === null) {
+ return;
+ }
+
+ setPendingValues((pending) =>
+ reconcilePendingCompositionMetadata({
+ currentConfig: resolvedConfig,
+ pending,
+ }),
+ );
+ }, [resolvedConfig]);
+
+ const onPendingValue = useCallback(
+ (
+ field: CompositionMetadataField,
+ value: PendingCompositionMetadataValue,
+ ) => {
+ setPendingValues((pending) => ({...pending, [field]: value}));
+ },
+ [],
+ );
+ const onPendingValueAccepted = useCallback(
+ (
+ field: CompositionMetadataField,
+ value: PendingCompositionMetadataValue,
+ ) => {
+ setPendingValues((pending) => {
+ if (resolvedConfigRef.current === null) {
+ return pending;
+ }
+
+ return acceptPendingCompositionMetadataValue({
+ currentConfig: resolvedConfigRef.current,
+ field,
+ pending,
+ value,
+ });
+ });
+ },
+ [],
+ );
+ const onPendingValueFailed = useCallback(
+ (
+ field: CompositionMetadataField,
+ value: PendingCompositionMetadataValue,
+ ) => {
+ setPendingValues((pending) =>
+ failPendingCompositionMetadataValue({field, pending, value}),
+ );
+ },
+ [],
+ );
+
+ if (video === null || resolvedConfig === null) {
+ return null;
+ }
+
+ const metadataSource =
+ resolvedVideoConfig?.type === 'success' ||
+ resolvedVideoConfig?.type === 'success-and-refreshing'
+ ? resolvedVideoConfig.metadataSource
+ : undefined;
+ const widthIsComputed = metadataSource?.width === 'calculate-metadata';
+ const heightIsComputed = metadataSource?.height === 'calculate-metadata';
+ const fpsIsComputed = metadataSource?.fps === 'calculate-metadata';
+ const durationIsComputed =
+ metadataSource?.durationInFrames === 'calculate-metadata';
+ const isStill = isCompositionStill(video);
+
+ return (
+ <div style={detailsContainer}>
+ <InspectorDetailRow label="Dimensions">
+ <div style={dimensionsControls}>
+ <CompositionMetadataValue
+ compositionId={compositionId}
+ computed={widthIsComputed}
+ disabled={disabled}
+ field="width"
+ onPendingValue={onPendingValue}
+ onPendingValueAccepted={onPendingValueAccepted}
+ onPendingValueFailed={onPendingValueFailed}
+ pendingValue={pendingValues.width ?? null}
+ resolvedConfig={resolvedConfig}
+ symbolicatedStack={symbolicatedStack}
+ value={video.width}
+ />
+ <CompositionMetadataValue
+ compositionId={compositionId}
+ computed={heightIsComputed}
+ disabled={disabled}
+ field="height"
+ onPendingValue={onPendingValue}
+ onPendingValueAccepted={onPendingValueAccepted}
+ onPendingValueFailed={onPendingValueFailed}
+ pendingValue={pendingValues.height ?? null}
+ resolvedConfig={resolvedConfig}
+ symbolicatedStack={symbolicatedStack}
+ value={video.height}
+ />
+ </div>
+ </InspectorDetailRow>
+ {isStill ? null : (
+ <>
+ <InspectorDetailRow label="Frame rate">
+ <CompositionMetadataValue
+ compositionId={compositionId}
+ computed={fpsIsComputed}
+ disabled={disabled}
+ field="fps"
+ onPendingValue={onPendingValue}
+ onPendingValueAccepted={onPendingValueAccepted}
+ onPendingValueFailed={onPendingValueFailed}
+ pendingValue={pendingValues.fps ?? null}
+ resolvedConfig={resolvedConfig}
+ symbolicatedStack={symbolicatedStack}
+ value={video.fps}
+ />
+ </InspectorDetailRow>
+ <InspectorDetailRow label="Duration">
+ <CompositionMetadataValue
+ compositionId={compositionId}
+ computed={durationIsComputed}
+ disabled={disabled}
+ field="durationInFrames"
+ onPendingValue={onPendingValue}
+ onPendingValueAccepted={onPendingValueAccepted}
+ onPendingValueFailed={onPendingValueFailed}
+ pendingValue={pendingValues.durationInFrames ?? null}
+ resolvedConfig={resolvedConfig}
+ symbolicatedStack={symbolicatedStack}
+ value={video.durationInFrames}
+ />
+ </InspectorDetailRow>
+ </>
+ )}
+ </div>
+ );
+};
diff --git a/packages/studio/src/components/InspectorPanel/DefaultInspector.tsx b/packages/studio/src/components/InspectorPanel/DefaultInspector.tsx
index 30c75d0509..4506872e62 100644
--- a/packages/studio/src/components/InspectorPanel/DefaultInspector.tsx
+++ b/packages/studio/src/components/InspectorPanel/DefaultInspector.tsx
@@ -26,6 +26,7 @@ import {
InspectorSectionDivider,
InspectorSectionHeader,
} from './common';
+import {CompositionDimensions} from './CompositionDimensions';
import {
compositionSection,
container,
@@ -124,6 +125,12 @@ export const DefaultInspector: React.FC<{
<div style={scrollableContainer} className={VERTICAL_SCROLLBAR_CLASSNAME}>
<div style={compositionSection}>
<CurrentComposition />
+ <InspectorSectionDivider />
+ <CompositionDimensions
+ compositionId={composition.id}
+ disabled={readOnlyStudio}
+ stack={composition.stack}
+ />
</div>
{canShowDefaultPropsSection ? (
<>
diff --git a/packages/studio/src/components/InspectorPanel/optimistic-composition-metadata.ts b/packages/studio/src/components/InspectorPanel/optimistic-composition-metadata.ts
new file mode 100644
index 0000000000..ec13b02035
--- /dev/null
+++ b/packages/studio/src/components/InspectorPanel/optimistic-composition-metadata.ts
@@ -0,0 +1,89 @@
+export type CompositionMetadataField =
+ | 'durationInFrames'
+ | 'fps'
+ | 'height'
+ | 'width';
+
+export type PendingCompositionMetadataValue = {
+ readonly baseline: object;
+ readonly status: 'saving' | 'awaiting-hmr';
+ readonly value: number;
+};
+
+export type PendingCompositionMetadata = Partial<
+ Record<CompositionMetadataField, PendingCompositionMetadataValue>
+>;
+
+const removePendingValue = ({
+ field,
+ pending,
+}: {
+ readonly field: CompositionMetadataField;
+ readonly pending: PendingCompositionMetadata;
+}): PendingCompositionMetadata => {
+ const {[field]: _removed, ...remaining} = pending;
+ return remaining;
+};
+
+export const failPendingCompositionMetadataValue = ({
+ field,
+ pending,
+ value,
+}: {
+ readonly field: CompositionMetadataField;
+ readonly pending: PendingCompositionMetadata;
+ readonly value: PendingCompositionMetadataValue;
+}): PendingCompositionMetadata => {
+ if (pending[field] !== value) {
+ return pending;
+ }
+
+ return removePendingValue({field, pending});
+};
+
+export const acceptPendingCompositionMetadataValue = ({
+ currentConfig,
+ field,
+ pending,
+ value,
+}: {
+ readonly currentConfig: object;
+ readonly field: CompositionMetadataField;
+ readonly pending: PendingCompositionMetadata;
+ readonly value: PendingCompositionMetadataValue;
+}): PendingCompositionMetadata => {
+ if (pending[field] !== value) {
+ return pending;
+ }
+
+ if (currentConfig !== value.baseline) {
+ return removePendingValue({field, pending});
+ }
+
+ return {
+ ...pending,
+ [field]: {
+ ...value,
+ status: 'awaiting-hmr',
+ },
+ };
+};
+
+export const reconcilePendingCompositionMetadata = ({
+ currentConfig,
+ pending,
+}: {
+ readonly currentConfig: object;
+ readonly pending: PendingCompositionMetadata;
+}): PendingCompositionMetadata => {
+ let reconciled = pending;
+
+ for (const field of Object.keys(pending) as CompositionMetadataField[]) {
+ const value = pending[field];
+ if (value?.status === 'awaiting-hmr' && value.baseline !== currentConfig) {
+ reconciled = removePendingValue({field, pending: reconciled});
+ }
+ }
+
+ return reconciled;
+};
diff --git a/packages/studio/src/components/InspectorPanel/styles.ts b/packages/studio/src/components/InspectorPanel/styles.ts
index 1f8cf9e76f..e7bfcac3cf 100644
--- a/packages/studio/src/components/InspectorPanel/styles.ts
+++ b/packages/studio/src/components/InspectorPanel/styles.ts
@@ -198,7 +198,6 @@ export const detailRow: React.CSSProperties = {
display: 'flex',
gap: 12,
justifyContent: 'space-between',
- padding: '10px 0',
};
export const detailLabel: React.CSSProperties = {
diff --git a/packages/studio/src/test/optimistic-composition-metadata.test.ts b/packages/studio/src/test/optimistic-composition-metadata.test.ts
new file mode 100644
index 0000000000..d7419ee708
--- /dev/null
+++ b/packages/studio/src/test/optimistic-composition-metadata.test.ts
@@ -0,0 +1,97 @@
+import {expect, test} from 'bun:test';
+import {
+ acceptPendingCompositionMetadataValue,
+ failPendingCompositionMetadataValue,
+ type PendingCompositionMetadata,
+ type PendingCompositionMetadataValue,
+ reconcilePendingCompositionMetadata,
+} from '../components/InspectorPanel/optimistic-composition-metadata';
+
+const makePendingValue = (
+ baseline: object,
+): PendingCompositionMetadataValue => ({
+ baseline,
+ status: 'saving',
+ value: 1920,
+});
+
+test('keeps the optimistic value until HMR updates the resolved config', () => {
+ const baseline = {width: 1280};
+ const value = makePendingValue(baseline);
+ const pending: PendingCompositionMetadata = {width: value};
+ const accepted = acceptPendingCompositionMetadataValue({
+ currentConfig: baseline,
+ field: 'width',
+ pending,
+ value,
+ });
+
+ expect(accepted.width).toEqual({...value, status: 'awaiting-hmr'});
+ expect(
+ reconcilePendingCompositionMetadata({
+ currentConfig: baseline,
+ pending: accepted,
+ }).width,
+ ).toBeDefined();
+ expect(
+ reconcilePendingCompositionMetadata({
+ currentConfig: {width: 1920},
+ pending: accepted,
+ }).width,
+ ).toBeUndefined();
+});
+
+test('reconciles when undo produces a new config with the original value', () => {
+ const baseline = {width: 1280};
+ const value = makePendingValue(baseline);
+ const accepted = acceptPendingCompositionMetadataValue({
+ currentConfig: baseline,
+ field: 'width',
+ pending: {width: value},
+ value,
+ });
+
+ expect(
+ reconcilePendingCompositionMetadata({
+ currentConfig: {width: 1280},
+ pending: accepted,
+ }).width,
+ ).toBeUndefined();
+});
+
+test('handles HMR completing before the codemod response', () => {
+ const baseline = {width: 1280};
+ const value = makePendingValue(baseline);
+ const pending: PendingCompositionMetadata = {width: value};
+ const refreshed = {width: 1920};
+
+ expect(
+ reconcilePendingCompositionMetadata({
+ currentConfig: refreshed,
+ pending,
+ }),
+ ).toBe(pending);
+ expect(
+ acceptPendingCompositionMetadataValue({
+ currentConfig: refreshed,
+ field: 'width',
+ pending,
+ value,
+ }).width,
+ ).toBeUndefined();
+});
+
+test('does not clear a newer pending edit when an older request fails', () => {
+ const baseline = {width: 1280};
+ const older = makePendingValue(baseline);
+ const newer = {...makePendingValue(baseline), value: 2560};
+ const pending: PendingCompositionMetadata = {width: newer};
+
+ expect(
+ failPendingCompositionMetadataValue({
+ field: 'width',
+ pending,
+ value: older,
+ }),
+ ).toBe(pending);
+});