Skip to content

🎥 Make videos programmatically with React

update

Jonny Burger2c8fd2945eda
diff --git a/packages/studio/src/ResolveCompositionConfigInStudio.tsx b/packages/studio/src/ResolveCompositionConfigInStudio.tsx
index 21fbc26b8e..ee0e84d459 100644
--- a/packages/studio/src/ResolveCompositionConfigInStudio.tsx
+++ b/packages/studio/src/ResolveCompositionConfigInStudio.tsx
@@ -29,13 +29,14 @@ type VideoConfigState =
export const ResolveCompositionConfigInStudio: React.FC<
PropsWithChildren<{
- children: React.ReactNode;
+ readonly children: React.ReactNode;
}>
> = ({children}) => {
const [currentRenderModalComposition, setCurrentRenderModalComposition] =
useState<string | null>(null);
- const {compositions, canvasContent, currentCompositionMetadata} =
- useContext(Internals.CompositionManager);
+ const {compositions, canvasContent, currentCompositionMetadata} = useContext(
+ Internals.CompositionManager,
+ );
const {fastRefreshes, manualRefreshes} = useContext(FastRefreshContext);
// don't do anything, this component should should re-render if the value changes
@@ -111,7 +112,9 @@ export const ResolveCompositionConfigInStudio: React.FC<
const result = Internals.resolveVideoConfigOrCatch({
compositionId,
- calculateMetadata: calculateMetadata as Parameters<typeof Internals.resolveVideoConfigOrCatch>[0]['calculateMetadata'],
+ calculateMetadata: calculateMetadata as Parameters<
+ typeof Internals.resolveVideoConfigOrCatch
+ >[0]['calculateMetadata'],
inputProps: combinedProps,
signal,
defaultProps,
@@ -202,57 +205,61 @@ export const ResolveCompositionConfigInStudio: React.FC<
const currentComposition =
canvasContent?.type === 'composition' ? canvasContent.compositionId : null;
- useImperativeHandle(Internals.resolveCompositionsRef, () => {
- return {
- setCurrentRenderModalComposition: (id: string | null) => {
- setCurrentRenderModalComposition(id);
- },
- reloadCurrentlySelectedComposition: () => {
- if (!currentComposition) {
- return;
- }
-
- const composition = compositions.find(
- (c) => c.id === currentComposition,
- );
-
- if (!composition) {
- throw new Error(
- `Could not find composition with id ${currentComposition}`,
+ useImperativeHandle(
+ Internals.resolveCompositionsRef,
+ () => {
+ return {
+ setCurrentRenderModalComposition: (id: string | null) => {
+ setCurrentRenderModalComposition(id);
+ },
+ reloadCurrentlySelectedComposition: () => {
+ if (!currentComposition) {
+ return;
+ }
+
+ const composition = compositions.find(
+ (c) => c.id === currentComposition,
);
- }
- const editorProps = allEditorProps[currentComposition] ?? {};
+ if (!composition) {
+ throw new Error(
+ `Could not find composition with id ${currentComposition}`,
+ );
+ }
- const defaultProps = {
- ...(composition.defaultProps ?? {}),
- ...(editorProps ?? {}),
- };
+ const editorProps = allEditorProps[currentComposition] ?? {};
- const props = {
- ...defaultProps,
- ...(inputProps ?? {}),
- };
+ const defaultProps = {
+ ...(composition.defaultProps ?? {}),
+ ...(editorProps ?? {}),
+ };
- doResolution({
- defaultProps,
- calculateMetadata: composition.calculateMetadata,
- combinedProps: props,
- compositionDurationInFrames: composition.durationInFrames ?? null,
- compositionFps: composition.fps ?? null,
- compositionHeight: composition.height ?? null,
- compositionWidth: composition.width ?? null,
- compositionId: composition.id,
- });
- },
- };
- }, [
- allEditorProps,
- compositions,
- currentComposition,
- doResolution,
- inputProps,
- ]);
+ const props = {
+ ...defaultProps,
+ ...(inputProps ?? {}),
+ };
+
+ doResolution({
+ defaultProps,
+ calculateMetadata: composition.calculateMetadata,
+ combinedProps: props,
+ compositionDurationInFrames: composition.durationInFrames ?? null,
+ compositionFps: composition.fps ?? null,
+ compositionHeight: composition.height ?? null,
+ compositionWidth: composition.width ?? null,
+ compositionId: composition.id,
+ });
+ },
+ };
+ },
+ [
+ allEditorProps,
+ compositions,
+ currentComposition,
+ doResolution,
+ inputProps,
+ ],
+ );
const isTheSame = selectedComposition?.id === renderModalComposition?.id;
diff --git a/packages/studio/src/Studio.tsx b/packages/studio/src/Studio.tsx
index 50bcac1849..e47d99c2ec 100644
--- a/packages/studio/src/Studio.tsx
+++ b/packages/studio/src/Studio.tsx
@@ -1,10 +1,9 @@
-import React, {useContext, useLayoutEffect} from 'react';
+import React, {useLayoutEffect} from 'react';
import {createPortal} from 'react-dom';
import {Internals} from 'remotion';
import {Editor} from './components/Editor';
import {EditorContexts} from './components/EditorContexts';
import {ServerDisconnected} from './components/Notifications/ServerDisconnected';
-import {FastRefreshContext} from './fast-refresh-context';
import {FastRefreshProvider} from './FastRefreshProvider';
import {injectCSS} from './helpers/inject-css';
import {ResolveCompositionConfigInStudio} from './ResolveCompositionConfigInStudio';
@@ -17,8 +16,6 @@ const StudioInner: React.FC<{
readonly rootComponent: React.FC;
readonly readOnly: boolean;
}> = ({rootComponent, readOnly}) => {
- const {fastRefreshes, manualRefreshes} = useContext(FastRefreshContext);
-
return (
<Internals.CompositionManagerProvider
onlyRenderComposition={null}
@@ -33,7 +30,6 @@ const StudioInner: React.FC<{
logLevel={window.remotion_logLevel}
numberOfAudioTags={window.remotion_numberOfAudioTags}
audioLatencyHint={window.remotion_audioLatencyHint ?? 'interactive'}
- nonceContextSeed={fastRefreshes + manualRefreshes}
>
<ResolveCompositionConfigInStudio>
<EditorContexts readOnlyStudio={readOnly}>