Skip to content

🎥 Make videos programmatically with React

remotion: Make Sequence freeze nullable

Jonny Burger15c23cf949ab
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index 9a3bcee5ca..11d655be1d 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -55,7 +55,7 @@ export type SequencePropsWithoutDuration = {
readonly width?: number;
readonly height?: number;
readonly from?: number;
- readonly freeze?: number;
+ readonly freeze?: number | null;
readonly name?: string;
readonly showInTimeline?: boolean;
readonly hidden?: boolean;
@@ -188,7 +188,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
);
}
- if (typeof freeze !== 'undefined') {
+ if (typeof freeze !== 'undefined' && freeze !== null) {
if (typeof freeze !== 'number') {
throw new TypeError(
`The "freeze" prop of <Sequence /> must be a number, but is of type ${typeof freeze}.`,
@@ -427,7 +427,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
? null
: children;
const frozenContent =
- content === null || typeof freeze === 'undefined' ? (
+ content === null || typeof freeze === 'undefined' || freeze === null ? (
content
) : (
<Freeze frame={freeze}>{content}</Freeze>
diff --git a/packages/core/src/sequence-field-schema.ts b/packages/core/src/sequence-field-schema.ts
index 6443ee9075..11b0dc97ae 100644
--- a/packages/core/src/sequence-field-schema.ts
+++ b/packages/core/src/sequence-field-schema.ts
@@ -8,7 +8,7 @@ export type NumberFieldSchema = {
min?: number;
max?: number;
step?: number;
- default: number | undefined;
+ default: number | null | undefined;
description?: string;
hiddenFromList: boolean;
keyframable?: boolean;
@@ -280,7 +280,7 @@ export const fromField = {
export const freezeField = {
type: 'number',
- default: undefined,
+ default: null,
step: 1,
hiddenFromList: true,
} as const satisfies SequenceFieldSchema;
diff --git a/packages/core/src/test/sequence-validation.test.tsx b/packages/core/src/test/sequence-validation.test.tsx
index 31d716cf13..8626446af7 100644
--- a/packages/core/src/test/sequence-validation.test.tsx
+++ b/packages/core/src/test/sequence-validation.test.tsx
@@ -91,6 +91,15 @@ describe('Composition-validation render should throw with invalid props', () =>
);
});
});
+ describe('Allow valid freeze props', () => {
+ test('It should allow "freeze" prop to be null', () => {
+ render(
+ <WrapSequenceContext>
+ <Sequence freeze={null} durationInFrames={30} />
+ </WrapSequenceContext>,
+ );
+ });
+ });
test('It should throw for invalid layout value', () => {
expectToThrow(
() =>
diff --git a/packages/docs/docs/sequence.mdx b/packages/docs/docs/sequence.mdx
index 34994af4d4..dbb4471b73 100644
--- a/packages/docs/docs/sequence.mdx
+++ b/packages/docs/docs/sequence.mdx
@@ -195,6 +195,7 @@ For how many frames the sequence should be displayed. Children are unmounted if
### `freeze?`<AvailableFrom v="4.0.476" />
Freezes the children of the sequence at the specified frame.
+Pass `null` or omit the prop to keep the sequence unfrozen.
```tsx twoslash title="MyVideo.tsx"
import {Sequence, useCurrentFrame} from 'remotion';
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 0e922ba3c2..8e7905464b 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
@@ -32,7 +32,7 @@ type ResolvedSequencePropEdit = {
key: SaveSequencePropEdit['key'];
value: unknown;
valueString: string;
- defaultValue: unknown | null | undefined;
+ defaultValue: unknown | null;
defaultValueString: string | null;
schema: SaveSequencePropEdit['schema'];
};
@@ -102,14 +102,9 @@ export const saveSequencePropsHandler: ApiHandler<
const editGroups = new Map<string, SequencePropEditGroup>();
for (const [index, edit] of edits.entries()) {
- const parsedValue =
- edit.value === undefined ? undefined : JSON.parse(edit.value);
+ const parsedValue = JSON.parse(edit.value);
const parsedDefaultValue =
- edit.defaultValue === undefined
- ? undefined
- : edit.defaultValue !== null
- ? JSON.parse(edit.defaultValue)
- : null;
+ edit.defaultValue !== null ? JSON.parse(edit.defaultValue) : null;
const {absolutePath, fileRelativeToRoot} = resolveFileInsideProject({
remotionRoot,
fileName: edit.fileName,
@@ -126,11 +121,10 @@ export const saveSequencePropsHandler: ApiHandler<
nodePath: edit.nodePath,
key: edit.key,
value: parsedValue,
- valueString:
- parsedValue === undefined ? 'undefined' : JSON.stringify(parsedValue),
+ valueString: JSON.stringify(parsedValue),
defaultValue: parsedDefaultValue,
defaultValueString:
- parsedDefaultValue !== undefined && parsedDefaultValue !== null
+ parsedDefaultValue !== null
? JSON.stringify(parsedDefaultValue)
: null,
schema: edit.schema,
diff --git a/packages/studio-server/src/test/update-sequence-props.test.ts b/packages/studio-server/src/test/update-sequence-props.test.ts
index 4a7cc2ae9e..4d4622d833 100644
--- a/packages/studio-server/src/test/update-sequence-props.test.ts
+++ b/packages/studio-server/src/test/update-sequence-props.test.ts
@@ -82,7 +82,7 @@ test('updateSequenceProps should remove attribute when value equals default', as
expect(output.split('\n')[7]).toContain('hueShift={30}');
});
-test('updateSequenceProps should remove optional attribute', async () => {
+test('updateSequenceProps should set optional attribute to null', async () => {
const input = `import {Sequence} from 'remotion';
export const Example: React.FC = () => {
@@ -97,13 +97,13 @@ export const Example: React.FC = () => {
const {output, oldValueStrings} = await updateSequenceProps({
input,
nodePath: lineColumnToNodePath(input, 5),
- updates: [{key: 'freeze', value: undefined, defaultValue: undefined}],
+ updates: [{key: 'freeze', value: null, defaultValue: null}],
schema: NoReactInternals.sequenceSchema,
prettierConfigOverride: null,
});
expect(oldValueStrings[0]).toBe('12');
- expect(output).not.toContain('freeze=');
+ expect(output).toContain('freeze={null}');
});
test('updateSequenceProps should set boolean true as shorthand', async () => {
diff --git a/packages/studio-shared/src/api-requests.ts b/packages/studio-shared/src/api-requests.ts
index db25dd7ad4..d8bb0514ce 100644
--- a/packages/studio-shared/src/api-requests.ts
+++ b/packages/studio-shared/src/api-requests.ts
@@ -299,17 +299,10 @@ export type SaveSequencePropEdit = {
fileName: string;
nodePath: SequencePropsSubscriptionKey;
key: string;
+ value: string;
+ defaultValue: string | null;
schema: SequenceSchema;
-} & (
- | {
- value: string;
- defaultValue: string | null;
- }
- | {
- value?: undefined;
- defaultValue?: undefined;
- }
-);
+};
export type SaveSequencePropsRequest = {
edits: SaveSequencePropEdit[];
diff --git a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
index 939a264e0a..f92ccdd6da 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceItem.tsx
@@ -816,7 +816,8 @@ export const TimelineSequenceItem: React.FC<{
const freezeStatus = propStatusesForOverride?.freeze;
const isFrozen =
- freezeStatus?.status === 'static' && freezeStatus.codeValue !== undefined;
+ freezeStatus?.status === 'static' &&
+ typeof freezeStatus.codeValue === 'number';
const canToggleFreeze =
previewConnected &&
@@ -853,8 +854,8 @@ export const TimelineSequenceItem: React.FC<{
fileName: validatedLocation.source,
nodePath,
fieldKey: 'freeze',
- value: remove ? undefined : freezeFrame,
- defaultValue: remove ? undefined : null,
+ value: remove ? null : freezeFrame,
+ defaultValue: null,
schema: sequence.controls.schema,
},
],
diff --git a/packages/studio/src/components/Timeline/save-sequence-prop.ts b/packages/studio/src/components/Timeline/save-sequence-prop.ts
index 4935e22916..19da94d55b 100644
--- a/packages/studio/src/components/Timeline/save-sequence-prop.ts
+++ b/packages/studio/src/components/Timeline/save-sequence-prop.ts
@@ -1,7 +1,4 @@
-import {
- optimisticUpdateForPropStatuses,
- type SaveSequencePropEdit,
-} from '@remotion/studio-shared';
+import {optimisticUpdateForPropStatuses} from '@remotion/studio-shared';
import type {
CanUpdateSequencePropsResponse,
SequencePropsSubscriptionKey,
@@ -22,7 +19,7 @@ export type SaveSequencePropChange = {
nodePath: SequencePropsSubscriptionKey;
fieldKey: string;
value: unknown;
- defaultValue: string | null | undefined;
+ defaultValue: string | null;
schema: SequenceSchema;
};
@@ -34,31 +31,6 @@ type SaveSequencePropsOptions = {
redoLabel: string;
};
-const changeToEdit = (change: SaveSequencePropChange): SaveSequencePropEdit => {
- const base = {
- fileName: change.fileName,
- nodePath: change.nodePath,
- key: change.fieldKey,
- schema: change.schema,
- };
-
- if (change.value === undefined && change.defaultValue === undefined) {
- return base;
- }
-
- if (change.defaultValue === undefined) {
- throw new Error(
- 'Expected defaultValue to be defined for sequence prop save',
- );
- }
-
- return {
- ...base,
- defaultValue: change.defaultValue,
- value: JSON.stringify(change.value),
- };
-};
-
export const saveSequenceProps = ({
changes,
setPropStatuses,
@@ -88,7 +60,16 @@ export const saveSequenceProps = ({
}),
apiCall: () =>
callApi('/api/save-sequence-props', {
- edits: [changeToEdit(change)],
+ edits: [
+ {
+ fileName: change.fileName,
+ nodePath: change.nodePath,
+ key: change.fieldKey,
+ value: JSON.stringify(change.value),
+ defaultValue: change.defaultValue,
+ schema: change.schema,
+ },
+ ],
clientId,
undoLabel,
redoLabel,
@@ -109,7 +90,16 @@ export const saveSequenceProps = ({
}
return callApi('/api/save-sequence-props', {
- edits: changes.map(changeToEdit),
+ edits: changes.map((change) => {
+ return {
+ fileName: change.fileName,
+ nodePath: change.nodePath,
+ key: change.fieldKey,
+ value: JSON.stringify(change.value),
+ defaultValue: change.defaultValue,
+ schema: change.schema,
+ };
+ }),
clientId,
undoLabel,
redoLabel,