Skip to content

🎥 Make videos programmatically with React

@remotion/studio: Revert keyframe clock changes (#10470)

Jonny Burger2e55936cf84a
diff --git a/packages/core/src/effects/use-memoized-effects.ts b/packages/core/src/effects/use-memoized-effects.ts
index 96c8cffeba..1f8ae87ec0 100644
--- a/packages/core/src/effects/use-memoized-effects.ts
+++ b/packages/core/src/effects/use-memoized-effects.ts
@@ -1,5 +1,6 @@
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,
@@ -70,6 +71,7 @@ const mergeOverrides = ({
const resolvePropStatusOverrides = (
propStatus: Record<string, CanUpdateSequencePropStatus> | undefined,
+ frame: number,
): Record<string, unknown> | null => {
if (!propStatus) {
return null;
@@ -84,8 +86,17 @@ const resolvePropStatusOverrides = (
continue;
}
- // Keyframed params retain the value evaluated by their JSX expression.
- // Explicit drag overrides are resolved separately in mergeOverrides().
+ if (status.status === 'keyframed') {
+ const value = interpolateKeyframedStatus({
+ forceSpringAllowTail: null,
+ frame,
+ status,
+ });
+ if (value !== null) {
+ out[key] = value;
+ hasAny = true;
+ }
+ }
}
return hasAny ? out : null;
@@ -213,7 +224,7 @@ export const useMemoizedEffects = ({
});
const propStatusOverrides =
effectStatus.type === 'can-update-effect'
- ? resolvePropStatusOverrides(effectStatus.props)
+ ? resolvePropStatusOverrides(effectStatus.props, frame)
: 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 5f8e7d0c08..6cb6641332 100644
--- a/packages/core/src/test/sequence-register-once.test.tsx
+++ b/packages/core/src/test/sequence-register-once.test.tsx
@@ -18,7 +18,6 @@ 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';
@@ -583,73 +582,6 @@ 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 8fe0f364bf..93f033b05b 100644
--- a/packages/core/src/use-schema.ts
+++ b/packages/core/src/use-schema.ts
@@ -8,6 +8,7 @@ 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,
@@ -310,9 +311,14 @@ 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/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
index f67c3d8d92..797229db8a 100644
--- a/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
+++ b/packages/studio/src/components/Timeline/TimelineSequenceRightEdgeDragHandle.tsx
@@ -89,9 +89,7 @@ export type TimelineSequenceFromDragTarget = {
};
type TimelineSequenceKeyframeDragTarget = {
- readonly fileName: string;
readonly fieldKey: string;
- readonly nodePath: SequencePropsSubscriptionKey;
readonly schema: InteractivitySchema;
readonly status: CanUpdateSequencePropStatusKeyframed;
};
@@ -125,15 +123,7 @@ const getKeyframedSequenceDragTargets = ({
? []
: Object.entries(status.props).flatMap(([fieldKey, propStatus]) =>
propStatus.status === 'keyframed'
- ? [
- {
- fileName: nodePath.absolutePath,
- fieldKey,
- nodePath,
- schema: sequenceSchema,
- status: propStatus,
- },
- ]
+ ? [{fieldKey, schema: sequenceSchema, status: propStatus}]
: [],
);
@@ -153,9 +143,7 @@ const getKeyframedSequenceDragTargets = ({
? [
{
effectIndex: effectStatus.effectIndex,
- fileName: nodePath.absolutePath,
fieldKey,
- nodePath,
schema: effectSchema,
status: propStatus,
},
@@ -597,8 +585,8 @@ export const getTimelineSequenceFromDragKeyframeMoves = ({
sequenceKeyframes: targets.flatMap((target) =>
target.sequenceKeyframes.flatMap((keyframeTarget) =>
keyframeTarget.status.keyframes.map((keyframe) => ({
- fileName: keyframeTarget.fileName,
- nodePath: keyframeTarget.nodePath,
+ fileName: target.fileName,
+ nodePath: target.nodePath,
fieldKey: keyframeTarget.fieldKey,
fromFrame: keyframe.frame,
toFrame: keyframe.frame + deltaFrames,
@@ -609,8 +597,8 @@ export const getTimelineSequenceFromDragKeyframeMoves = ({
effectKeyframes: targets.flatMap((target) =>
target.effectKeyframes.flatMap((keyframeTarget) =>
keyframeTarget.status.keyframes.map((keyframe) => ({
- fileName: keyframeTarget.fileName,
- nodePath: keyframeTarget.nodePath,
+ fileName: target.fileName,
+ nodePath: target.nodePath,
effectIndex: keyframeTarget.effectIndex,
fieldKey: keyframeTarget.fieldKey,
fromFrame: keyframe.frame,
@@ -869,7 +857,6 @@ export const getTimelineSequenceFromDragTargets = ({
: [draggedNodePathInfo];
const tracks = calculateTimeline({sequences, overrideIdsToNodePaths});
const targets = new Map<string, TimelineSequenceFromDragTarget>();
- const includedKeyframeNodePaths = new Set<string>();
for (const nodePathInfo of targetNodePathInfos) {
const track = findSequenceTrack({tracks, nodePathInfo});
@@ -892,51 +879,12 @@ export const getTimelineSequenceFromDragTargets = ({
const key = stringifySequenceSubscriptionKey(nodePath);
if (!targets.has(key)) {
- const descendants = sequences.filter((candidate) => {
- let parentId: string | null = candidate.id;
- while (parentId !== null) {
- if (parentId === originalSequence.id) {
- return true;
- }
-
- parentId =
- sequences.find((sequence) => sequence.id === parentId)?.parent ??
- null;
- }
-
- return false;
- });
- const descendantKeyframes = descendants.flatMap((sequence) => {
- const overrideId = sequence.controls?.overrideId;
- const descendantNodePath = overrideId
- ? overrideIdsToNodePaths[overrideId]
- : undefined;
- if (descendantNodePath === undefined) {
- return [];
- }
-
- const descendantNodePathKey =
- stringifySequenceSubscriptionKey(descendantNodePath);
- if (includedKeyframeNodePaths.has(descendantNodePathKey)) {
- return [];
- }
-
- includedKeyframeNodePaths.add(descendantNodePathKey);
-
- return [
- getKeyframedSequenceDragTargets({
- nodePath: descendantNodePath,
- sequence,
- propStatuses,
- }),
- ];
- });
- const effectKeyframes = descendantKeyframes.flatMap(
- (descendant) => descendant.effectKeyframes,
- );
- const sequenceKeyframes = descendantKeyframes.flatMap(
- (descendant) => descendant.sequenceKeyframes,
- );
+ const {effectKeyframes, sequenceKeyframes} =
+ getKeyframedSequenceDragTargets({
+ nodePath,
+ sequence: originalSequence,
+ propStatuses,
+ });
targets.set(key, {
canSnapToTimelineStart: originalSequence.parent === null,
effectKeyframes,
@@ -989,26 +937,11 @@ const clearFromDragOverrides = ({
}) => {
for (const target of targets) {
clearDragOverrides(target.nodePath);
- for (const keyframeTarget of target.sequenceKeyframes) {
- clearDragOverrides(keyframeTarget.nodePath);
- }
-
const effectIndexes = new Set(
- target.effectKeyframes.map(
- (keyframe) =>
- `${stringifySequenceSubscriptionKey(keyframe.nodePath)}:${keyframe.effectIndex}`,
- ),
+ target.effectKeyframes.map((keyframe) => keyframe.effectIndex),
);
- for (const keyframeTarget of target.effectKeyframes) {
- const key = `${stringifySequenceSubscriptionKey(keyframeTarget.nodePath)}:${keyframeTarget.effectIndex}`;
- if (!effectIndexes.delete(key)) {
- continue;
- }
-
- clearEffectDragOverrides(
- keyframeTarget.nodePath,
- keyframeTarget.effectIndex,
- );
+ for (const effectIndex of effectIndexes) {
+ clearEffectDragOverrides(target.nodePath, effectIndex);
}
}
};
@@ -1517,7 +1450,7 @@ export const useTimelineSequenceFromDrag = ({
);
for (const keyframeTarget of target.sequenceKeyframes) {
latestRef.current.setDragOverrides(
- keyframeTarget.nodePath,
+ target.nodePath,
keyframeTarget.fieldKey,
{
type: 'keyframed',
@@ -1531,7 +1464,7 @@ export const useTimelineSequenceFromDrag = ({
for (const keyframeTarget of target.effectKeyframes) {
latestRef.current.setEffectDragOverrides(
- keyframeTarget.nodePath,
+ target.nodePath,
keyframeTarget.effectIndex,
keyframeTarget.fieldKey,
{
diff --git a/packages/studio/src/test/timeline-selection.test.ts b/packages/studio/src/test/timeline-selection.test.ts
index 08c970f725..eef0c94737 100644
--- a/packages/studio/src/test/timeline-selection.test.ts
+++ b/packages/studio/src/test/timeline-selection.test.ts
@@ -2581,87 +2581,6 @@ test('Timeline from drag moves all owned sequence keyframes by the same delta',
]);
});
-test('Timeline from drag moves all descendant keyframes', () => {
- 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: [
- {
- fileName: '/project/src/Comp.tsx',
- fieldKey: 'color',
- fromFrame: 0,
- nodePath: descendantNodePath,
- schema: {color: {type: 'color', default: '#000000'}},
- toFrame: -34,
- },
- {
- fileName: '/project/src/Comp.tsx',
- fieldKey: 'color',
- fromFrame: 100,
- nodePath: descendantNodePath,
- schema: {color: {type: 'color', default: '#000000'}},
- toFrame: 66,
- },
- ],
- });
-});
-
test('Timeline from drag moves owned effect keyframes by the same delta', () => {
const schema = {} satisfies InteractivitySchema;
const effectSchema = {