Skip to content

🎥 Make videos programmatically with React

refactor

Jonny Burgeref70686c5eff
diff --git a/packages/bundler/renderEntry.tsx b/packages/bundler/renderEntry.tsx
index cd6b456f61..a3f0238860 100644
--- a/packages/bundler/renderEntry.tsx
+++ b/packages/bundler/renderEntry.tsx
@@ -343,11 +343,15 @@ if (typeof window !== 'undefined') {
`Running calculateMetadata() for composition ${c.id}. If you didn't want to evaluate this composition, use "selectComposition()" instead of "getCompositions()"`,
);
+ const originalProps = {
+ ...(c.defaultProps ?? {}),
+ ...(inputProps ?? {}),
+ };
+
const comp = Internals.resolveVideoConfig({
composition: c,
- editorProps: {},
signal: new AbortController().signal,
- inputProps,
+ originalProps,
});
const resolved = await Promise.resolve(comp);
@@ -398,12 +402,16 @@ if (typeof window !== 'undefined') {
? {}
: getInputProps() ?? {};
+ const originalProps = {
+ ...(selectedComp.defaultProps ?? {}),
+ ...(inputProps ?? {}),
+ };
+
const prom = await Promise.resolve(
Internals.resolveVideoConfig({
composition: selectedComp,
- editorProps: {},
+ originalProps,
signal: abortController.signal,
- inputProps,
}),
);
continueRender(handle);
diff --git a/packages/core/src/ResolveCompositionConfig.tsx b/packages/core/src/ResolveCompositionConfig.tsx
index 07bef51144..b07852233a 100644
--- a/packages/core/src/ResolveCompositionConfig.tsx
+++ b/packages/core/src/ResolveCompositionConfig.tsx
@@ -63,12 +63,15 @@ export const ResolveCompositionConfig: React.FC<
useState<string | null>(null);
const {compositions, canvasContent, currentCompositionMetadata} =
useContext(CompositionManager);
- const selectedComposition = compositions.find(
- (c) =>
- canvasContent &&
- canvasContent.type === 'composition' &&
- canvasContent.compositionId === c.id,
- );
+ const selectedComposition = useMemo(() => {
+ return compositions.find(
+ (c) =>
+ canvasContent &&
+ canvasContent.type === 'composition' &&
+ canvasContent.compositionId === c.id,
+ );
+ }, [canvasContent, compositions]);
+
const renderModalComposition = compositions.find(
(c) => c.id === currentRenderModalComposition,
);
@@ -104,10 +107,15 @@ export const ResolveCompositionConfig: React.FC<
const {signal} = controller;
+ const originalProps = {
+ ...(composition.defaultProps ?? {}),
+ ...(editorProps ?? {}),
+ ...(inputProps ?? {}),
+ };
+
const promOrNot = resolveVideoConfig({
composition,
- editorProps,
- inputProps,
+ originalProps,
signal,
});
diff --git a/packages/core/src/resolve-video-config.ts b/packages/core/src/resolve-video-config.ts
index ca3543725f..3874db60dc 100644
--- a/packages/core/src/resolve-video-config.ts
+++ b/packages/core/src/resolve-video-config.ts
@@ -60,24 +60,16 @@ const validateCalculated = ({
export const resolveVideoConfig = ({
composition,
- editorProps: editorPropsOrUndefined,
signal,
- inputProps,
+ originalProps,
}: {
composition: TCompMetadataWithCalcFunction<
AnyZodObject,
Record<string, unknown>
>;
- editorProps: object;
signal: AbortSignal;
- inputProps: Record<string, unknown>;
+ originalProps: Record<string, unknown>;
}): VideoConfig | Promise<VideoConfig> => {
- const originalProps = {
- ...(composition.defaultProps ?? {}),
- ...(editorPropsOrUndefined ?? {}),
- ...(inputProps ?? {}),
- };
-
const calculatedProm = composition.calculateMetadata
? composition.calculateMetadata({
defaultProps: composition.defaultProps ?? {},
diff --git a/packages/core/src/test/composition-validation.test.tsx b/packages/core/src/test/composition-validation.test.tsx
index 039cb11a2b..895d86f33c 100644
--- a/packages/core/src/test/composition-validation.test.tsx
+++ b/packages/core/src/test/composition-validation.test.tsx
@@ -24,9 +24,8 @@ describe('Composition-validation render should throw with invalid props', () =>
width: undefined,
defaultProps: {},
},
- editorProps: {},
+ originalProps: {},
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/,
@@ -46,8 +45,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
@@ -66,8 +64,7 @@ describe('Composition-validation render should throw with invalid props', () =>
id: 'id',
width: 100,
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/The "height" prop of the "<Composition \/>" component with the id "id" must be positive, but got 0./,
@@ -106,8 +103,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/The "height" prop of the "<Composition \/>" component with the id "id" must be an integer, but is 100.01./,
@@ -128,8 +124,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: -100,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/The "width" prop of the "<Composition \/>" component with the id "id" must be positive, but got -100./,
@@ -148,8 +143,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 0,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/The "width" prop of the "<Composition \/>" component with the id "id" must be positive, but got 0./,
@@ -190,8 +184,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/The "durationInFrames" prop of the "<Composition \/>" component with the id "id" must be positive, but got -100./,
@@ -210,8 +203,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/The "durationInFrames" prop of the "<Composition \/>" component with the id "id" must be positive, but got 0./,
@@ -230,8 +222,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/The "durationInFrames" prop of the "<Composition \/>" component with the id "id" must be an integer, but got 0.11./,
@@ -272,8 +263,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/"fps" must be positive, but got -30./,
@@ -292,8 +282,7 @@ describe('Composition-validation render should throw with invalid props', () =>
width: 100,
defaultProps: {},
},
- inputProps: {},
- editorProps: {},
+ originalProps: {},
signal: new AbortController().signal,
}),
/"fps" must be positive, but got 0./,
@@ -445,8 +434,8 @@ test('should resolve props correctly with no calculateMetadata()', async () => {
a: 'b',
},
},
- editorProps: {},
- inputProps: {
+ originalProps: {
+ a: 'b',
c: 'd',
},
signal: new AbortController().signal,