Skip to content

🎥 Make videos programmatically with React

Remove inactive transition presentation optimization

JonnyBurgerf6daaa6da630
diff --git a/packages/transitions/src/TransitionSeries.tsx b/packages/transitions/src/TransitionSeries.tsx
index 4ab9e0d002..888794468c 100644
--- a/packages/transitions/src/TransitionSeries.tsx
+++ b/packages/transitions/src/TransitionSeries.tsx
@@ -782,25 +782,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
);
}
- // Built-in presentations can leave their effects inactive without
- // replacing the child tree and discarding premounted media.
- const renderNextPresentation =
- next &&
- (nextProgress !== null ||
- (next.props.presentation ?? slide())
- ._remotionInternalSupportsInactive);
- const renderPrevPresentation =
- prev &&
- (prevProgress !== null ||
- (prev.props.presentation ?? slide())
- ._remotionInternalSupportsInactive);
-
- if (
- next &&
- prev &&
- renderNextPresentation &&
- renderPrevPresentation
- ) {
+ if (next && prev && nextProgress !== null && prevProgress !== null) {
const nextPresentation = next.props.presentation ?? slide();
const prevPresentation = prev.props.presentation ?? slide();
@@ -820,20 +802,17 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
<UppercaseNextPresentation
passedProps={nextPresentation.props ?? {}}
presentationDirection="exiting"
- presentationProgress={nextProgress ?? 0}
- _remotionInternalIsActive={nextProgress !== null}
+ presentationProgress={nextProgress}
presentationDurationInFrames={next.props.timing.getDurationInFrames(
{fps},
)}
- onElementImage={(elementImage, draw) => {
- onPrevElementImage(elementImage, nextProgress, draw, i + 1);
+ onElementImage={() => {
+ throw new Error('Should not call when exiting');
}}
onUnmount={() => {
- onPrevElementImage(null, null, null, i + 1);
+ throw new Error('Should not call when exiting');
}}
- bothEnteringAndExiting={
- nextProgress !== null && prevProgress !== null
- }
+ bothEnteringAndExiting
>
<WrapInExitingProgressContext
presentationProgress={nextProgress}
@@ -841,21 +820,17 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
<UppercasePrevPresentation
passedProps={prevPresentation.props ?? {}}
presentationDirection="entering"
- presentationProgress={prevProgress ?? 1}
- _remotionInternalIsActive={prevProgress !== null}
+ presentationProgress={prevProgress}
presentationDurationInFrames={prev.props.timing.getDurationInFrames(
{fps},
)}
onElementImage={(elementImage, draw) => {
- if (nextProgress !== null) {
- onPrevElementImage(
- elementImage,
- nextProgress,
- draw,
- i + 1,
- );
- }
-
+ onPrevElementImage(
+ elementImage,
+ nextProgress,
+ draw,
+ i + 1,
+ );
onNextElementImage(
elementImage,
prevProgress,
@@ -867,9 +842,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
onPrevElementImage(null, null, null, i + 1);
onNextElementImage(null, null, null, i - 1);
}}
- bothEnteringAndExiting={
- nextProgress !== null && prevProgress !== null
- }
+ bothEnteringAndExiting
>
<WrapInEnteringProgressContext
presentationProgress={prevProgress}
@@ -883,7 +856,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
);
}
- if (renderPrevPresentation && prev) {
+ if (prevProgress !== null && prev) {
const prevPresentation = prev.props.presentation ?? slide();
const UppercasePrevPresentation = prevPresentation.component;
@@ -901,8 +874,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
<UppercasePrevPresentation
passedProps={prevPresentation.props ?? {}}
presentationDirection="entering"
- presentationProgress={prevProgress ?? 1}
- _remotionInternalIsActive={prevProgress !== null}
+ presentationProgress={prevProgress}
presentationDurationInFrames={prev.props.timing.getDurationInFrames(
{fps},
)}
@@ -924,7 +896,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
);
}
- if (renderNextPresentation && next) {
+ if (nextProgress !== null && next) {
const nextPresentation = next.props.presentation ?? slide();
const UppercaseNextPresentation = nextPresentation.component;
@@ -942,8 +914,7 @@ const TransitionSeriesChildren: FC<{readonly children: React.ReactNode}> = ({
<UppercaseNextPresentation
passedProps={nextPresentation.props ?? {}}
presentationDirection="exiting"
- presentationProgress={nextProgress ?? 0}
- _remotionInternalIsActive={nextProgress !== null}
+ presentationProgress={nextProgress}
presentationDurationInFrames={next.props.timing.getDurationInFrames(
{fps},
)}
diff --git a/packages/transitions/src/context.tsx b/packages/transitions/src/context.tsx
index ae041e7c16..0e143a3480 100644
--- a/packages/transitions/src/context.tsx
+++ b/packages/transitions/src/context.tsx
@@ -1,4 +1,4 @@
-import React, {useContext, useMemo} from 'react';
+import React, {useMemo} from 'react';
type EnteringState = {
enteringProgress: number;
@@ -12,17 +12,14 @@ export const EnteringContext = React.createContext<EnteringState | null>(null);
export const ExitingContext = React.createContext<ExitingState | null>(null);
export const WrapInEnteringProgressContext: React.FC<{
- readonly presentationProgress: number | null;
+ readonly presentationProgress: number;
readonly children: React.ReactNode;
}> = ({presentationProgress, children}) => {
- const inheritedValue = useContext(EnteringContext);
- const value: EnteringState | null = useMemo(() => {
- return presentationProgress === null
- ? inheritedValue
- : {
- enteringProgress: presentationProgress,
- };
- }, [inheritedValue, presentationProgress]);
+ const value: EnteringState = useMemo(() => {
+ return {
+ enteringProgress: presentationProgress,
+ };
+ }, [presentationProgress]);
return (
<EnteringContext.Provider value={value}>
@@ -32,17 +29,14 @@ export const WrapInEnteringProgressContext: React.FC<{
};
export const WrapInExitingProgressContext: React.FC<{
- readonly presentationProgress: number | null;
+ readonly presentationProgress: number;
readonly children: React.ReactNode;
}> = ({presentationProgress, children}) => {
- const inheritedValue = useContext(ExitingContext);
- const value: ExitingState | null = useMemo(() => {
- return presentationProgress === null
- ? inheritedValue
- : {
- exitingProgress: presentationProgress,
- };
- }, [inheritedValue, presentationProgress]);
+ const value: ExitingState = useMemo(() => {
+ return {
+ exitingProgress: presentationProgress,
+ };
+ }, [presentationProgress]);
return (
<ExitingContext.Provider value={value}>{children}</ExitingContext.Provider>
diff --git a/packages/transitions/src/presentations/clock-wipe.tsx b/packages/transitions/src/presentations/clock-wipe.tsx
index a569d1f537..444c74cbd3 100644
--- a/packages/transitions/src/presentations/clock-wipe.tsx
+++ b/packages/transitions/src/presentations/clock-wipe.tsx
@@ -18,43 +18,29 @@ export type ClockWipeProps = {
const ClockWipePresentation: React.FC<
TransitionPresentationComponentProps<ClockWipeProps>
-> = ({
- children,
- presentationDirection,
- presentationProgress,
- passedProps,
- _remotionInternalIsActive = true,
-}) => {
- const translatedPath = useMemo(() => {
- if (!_remotionInternalIsActive || presentationDirection === 'exiting') {
- return null;
- }
+> = ({children, presentationDirection, presentationProgress, passedProps}) => {
+ const finishedRadius =
+ Math.sqrt(passedProps.width ** 2 + passedProps.height ** 2) / 2;
- const finishedRadius =
- Math.sqrt(passedProps.width ** 2 + passedProps.height ** 2) / 2;
- const {path} = makePie({
- radius: finishedRadius,
- progress: presentationProgress,
- });
- return translatePath(
- path,
- -(finishedRadius * 2 - passedProps.width) / 2,
- -(finishedRadius * 2 - passedProps.height) / 2,
- );
- }, [
- _remotionInternalIsActive,
- presentationDirection,
- presentationProgress,
- passedProps.width,
- passedProps.height,
- ]);
+ const {path} = makePie({
+ radius: finishedRadius,
+ progress: presentationProgress,
+ });
+
+ const translatedPath = translatePath(
+ path,
+ -(finishedRadius * 2 - passedProps.width) / 2,
+ -(finishedRadius * 2 - passedProps.height) / 2,
+ );
const style: React.CSSProperties = useMemo(() => {
return {
width: '100%',
height: '100%',
clipPath:
- translatedPath === null ? undefined : `path("${translatedPath}")`,
+ presentationDirection === 'exiting'
+ ? undefined
+ : `path("${translatedPath}")`,
...(presentationDirection === 'entering'
? passedProps.innerEnterStyle
: passedProps.innerExitStyle),
@@ -77,14 +63,8 @@ const ClockWipePresentation: React.FC<
]);
return (
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? outerStyle : {display: 'contents'}}
- >
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? style : {display: 'contents'}}
- >
+ <AbsoluteFill showInTimeline={false} style={outerStyle}>
+ <AbsoluteFill showInTimeline={false} style={style}>
{children}
</AbsoluteFill>
</AbsoluteFill>
@@ -98,9 +78,5 @@ const ClockWipePresentation: React.FC<
export const clockWipe = (
props: ClockWipeProps,
): TransitionPresentation<ClockWipeProps> => {
- return {
- _remotionInternalSupportsInactive: true,
- component: ClockWipePresentation,
- props: props ?? {},
- };
+ return {component: ClockWipePresentation, props: props ?? {}};
};
diff --git a/packages/transitions/src/presentations/fade.tsx b/packages/transitions/src/presentations/fade.tsx
index e605b86858..ec04d8ce4d 100644
--- a/packages/transitions/src/presentations/fade.tsx
+++ b/packages/transitions/src/presentations/fade.tsx
@@ -13,13 +13,7 @@ export type FadeProps = {
const FadePresentation: React.FC<
TransitionPresentationComponentProps<FadeProps>
-> = ({
- children,
- presentationDirection,
- presentationProgress,
- passedProps,
- _remotionInternalIsActive = true,
-}) => {
+> = ({children, presentationDirection, presentationProgress, passedProps}) => {
const isEntering = presentationDirection === 'entering';
const style: React.CSSProperties = useMemo(() => {
return {
@@ -42,10 +36,7 @@ const FadePresentation: React.FC<
]);
return (
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? style : {display: 'contents'}}
- >
+ <AbsoluteFill showInTimeline={false} style={style}>
{children}
</AbsoluteFill>
);
@@ -57,7 +48,6 @@ const FadePresentation: React.FC<
export const fade = (props?: FadeProps): TransitionPresentation<FadeProps> => {
return {
- _remotionInternalSupportsInactive: true,
component: FadePresentation,
props: props ?? {},
};
diff --git a/packages/transitions/src/presentations/flip.tsx b/packages/transitions/src/presentations/flip.tsx
index 14170f6bd4..b975048f52 100644
--- a/packages/transitions/src/presentations/flip.tsx
+++ b/packages/transitions/src/presentations/flip.tsx
@@ -24,7 +24,6 @@ const Flip: React.FC<TransitionPresentationComponentProps<FlipProps>> = ({
children,
presentationDirection,
presentationProgress,
- _remotionInternalIsActive = true,
passedProps: {
direction = 'from-left',
perspective = 1000,
@@ -80,14 +79,8 @@ const Flip: React.FC<TransitionPresentationComponentProps<FlipProps>> = ({
}, [outerEnterStyle, outerExitStyle, perspective, presentationDirection]);
return (
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? outer : {display: 'contents'}}
- >
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? style : {display: 'contents'}}
- >
+ <AbsoluteFill showInTimeline={false} style={outer}>
+ <AbsoluteFill showInTimeline={false} style={style}>
{children}
</AbsoluteFill>
</AbsoluteFill>
@@ -99,9 +92,5 @@ const Flip: React.FC<TransitionPresentationComponentProps<FlipProps>> = ({
*/
export const flip = (props?: FlipProps): TransitionPresentation<FlipProps> => {
- return {
- _remotionInternalSupportsInactive: true,
- component: Flip,
- props: props ?? {},
- };
+ return {component: Flip, props: props ?? {}};
};
diff --git a/packages/transitions/src/presentations/iris.tsx b/packages/transitions/src/presentations/iris.tsx
index cfb3c5071d..455b01ef6b 100644
--- a/packages/transitions/src/presentations/iris.tsx
+++ b/packages/transitions/src/presentations/iris.tsx
@@ -18,13 +18,7 @@ export type IrisProps = {
const IrisPresentation: React.FC<
TransitionPresentationComponentProps<IrisProps>
-> = ({
- children,
- presentationDirection,
- presentationProgress,
- passedProps,
- _remotionInternalIsActive = true,
-}) => {
+> = ({children, presentationDirection, presentationProgress, passedProps}) => {
const maxRadius =
Math.sqrt(passedProps.width ** 2 + passedProps.height ** 2) / 2;
@@ -74,14 +68,8 @@ const IrisPresentation: React.FC<
]);
return (
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? outerStyle : {display: 'contents'}}
- >
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? style : {display: 'contents'}}
- >
+ <AbsoluteFill showInTimeline={false} style={outerStyle}>
+ <AbsoluteFill showInTimeline={false} style={style}>
{children}
</AbsoluteFill>
</AbsoluteFill>
@@ -93,9 +81,5 @@ const IrisPresentation: React.FC<
* @see [Documentation](https://www.remotion.dev/docs/transitions/presentations/iris)
*/
export const iris = (props: IrisProps): TransitionPresentation<IrisProps> => {
- return {
- _remotionInternalSupportsInactive: true,
- component: IrisPresentation,
- props: props ?? {},
- };
+ return {component: IrisPresentation, props: props ?? {}};
};
diff --git a/packages/transitions/src/presentations/none.tsx b/packages/transitions/src/presentations/none.tsx
index 15862c3dfa..d2cb21406a 100644
--- a/packages/transitions/src/presentations/none.tsx
+++ b/packages/transitions/src/presentations/none.tsx
@@ -12,12 +12,7 @@ export type NoneProps = {
const NonePresentation: React.FC<
TransitionPresentationComponentProps<NoneProps>
-> = ({
- children,
- presentationDirection,
- passedProps,
- _remotionInternalIsActive = true,
-}) => {
+> = ({children, presentationDirection, passedProps}) => {
const style: React.CSSProperties = useMemo(() => {
return {
...(presentationDirection === 'entering'
@@ -27,10 +22,7 @@ const NonePresentation: React.FC<
}, [passedProps.enterStyle, passedProps.exitStyle, presentationDirection]);
return (
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? style : {display: 'contents'}}
- >
+ <AbsoluteFill showInTimeline={false} style={style}>
{children}
</AbsoluteFill>
);
@@ -42,7 +34,6 @@ const NonePresentation: React.FC<
*/
export const none = (props?: NoneProps): TransitionPresentation<NoneProps> => {
return {
- _remotionInternalSupportsInactive: true,
component: NonePresentation,
props: props ?? {},
};
diff --git a/packages/transitions/src/presentations/push-cut.tsx b/packages/transitions/src/presentations/push-cut.tsx
index 0406b357ad..14157dce43 100644
--- a/packages/transitions/src/presentations/push-cut.tsx
+++ b/packages/transitions/src/presentations/push-cut.tsx
@@ -85,7 +85,6 @@ const PushCutPresentation: React.FC<
presentationDurationInFrames,
presentationProgress,
passedProps,
- _remotionInternalIsActive = true,
}) => {
const {
cutProgress = 5 / 11,
@@ -171,17 +170,11 @@ const PushCutPresentation: React.FC<
}, [innerEnterStyle, innerExitStyle, isEntering, scale, transformOrigin]);
return (
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? outerStyle : {display: 'contents'}}
- >
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? innerStyle : {display: 'contents'}}
- >
+ <AbsoluteFill showInTimeline={false} style={outerStyle}>
+ <AbsoluteFill showInTimeline={false} style={innerStyle}>
{children}
</AbsoluteFill>
- {_remotionInternalIsActive && flashOpacity > 0 ? (
+ {flashOpacity > 0 ? (
<AbsoluteFill
showInTimeline={false}
style={{
@@ -207,7 +200,6 @@ export const pushCut = (
validateProps(passedProps);
return {
- _remotionInternalSupportsInactive: true,
component: PushCutPresentation,
props: passedProps,
};
diff --git a/packages/transitions/src/presentations/slide.tsx b/packages/transitions/src/presentations/slide.tsx
index 61375f2d78..846d9b5eeb 100644
--- a/packages/transitions/src/presentations/slide.tsx
+++ b/packages/transitions/src/presentations/slide.tsx
@@ -25,7 +25,6 @@ const SlidePresentation: React.FC<
children,
presentationProgress,
presentationDirection,
- _remotionInternalIsActive = true,
passedProps: {direction = 'from-left', enterStyle, exitStyle},
}) => {
const directionStyle = useMemo((): React.CSSProperties => {
@@ -97,10 +96,7 @@ const SlidePresentation: React.FC<
}, [directionStyle, enterStyle, exitStyle, presentationDirection]);
return (
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? style : {display: 'contents'}}
- >
+ <AbsoluteFill showInTimeline={false} style={style}>
{children}
</AbsoluteFill>
);
@@ -114,7 +110,6 @@ export const slide = (
props?: SlideProps,
): TransitionPresentation<SlideProps> => {
return {
- _remotionInternalSupportsInactive: true,
component: SlidePresentation,
props: props ?? {},
};
diff --git a/packages/transitions/src/presentations/wipe.tsx b/packages/transitions/src/presentations/wipe.tsx
index 0b102f8b3f..c43c2cb815 100644
--- a/packages/transitions/src/presentations/wipe.tsx
+++ b/packages/transitions/src/presentations/wipe.tsx
@@ -77,7 +77,6 @@ const WipePresentation: React.FC<
children,
presentationProgress,
presentationDirection,
- _remotionInternalIsActive = true,
passedProps: {
direction = 'from-left',
innerEnterStyle,
@@ -116,14 +115,8 @@ const WipePresentation: React.FC<
}, [outerEnterStyle, outerExitStyle, presentationDirection]);
return (
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? outerStyle : {display: 'contents'}}
- >
- <AbsoluteFill
- showInTimeline={false}
- style={_remotionInternalIsActive ? style : {display: 'contents'}}
- >
+ <AbsoluteFill showInTimeline={false} style={outerStyle}>
+ <AbsoluteFill showInTimeline={false} style={style}>
{children}
</AbsoluteFill>
</AbsoluteFill>
@@ -136,7 +129,6 @@ const WipePresentation: React.FC<
*/
export const wipe = (props?: WipeProps): TransitionPresentation<WipeProps> => {
return {
- _remotionInternalSupportsInactive: true,
component: WipePresentation,
props: props ?? {},
};
diff --git a/packages/transitions/src/types.ts b/packages/transitions/src/types.ts
index 54930ec7a6..1a9a23aaea 100644
--- a/packages/transitions/src/types.ts
+++ b/packages/transitions/src/types.ts
@@ -26,8 +26,6 @@ export type TransitionPresentation<
TransitionPresentationComponentProps<PresentationProps>
>;
props: PresentationProps;
- /** @internal Keeps the presentation mounted when its visual effect is inactive. */
- readonly _remotionInternalSupportsInactive?: boolean;
};
export type TransitionPresentationComponentProps<
@@ -41,8 +39,6 @@ export type TransitionPresentationComponentProps<
onElementImage: (elementImage: OffscreenCanvas, draw: DrawFunction) => void;
onUnmount: () => void;
bothEnteringAndExiting: boolean;
- /** @internal Defaults to true for presentations rendered directly. */
- readonly _remotionInternalIsActive?: boolean;
};
export type TransitionSeriesOverlayProps = Pick<