Skip to content

🎥 Make videos programmatically with React

Prevent enum fields from being keyframed (#8081)

Jonny Burger8bdbc1e1a26a
diff --git a/packages/studio-server/src/test/update-keyframes.test.ts b/packages/studio-server/src/test/update-keyframes.test.ts
index 3437047208..951a5e0dd9 100644
--- a/packages/studio-server/src/test/update-keyframes.test.ts
+++ b/packages/studio-server/src/test/update-keyframes.test.ts
@@ -189,6 +189,25 @@ test('updateSequenceKeyframes rejects non-keyframable fields', async () => {
).rejects.toThrow(/not keyframable/);
});
+test('updateSequenceKeyframes rejects enum fields', async () => {
+ await expect(
+ updateSequenceKeyframes({
+ input: sequenceInput,
+ nodePath: lineColumnToNodePath(
+ sequenceInput,
+ getLine(sequenceInput, '<AbsoluteFill>'),
+ ),
+ schema: NoReactInternals.sequenceSchema,
+ updates: [
+ {
+ key: 'layout',
+ operation: {type: 'add', frame: 25, value: 'none'},
+ },
+ ],
+ }),
+ ).rejects.toThrow(/not keyframable/);
+});
+
test('updateSequenceKeyframes converts a static value to a single-keyframe interpolation at frame 0', async () => {
const {output, oldValueStrings} = await updateSequenceKeyframes({
input: sequenceInput,
diff --git a/packages/studio-shared/src/keyframe-interpolation-function.ts b/packages/studio-shared/src/keyframe-interpolation-function.ts
index f332ec0132..5ec304ed61 100644
--- a/packages/studio-shared/src/keyframe-interpolation-function.ts
+++ b/packages/studio-shared/src/keyframe-interpolation-function.ts
@@ -48,7 +48,7 @@ export const isSchemaFieldKeyframable = ({
key: string;
}): boolean => {
const field = schema ? findFieldInSchema(schema, key) : undefined;
- return field?.keyframable !== false;
+ return field?.type !== 'enum' && field?.keyframable !== false;
};
export const getKeyframeInterpolationFunctionForSchemaField = ({
diff --git a/packages/studio-shared/src/test/keyframe-interpolation-function.test.ts b/packages/studio-shared/src/test/keyframe-interpolation-function.test.ts
new file mode 100644
index 0000000000..1b4ac8daf1
--- /dev/null
+++ b/packages/studio-shared/src/test/keyframe-interpolation-function.test.ts
@@ -0,0 +1,53 @@
+import {expect, test} from 'bun:test';
+import type {SequenceSchema} from 'remotion';
+import {isSchemaFieldKeyframable} from '../keyframe-interpolation-function';
+
+test('isSchemaFieldKeyframable rejects enum fields', () => {
+ const schema = {
+ layout: {
+ type: 'enum',
+ default: 'absolute-fill',
+ keyframable: true,
+ variants: {
+ 'absolute-fill': {},
+ none: {},
+ },
+ },
+ } satisfies SequenceSchema;
+
+ expect(isSchemaFieldKeyframable({schema, key: 'layout'})).toBe(false);
+});
+
+test('isSchemaFieldKeyframable rejects explicitly disabled fields', () => {
+ const schema = {
+ playbackRate: {
+ type: 'number',
+ default: 1,
+ hiddenFromList: false,
+ keyframable: false,
+ },
+ } satisfies SequenceSchema;
+
+ expect(isSchemaFieldKeyframable({schema, key: 'playbackRate'})).toBe(false);
+});
+
+test('isSchemaFieldKeyframable finds keyframable fields in enum variants', () => {
+ const schema = {
+ layout: {
+ type: 'enum',
+ default: 'absolute-fill',
+ variants: {
+ 'absolute-fill': {
+ 'style.opacity': {
+ type: 'number',
+ default: 1,
+ hiddenFromList: false,
+ },
+ },
+ none: {},
+ },
+ },
+ } satisfies SequenceSchema;
+
+ expect(isSchemaFieldKeyframable({schema, key: 'style.opacity'})).toBe(true);
+});
diff --git a/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts b/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts
index f1498092a9..e6d4d73823 100644
--- a/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts
+++ b/packages/studio-shared/src/test/optimistic-add-keyframe.test.ts
@@ -149,6 +149,39 @@ test('optimisticAddSequenceKeyframe ignores non-keyframable fields', () => {
expect(updated).toEqual(previous);
});
+test('optimisticAddSequenceKeyframe ignores enum fields', () => {
+ const previous: CanUpdateSequencePropsResponse = {
+ canUpdate: true,
+ props: {
+ layout: {
+ status: 'static',
+ codeValue: 'absolute-fill',
+ },
+ },
+ effects: [],
+ };
+ const schema = {
+ layout: {
+ type: 'enum',
+ default: 'absolute-fill',
+ variants: {
+ 'absolute-fill': {},
+ none: {},
+ },
+ },
+ } satisfies SequenceSchema;
+
+ const updated = optimisticAddSequenceKeyframe({
+ previous,
+ fieldKey: 'layout',
+ frame: 25,
+ value: 'none',
+ schema,
+ });
+
+ expect(updated).toEqual(previous);
+});
+
test('optimisticAddSequenceKeyframe appends a keyframe to an existing interpolation', () => {
const previous: CanUpdateSequencePropsResponse = {
canUpdate: true,
diff --git a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
index 2309d72f66..b6b64a5486 100644
--- a/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineEffectPropItem.tsx
@@ -1,4 +1,7 @@
-import {optimisticUpdateForEffectCodeValues} from '@remotion/studio-shared';
+import {
+ isSchemaFieldKeyframable,
+ optimisticUpdateForEffectCodeValues,
+} from '@remotion/studio-shared';
import React, {useCallback, useContext, useMemo} from 'react';
import type {
CanUpdateSequencePropStatus,
@@ -328,7 +331,10 @@ export const TimelineEffectPropItem: React.FC<{
shouldShowTimelineKeyframeControls({
propStatus,
selected: selection.selected,
- keyframable: field.fieldSchema.keyframable !== false,
+ keyframable: isSchemaFieldKeyframable({
+ schema: field.effectSchema,
+ key: field.key,
+ }),
}) ? (
<TimelineKeyframeControls
fieldKey={field.key}
diff --git a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
index 69065426f0..cf47ff5c7d 100644
--- a/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
+++ b/packages/studio/src/components/Timeline/TimelineKeyframeControls.tsx
@@ -1,3 +1,4 @@
+import {isSchemaFieldKeyframable} from '@remotion/studio-shared';
import React, {useCallback, useContext, useMemo} from 'react';
import type {
CanUpdateSequencePropStatus,
@@ -195,8 +196,10 @@ export const TimelineKeyframeControls: React.FC<{
[keyframes, timelinePosition],
);
- const fieldSchema = schema[fieldKey];
- const keyframable = fieldSchema?.keyframable !== false;
+ const keyframable = isSchemaFieldKeyframable({
+ schema,
+ key: fieldKey,
+ });
const canAddKeyframe = keyframable;
const canToggleKeyframe =
propStatus.status !== 'computed' &&
diff --git a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
index c52f6c2af5..4b17f47693 100644
--- a/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequencePropItem.tsx
@@ -1,3 +1,4 @@
+import {isSchemaFieldKeyframable} from '@remotion/studio-shared';
import React, {useCallback, useContext, useMemo} from 'react';
import type {
CanUpdateSequencePropStatus,
@@ -203,7 +204,10 @@ export const TimelineSequencePropItem: React.FC<{
shouldShowTimelineKeyframeControls({
propStatus: codeValue,
selected: selection.selected,
- keyframable: field.fieldSchema.keyframable !== false,
+ keyframable: isSchemaFieldKeyframable({
+ schema,
+ key: field.key,
+ }),
}) ? (
<TimelineKeyframeControls
fieldKey={field.key}