🎥 Make videos programmatically with React
`remotion`: Automatically premount Sequences behind v5 flag
Jonny Burgerdb531f9ce38b
diff --git a/packages/core/src/Sequence.tsx b/packages/core/src/Sequence.tsxindex 5c4d9442ff..5b6243ea35 100644--- a/packages/core/src/Sequence.tsx+++ b/packages/core/src/Sequence.tsx@@ -22,6 +22,7 @@ import {useVideoConfig} from './use-video-config.js';import {Freeze} from './freeze.js';import {useCurrentFrame} from './use-current-frame';import {useRemotionEnvironment} from './use-remotion-environment.js';+import {ENABLE_V5_BREAKING_CHANGES} from './v5-flag.js';export type AbsoluteFillLayout = {layout?: 'absolute-fill';@@ -311,17 +312,24 @@ const PremountedPostmountedSequenceRefForwardingFunction: React.ForwardRefRender);}+ const {fps} = useVideoConfig();+const {style: passedStyle,from = 0,durationInFrames = Infinity,- premountFor = 0,- postmountFor = 0,+ premountFor: premountForProp,+ postmountFor: postmountForProp,styleWhilePremounted,styleWhilePostmounted,...otherProps} = props;+ const premountFor = ENABLE_V5_BREAKING_CHANGES+ ? (premountForProp ?? (postmountForProp === undefined ? fps : 0))+ : (premountForProp ?? 0);+ const postmountFor = postmountForProp ?? 0;+const endThreshold = Math.ceil(from + durationInFrames - 1);const premountingActive = frame < from && frame >= from - premountFor;const postmountingActive =@@ -382,7 +390,15 @@ const SequenceRefForwardingFunction: React.ForwardRefRenderFunction<const env = useRemotionEnvironment();if (props.layout !== 'none' && !env.isRendering) {if (props.premountFor || props.postmountFor) {- return <PremountedPostmountedSequence {...props} ref={ref} />;+ return <PremountedPostmountedSequence ref={ref} {...props} />;+ }++ if (+ ENABLE_V5_BREAKING_CHANGES &&+ props.premountFor === undefined &&+ props.postmountFor === undefined+ ) {+ return <PremountedPostmountedSequence ref={ref} {...props} />;}}diff --git a/packages/docs/docs/5-0-migration.mdx b/packages/docs/docs/5-0-migration.mdxindex 06fef8476a..bf4979942c 100644--- a/packages/docs/docs/5-0-migration.mdx+++ b/packages/docs/docs/5-0-migration.mdx@@ -103,11 +103,18 @@ When using `loadFonts()` from `@remotion/google-fonts`, you must now specify whiimport {loadFont} from '@remotion/google-fonts/Roboto';loadFont('normal', {- weights: ['400', '700'],- subsets: ['latin'],+ weights: ['400', '700'],+ subsets: ['latin'],});```+## Sequences are automatically premounted++[`<Sequence>`](/docs/sequence), [`<Series.Sequence>`](/docs/series) and [`<TransitionSeries.Sequence>`](/docs/transitions/transitionseries) components now automatically [premount](/docs/player/premounting) for 1 second (`fps` frames) before they appear.+This prevents black frames that were commonly seen when a `<Sequence>` containing heavy content (e.g. videos, images) appeared.++**Required action**: If you don't want this behavior for a specific Sequence, opt out by passing [`premountFor={0}`](/docs/sequence#premountfor).+## License changesRemotion 5.0 has an updated license. View the [license](https://github.com/remotion-dev/remotion/blob/5-0-license/LICENSE.md) here or compare the [changes](https://github.com/remotion-dev/remotion/pull/3750).diff --git a/packages/docs/docs/player/premounting.mdx b/packages/docs/docs/player/premounting.mdxindex ef5ed6bbba..b4be657bca 100644--- a/packages/docs/docs/player/premounting.mdx+++ b/packages/docs/docs/player/premounting.mdx@@ -34,8 +34,10 @@ It's time defined by{' '}<a href="/docs/use-current-frame"><code>useCurrentFrame## Preloading a `<Sequence>`-Use premounting sparingly since having more elements mounted will slow down the page.-Add the [`premountFor`](/docs/sequence#premountfor) prop to the [`<Sequence>`](/docs/sequence) component to enable premounting.+From [v5.0](/docs/5-0-migration), all [`<Sequence>`](/docs/sequence) components are premounted for 1 second (`fps` frames) by default.+You can opt out by passing `premountFor={0}`.++In v4, add the [`premountFor`](/docs/sequence#premountfor) prop to the [`<Sequence>`](/docs/sequence) component to enable premounting.The number you pass is the number in frames you premount the component for.diff --git a/packages/docs/docs/sequence.mdx b/packages/docs/docs/sequence.mdxindex 2821b7d18e..1382c1b1fe 100644--- a/packages/docs/docs/sequence.mdx+++ b/packages/docs/docs/sequence.mdx@@ -219,6 +219,7 @@ A class name to be applied to the container. If `layout` is set to `none`, there### `premountFor?`<AvailableFrom v="4.0.140" />[Premount](/docs/player/premounting) the sequence for a set number of frames.+From [v5.0](/docs/5-0-migration), the default value changes from `0` to `fps` (1 second).### `postmountFor?`<AvailableFrom v="4.0.340" />