Skip to content

🎥 Make videos programmatically with React

add a test

Jonny Burger666422505566
diff --git a/packages/bundler/src/renderEntry.tsx b/packages/bundler/src/renderEntry.tsx
index 06be2b27f5..f4945e1569 100644
--- a/packages/bundler/src/renderEntry.tsx
+++ b/packages/bundler/src/renderEntry.tsx
@@ -6,7 +6,13 @@ import type {render, unmountComponentAtNode} from 'react-dom';
// hence why we import the right thing all the time but need to differentiate here
import ReactDOM from 'react-dom/client';
import type {AnyComposition, BundleState, VideoConfig} from 'remotion';
-import {continueRender, delayRender, Internals, VERSION} from 'remotion';
+import {
+ continueRender,
+ delayRender,
+ getInputProps,
+ Internals,
+ VERSION,
+} from 'remotion';
import {getBundleMode, setBundleMode} from './bundle-mode';
import {Homepage} from './homepage/homepage';
@@ -267,15 +273,24 @@ if (typeof window !== 'undefined') {
window.getStaticCompositions = (): Promise<VideoConfig[]> => {
const compositions = getUnevaluatedComps();
+ const inputProps =
+ typeof window === 'undefined' ||
+ Internals.getRemotionEnvironment() === 'player-development' ||
+ Internals.getRemotionEnvironment() === 'player-production'
+ ? {}
+ : getInputProps() ?? {};
+
return Promise.all(
compositions.map(async (c): Promise<VideoConfig> => {
const handle = delayRender(
`Running calculateMetadata() for composition ${c.id}. If you didn't want to evaluate this composition, use "selectComposition()" instead of "getCompositions()"`
);
+
const comp = Internals.resolveVideoConfig({
composition: c,
editorProps: {},
signal: new AbortController().signal,
+ inputProps,
});
const resolved = await Promise.resolve(comp);
@@ -303,11 +318,19 @@ if (typeof window !== 'undefined') {
`Running the calculateMetadata() function for composition ${compId}`
);
+ const inputProps =
+ typeof window === 'undefined' ||
+ Internals.getRemotionEnvironment() === 'player-development' ||
+ Internals.getRemotionEnvironment() === 'player-production'
+ ? {}
+ : getInputProps() ?? {};
+
const prom = await Promise.resolve(
Internals.resolveVideoConfig({
composition: selectedComp,
editorProps: {},
signal: abortController.signal,
+ inputProps,
})
);
continueRender(handle);
diff --git a/packages/core/src/ResolveCompositionConfig.tsx b/packages/core/src/ResolveCompositionConfig.tsx
index 4a12a1faed..70eddc5672 100644
--- a/packages/core/src/ResolveCompositionConfig.tsx
+++ b/packages/core/src/ResolveCompositionConfig.tsx
@@ -83,9 +83,21 @@ export const ResolveCompositionConfig: React.FC<
return controller;
}
+ const inputProps =
+ typeof window === 'undefined' ||
+ getRemotionEnvironment() === 'player-development' ||
+ getRemotionEnvironment() === 'player-production'
+ ? {}
+ : getInputProps() ?? {};
+
const {signal} = controller;
- const promOrNot = resolveVideoConfig({composition, editorProps, signal});
+ const promOrNot = resolveVideoConfig({
+ composition,
+ editorProps,
+ inputProps,
+ signal,
+ });
if (typeof promOrNot === 'object' && 'then' in promOrNot) {
setResolvedConfigs((r) => ({
diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.ts
index 9dae37d206..7cad0bdf08 100644
--- a/packages/core/src/resolve-video-config.ts
+++ b/packages/core/src/resolve-video-config.ts
@@ -1,8 +1,6 @@
import type {AnyZodObject} from 'zod';
import type {CalcMetadataReturnType} from './Composition.js';
import type {TCompMetadataWithCalcFunction} from './CompositionManager.js';
-import {getInputProps} from './config/input-props.js';
-import {getRemotionEnvironment} from './get-environment.js';
import {validateDimension} from './validation/validate-dimensions.js';
import {validateDurationInFrames} from './validation/validate-duration-in-frames.js';
import type {VideoConfig} from './video-config.js';
@@ -12,6 +10,7 @@ export const resolveVideoConfig = ({
composition,
editorProps: editorPropsOrUndefined,
signal,
+ inputProps,
}: {
composition: TCompMetadataWithCalcFunction<
AnyZodObject,
@@ -19,21 +18,15 @@ export const resolveVideoConfig = ({
>;
editorProps: object;
signal: AbortSignal;
+ inputProps: Record<string, unknown>;
}): VideoConfig | Promise<VideoConfig> => {
- const guardedInputProps =
- typeof window === 'undefined' ||
- getRemotionEnvironment() === 'player-development' ||
- getRemotionEnvironment() === 'player-production'
- ? {}
- : getInputProps() ?? {};
-
const calculatedProm = composition.calculateMetadata
? composition.calculateMetadata({
defaultProps: composition.defaultProps ?? {},
props: {
...(composition.defaultProps ?? {}),
...(editorPropsOrUndefined ?? {}),
- ...guardedInputProps,
+ ...inputProps,
},
abortSignal: signal,
})
@@ -71,7 +64,10 @@ export const resolveVideoConfig = ({
...data,
id: composition.id,
defaultProps: composition.defaultProps ?? {},
- props: composition.defaultProps ?? {},
+ props: {
+ ...(composition.defaultProps ?? {}),
+ ...(inputProps ?? {}),
+ },
};
}
diff --git a/packages/core/src/test/composition-validation.test.tsx b/packages/core/src/test/composition-validation.test.tsx
index 97be233d4b..1a5db4d708 100644
--- a/packages/core/src/test/composition-validation.test.tsx
+++ b/packages/core/src/test/composition-validation.test.tsx
@@ -26,6 +26,7 @@ describe('Composition-validation render should throw with invalid props', () =>
},
editorProps: {},
signal: new AbortController().signal,
+ inputProps: {},
}),
/The "width" prop of the "<Composition \/>" component with the id "id" must be a number, but you passed a value of type undefined/
@@ -45,6 +46,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -64,6 +66,7 @@ describe('Composition-validation render should throw with invalid props', () =>
id: 'id',
width: 100,
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -103,6 +106,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -124,6 +128,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: -100,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -143,6 +148,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 0,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -184,6 +190,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -203,6 +210,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -222,6 +230,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -263,6 +272,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -282,6 +292,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
+ inputProps: {},
editorProps: {},
signal: new AbortController().signal,
}),
@@ -420,3 +431,28 @@ describe('Composition-validation render should NOT throw with valid props', () =
);
});
});
+
+test('should resolve props correctly with no calculateMetadata()', async () => {
+ const resolved = await resolveVideoConfig({
+ composition: {
+ calculateMetadata: null,
+ durationInFrames: 100,
+ fps: 30,
+ height: 1080,
+ id: 'test',
+ width: 1920,
+ defaultProps: {
+ a: 'b',
+ },
+ },
+ editorProps: {},
+ inputProps: {
+ c: 'd',
+ },
+ signal: new AbortController().signal,
+ });
+ expect(resolved.props).toEqual({
+ a: 'b',
+ c: 'd',
+ });
+});