Skip to content

🎥 Make videos programmatically with React

`@remotion/transitions`: Show `TransitionSeries.Overlay` in JSX order in Studio

Jonny Burgerd1256cb83d7b
diff --git a/packages/canvas/src/get-timeline-sequence-sort-key.ts b/packages/canvas/src/get-timeline-sequence-sort-key.ts
index 94c9b31da1..57e4b85080 100644
--- a/packages/canvas/src/get-timeline-sequence-sort-key.ts
+++ b/packages/canvas/src/get-timeline-sequence-sort-key.ts
@@ -43,7 +43,11 @@ export const getTimelineSequenceSortKey = (
tracks: TimelineTrackData[],
sequenceRanks: Map<string, number>,
): string => {
- const rank = sequenceRanks.get(track.sequence.id) ?? 0;
+ // Keep source order in the timeline even when a sibling paints later.
+ const rank =
+ track.sequence.timelineOrderWithinParent ??
+ sequenceRanks.get(track.sequence.id) ??
+ 0;
const id = String(rank).padStart(6, '0');
if (!track.sequence.parent) {
return id;
diff --git a/packages/core/src/CompositionManager.tsx b/packages/core/src/CompositionManager.tsx
index ac7361ddf7..f872d9f42e 100644
--- a/packages/core/src/CompositionManager.tsx
+++ b/packages/core/src/CompositionManager.tsx
@@ -134,6 +134,8 @@ export type TSequence = {
parent: string | null;
showInTimeline: boolean;
timelineOrder: number | null;
+ /** Source order among siblings when paint order must differ. */
+ timelineOrderWithinParent?: number | null;
loopDisplay: LoopDisplay | undefined;
getStack: () => string | null;
premountDisplay: number | null;
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsx
index f765b03dfc..eb57c1c1ec 100644
--- a/packages/core/src/Sequence.tsx
+++ b/packages/core/src/Sequence.tsx
@@ -115,6 +115,10 @@ export type SequencePropsWithoutDuration = {
* @deprecated For internal use only.
*/
readonly _remotionInternalSingleChildComponent?: unknown;
+ /**
+ * @deprecated For internal use only.
+ */
+ readonly _remotionInternalTimelineOrderWithinParent?: number | null;
/**
* @deprecated For internal use only.
*/
@@ -169,6 +173,8 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
_remotionInternalStack: stack,
_remotionInternalDocumentationLink: documentationLink,
_remotionInternalSingleChildComponent: singleChildComponent,
+ _remotionInternalTimelineOrderWithinParent:
+ timelineOrderWithinParent = null,
_remotionInternalPremountDisplay: premountDisplay,
_remotionInternalPostmountDisplay: postmountDisplay,
_remotionInternalIsMedia: isMedia,
@@ -616,6 +622,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
premountDisplay: premountDisplay ?? null,
showInTimeline,
timelineOrder: null,
+ timelineOrderWithinParent,
src: isMedia.src,
getStack: () => stackRef.current,
refForOutline: refForOutline ?? null,
@@ -645,6 +652,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
premountDisplay: premountDisplay ?? null,
showInTimeline,
timelineOrder: null,
+ timelineOrderWithinParent,
src: isMedia.data.src,
getStack: () => stackRef.current,
startMediaFrom: startMediaFrom ?? isMedia.data.startMediaFrom,
@@ -671,6 +679,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
type: 'sequence',
showInTimeline,
timelineOrder: null,
+ timelineOrderWithinParent,
loopDisplay: resolvedLoopDisplay,
getStack: () => stackRef.current,
premountDisplay: premountDisplay ?? null,
@@ -707,6 +716,7 @@ const RegularSequenceRefForwardingFunction: React.ForwardRefRenderFunction<
mediaFrameAtSequenceZero,
frozenMediaFrame,
singleChildComponent,
+ timelineOrderWithinParent,
]);
useSequenceRegistration({
getSequence:
diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsx
index e7c6bbad9f..5af0f3adcd 100644
--- a/packages/transitions/src/TransitionSeries.tsx
+++ b/packages/transitions/src/TransitionSeries.tsx
@@ -344,6 +344,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
from={Math.round(info.overlayFrom)}
durationInFrames={info.durationInFrames}
name="<TS.Overlay>"
+ _remotionInternalTimelineOrderWithinParent={info.index}
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/transitions/transitionseries"
controls={info.controls ?? undefined}
layout="absolute-fill"
@@ -537,6 +538,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
from={transitionFrom}
durationInFrames={transitionDuration}
name="<TS.Transition>"
+ _remotionInternalTimelineOrderWithinParent={i}
_remotionInternalDocumentationLink="https://www.remotion.dev/docs/transitions/transitionseries"
controls={transitionProps.controls ?? undefined}
layout="none"
@@ -596,6 +598,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
} = resolvedProps as InternalSeriesSequenceProps & {from: never};
const propsForSequence = {
...passedProps,
+ _remotionInternalTimelineOrderWithinParent: i,
_remotionInternalSingleChildComponent:
Internals.getSingleChildComponent(sequenceChildren),
};