Skip to content

🎥 Make videos programmatically with React

composition

Jonny Burgerd9122535ac3a
diff --git a/packages/core/src/Composition.tsx b/packages/core/src/Composition.tsx
index 308aeb5496..59f4845e05 100644
--- a/packages/core/src/Composition.tsx
+++ b/packages/core/src/Composition.tsx
@@ -124,7 +124,7 @@ export const Composition = <
});
validateFps(fps, 'as a prop of the <Composition/> component', false);
- validateDefaultAndInputProps(defaultProps, 'defaultProps');
+ validateDefaultAndInputProps(defaultProps, 'defaultProps', id);
registerComposition<Schema, Props>({
durationInFrames,
fps,
diff --git a/packages/core/src/test/composition-validation.test.tsx b/packages/core/src/test/composition-validation.test.tsx
index ba2f7c4a52..9fc28d1545 100644
--- a/packages/core/src/test/composition-validation.test.tsx
+++ b/packages/core/src/test/composition-validation.test.tsx
@@ -387,4 +387,21 @@ describe('Composition-validation render should NOT throw with valid props', () =
)
).not.toThrow();
});
+ test('It should not allow an array as default props', () => {
+ expectToThrow(
+ () =>
+ render(
+ <Composition
+ lazyComponent={() => Promise.resolve({default: AnyComp})}
+ durationInFrames={100}
+ fps={1}
+ height={100}
+ width={100}
+ id="id"
+ defaultProps={[]}
+ />
+ ),
+ /"defaultProps" must be an object, an array was passed for composition "id"/
+ );
+ });
});
diff --git a/packages/core/src/validation/validate-default-props.ts b/packages/core/src/validation/validate-default-props.ts
index 00b02d37d4..1dc217423d 100644
--- a/packages/core/src/validation/validate-default-props.ts
+++ b/packages/core/src/validation/validate-default-props.ts
@@ -1,6 +1,7 @@
export const validateDefaultAndInputProps = (
defaultProps: unknown,
- name: 'defaultProps' | 'inputProps'
+ name: 'defaultProps' | 'inputProps',
+ compositionId: string | null
) => {
if (!defaultProps) {
return;
@@ -13,6 +14,10 @@ export const validateDefaultAndInputProps = (
}
if (Array.isArray(defaultProps)) {
- throw new Error(`"${name}" must be an object, but you passed an array`);
+ throw new Error(
+ `"${name}" must be an object, an array was passed ${
+ compositionId ? `for composition "${compositionId}"` : ''
+ }`
+ );
}
};
diff --git a/packages/player/src/Player.tsx b/packages/player/src/Player.tsx
index 2b9648aec9..5249369395 100644
--- a/packages/player/src/Player.tsx
+++ b/packages/player/src/Player.tsx
@@ -191,7 +191,7 @@ const PlayerFn = <Schema extends AnyZodObject, Props>(
allowFloats: false,
});
Internals.validateFps(fps, 'as a prop of the <Player/> component', false);
- Internals.validateDefaultAndInputProps(inputProps, 'inputProps');
+ Internals.validateDefaultAndInputProps(inputProps, 'inputProps', null);
validateInOutFrames({
durationInFrames,