Skip to content

🎥 Make videos programmatically with React

`@remotion/studio`: Preserve keyframe clocks when moving sequences (#10422)

Jonny Burger5bd5b2e7e30e
diff --git a/packages/core/src/effects/use-memoized-effects.ts b/packages/core/src/effects/use-memoized-effects.ts
index 1f8ae87ec0..96c8cffeba 100644
--- a/packages/core/src/effects/use-memoized-effects.ts
+++ b/packages/core/src/effects/use-memoized-effects.ts
@@ -1,6 +1,5 @@
import {useContext, useRef} from 'react';
import {resolveDragOverrideValue} from '../get-effective-visual-mode-value.js';
-import {interpolateKeyframedStatus} from '../interpolate-keyframed-status.js';
import {OverrideIdsToNodePathsGettersContext} from '../sequence-node-path.js';
import type {
CannotUpdateEffectReason,
@@ -71,7 +70,6 @@ const mergeOverrides = ({
const resolvePropStatusOverrides = (
propStatus: Record<string, CanUpdateSequencePropStatus> | undefined,
- frame: number,
): Record<string, unknown> | null => {
if (!propStatus) {
return null;
@@ -86,17 +84,8 @@ const resolvePropStatusOverrides = (
continue;
}
- if (status.status === 'keyframed') {
- const value = interpolateKeyframedStatus({
- forceSpringAllowTail: null,
- frame,
- status,
- });
- if (value !== null) {
- out[key] = value;
- hasAny = true;
- }
- }
+ // Keyframed params retain the value evaluated by their JSX expression.
+ // Explicit drag overrides are resolved separately in mergeOverrides().
}
return hasAny ? out : null;
@@ -224,7 +213,7 @@ export const useMemoizedEffects = ({
});
const propStatusOverrides =
effectStatus.type === 'can-update-effect'
- ? resolvePropStatusOverrides(effectStatus.props, frame)
+ ? resolvePropStatusOverrides(effectStatus.props)
: null;
const dragOverridesMap = getEffectDragOverrides(nodePath, index);
const dragOverrides =
diff --git a/packages/core/src/test/sequence-register-once.test.tsx b/packages/core/src/test/sequence-register-once.test.tsx
index 6cb6641332..5f8e7d0c08 100644
--- a/packages/core/src/test/sequence-register-once.test.tsx
+++ b/packages/core/src/test/sequence-register-once.test.tsx
@@ -18,6 +18,7 @@ import type {
import {Img, imgSchema} from '../Img.js';
import {Interactive} from '../Interactive.js';
import {Internals} from '../internals.js';
+import {interpolate} from '../interpolate.js';
import {Loading} from '../loading-indicator.js';
import type {OverrideIdToNodePaths} from '../sequence-node-path.js';
import {OverrideIdsToNodePathsGettersContext} from '../sequence-node-path.js';
@@ -582,6 +583,73 @@ test('read-only Studio registers visual controls without applying overrides', ()
expect(sequence?.duration).toBe(10);
});
+test('Visual Mode preserves the frame scope of keyframed JSX props', () => {
+ const nodePath = {
+ absolutePath: '/src/Composition.tsx',
+ nodePath: ['body', 0],
+ sequenceKeys: [],
+ effectKeys: [],
+ videoConfigValues: null,
+ };
+ const subscriptionKey = Internals.makeSequencePropsSubscriptionKey(nodePath);
+ const Repro: React.FC = () => {
+ const frame = useCurrentFrame();
+
+ return (
+ <Sequence from={-10} durationInFrames={30}>
+ <AbsoluteFill
+ data-testid="fill"
+ style={{
+ translate: interpolate(frame, [10, 20], ['0px 0px', '500px 0px'], {
+ extrapolateLeft: 'clamp',
+ extrapolateRight: 'clamp',
+ }),
+ }}
+ />
+ </Sequence>
+ );
+ };
+
+ const rendered = render(
+ <SequenceTestWrapperWithVisualModeOverrides
+ compositionDurationInFrames={30}
+ currentFrame={5}
+ onRegisterSequence={() => undefined}
+ visualModeOverrides={{
+ overrideIdToNodePathMappings: new Proxy(
+ {},
+ {get: () => nodePath},
+ ) as OverrideIdToNodePaths,
+ propStatuses: {
+ [subscriptionKey]: {
+ canUpdate: true,
+ props: {
+ 'style.translate': {
+ status: 'keyframed',
+ interpolationFunction: 'interpolate',
+ keyframes: [
+ {frame: 10, value: '0px 0px'},
+ {frame: 20, value: '500px 0px'},
+ ],
+ easing: [{type: 'linear'}],
+ clamping: {left: 'clamp', right: 'clamp'},
+ posterize: undefined,
+ output: undefined,
+ },
+ },
+ effects: [],
+ },
+ },
+ dragOverrides: {},
+ }}
+ >
+ <Repro />
+ </SequenceTestWrapperWithVisualModeOverrides>,
+ );
+
+ expect(rendered.getByTestId('fill').style.translate).toBe('0px 0px');
+});
+
test('Series.Sequence timing overrides cascade to later sequences', async () => {
const registeredSequences: TSequence[] = [];
const onRegisterSequence = (sequence: TSequence) => {
diff --git a/packages/core/src/use-schema.ts b/packages/core/src/use-schema.ts
index 93f033b05b..8fe0f364bf 100644
--- a/packages/core/src/use-schema.ts
+++ b/packages/core/src/use-schema.ts
@@ -8,7 +8,6 @@ import type {
InteractivitySchema,
InteractivitySchemaField,
} from './interactivity-schema.js';
-import {interpolateKeyframedStatus} from './interpolate-keyframed-status.js';
import type {ExtrapolateType, InterpolateOutputOption} from './interpolate.js';
import type {
CanUpdateSequencePropsResponse,
@@ -311,14 +310,9 @@ export const computeEffectiveSchemaValuesDotNotation = ({
});
if (dragOverride.type === 'resolved') {
value = dragOverride.value;
- } else if (frame !== null) {
- const interpolated = interpolateKeyframedStatus({
- forceSpringAllowTail: null,
- frame,
- status,
- });
- value = interpolated ?? currentValue[key];
} else {
+ // This value was evaluated by the original JSX expression, so it
+ // preserves the frame scope in which useCurrentFrame() was called.
value = currentValue[key];
}
}
diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.ts
index eef0c94737..1083c28266 100644
--- a/packages/studio/src/test/timeline-selection.test.ts
+++ b/packages/studio/src/test/timeline-selection.test.ts
@@ -2581,6 +2581,67 @@ test('Timeline from drag moves all owned sequence keyframes by the same delta',
]);
});
+test('Timeline from drag leaves descendant keyframes on their JSX clock', () => {
+ const parentNodePathInfo = makeNodePathInfo(['body', 0], []);
+ const parentNodePath = parentNodePathInfo.sequenceSubscriptionKey;
+ const descendantNodePath = makeNodePathInfo(
+ ['body', 0, 'children', 0],
+ [],
+ ).sequenceSubscriptionKey;
+ const propStatuses = makeFromPropStatuses([parentNodePath]);
+ propStatuses[Internals.makeSequencePropsSubscriptionKey(descendantNodePath)] =
+ {
+ canUpdate: true,
+ props: {
+ color: {
+ status: 'keyframed',
+ interpolationFunction: 'interpolateColors',
+ keyframes: [
+ {frame: 0, value: '#0b84f3'},
+ {frame: 100, value: '#f43b00'},
+ ],
+ easing: [{type: 'linear'}],
+ clamping: {left: 'extend', right: 'extend'},
+ posterize: undefined,
+ output: undefined,
+ },
+ },
+ effects: [],
+ };
+
+ const targets = getTimelineSequenceFromDragTargets({
+ draggedNodePathInfo: parentNodePathInfo,
+ selectedItems: [{type: 'sequence', nodePathInfo: parentNodePathInfo}],
+ sequences: [
+ makeTimelineSequence({
+ schema: {},
+ id: 'parent',
+ overrideId: 'parent-override',
+ }),
+ makeTimelineSequence({
+ schema: {
+ color: {type: 'color', default: '#000000'},
+ },
+ id: 'descendant',
+ overrideId: 'descendant-override',
+ parentId: 'parent',
+ }),
+ ],
+ overrideIdsToNodePaths: {
+ 'parent-override': parentNodePath,
+ 'descendant-override': descendantNodePath,
+ },
+ propStatuses,
+ });
+
+ expect(
+ getTimelineSequenceFromDragKeyframeMoves({
+ targets: targets ?? [],
+ deltaFrames: -34,
+ }),
+ ).toEqual({effectKeyframes: [], sequenceKeyframes: []});
+});
+
test('Timeline from drag moves owned effect keyframes by the same delta', () => {
const schema = {} satisfies InteractivitySchema;
const effectSchema = {