Skip to content

🎥 Make videos programmatically with React

`remotion`: Skip unchanged timeline sequence updates

Jonny Burger2cbcb43950f5
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index 143aa9064a..8f7a0e39d3 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -526,6 +526,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
stackRef.current = controls
? (getStackForControls(controls) ?? stack ?? null)
: (stack ?? null);
+ const getStack = useCallback(() => stackRef.current, []);
const registeredFrozenFrame = typeof freeze === 'number' ? freeze : null;
const currentFrame =
registeredFrozenFrame ??
@@ -648,7 +649,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
showInTimeline,
timelineOrder: null,
src: isMedia.src,
- getStack: () => stackRef.current,
+ getStack,
getCurrentFrame,
refForOutline: refForOutline ?? null,
isInsideSeries,
@@ -678,7 +679,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
showInTimeline,
timelineOrder: null,
src: isMedia.data.src,
- getStack: () => stackRef.current,
+ getStack,
getCurrentFrame,
startMediaFrom: startMediaFrom ?? isMedia.data.startMediaFrom,
mediaFrameAtSequenceZero,
@@ -708,7 +709,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
showInTimeline,
timelineOrder: null,
loopDisplay: resolvedLoopDisplay,
- getStack: () => stackRef.current,
+ getStack,
getCurrentFrame,
premountDisplay: premountDisplay ?? null,
postmountDisplay: postmountDisplay ?? null,
@@ -723,6 +724,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
}, [
id,
getCurrentFrame,
+ getStack,
timelineClipName,
playbackRate,
parentSequence?.id,
diff --git a/packages/core/src/SequenceManager.tsx b/packages/core/src/SequenceManager.tsx
index 87a90b802e..2871d372ed 100644
--- a/packages/core/src/SequenceManager.tsx
+++ b/packages/core/src/SequenceManager.tsx
@@ -839,11 +839,26 @@ export const SequenceManagerProvider: React.FC<{
return seqs;
}
- const next = [...seqs];
- next[index] = {
+ const nextSequence = {
...seq,
timelineOrder: committedOrderRef.current?.get(seq.id) ?? null,
};
+ const previousSequence = seqs[index];
+ // A new registration getter does not necessarily change the metadata.
+ if (
+ Object.keys(previousSequence).length ===
+ Object.keys(nextSequence).length &&
+ Object.entries(nextSequence).every(
+ ([key, value]) =>
+ Object.prototype.hasOwnProperty.call(previousSequence, key) &&
+ Object.is(previousSequence[key as keyof TSequence], value),
+ )
+ ) {
+ return seqs;
+ }
+
+ const next = [...seqs];
+ next[index] = nextSequence;
return next;
});
}, []);
diff --git a/packages/core/src/use-media-in-timeline.ts b/packages/core/src/use-media-in-timeline.ts
index 744f3e9339..254d0409ab 100644
--- a/packages/core/src/use-media-in-timeline.ts
+++ b/packages/core/src/use-media-in-timeline.ts
@@ -20,6 +20,8 @@ import {useVideoConfig} from './use-video-config.js';
import type {VolumeProp} from './volume-prop.js';
import {evaluateVolume} from './volume-prop.js';
+const EMPTY_EFFECTS = [] as const;
+
export const useBasicMediaInTimeline = ({
volume,
mediaVolume,
@@ -297,7 +299,7 @@ export const useMediaInTimeline = ({
premountDisplay,
postmountDisplay,
controls: null,
- effects: [],
+ effects: EMPTY_EFFECTS,
refForOutline: automaticOutlineRef,
isInsideSeries: false,
frozenFrame: null,
@@ -306,7 +308,7 @@ export const useMediaInTimeline = ({
}, [
duration,
id,
- parentSequence,
+ parentSequence?.id,
src,
volumes,
doesVolumeChange,