Skip to content

🎥 Make videos programmatically with React

also serialize default props

Jonny Burger46f1d5be241d
diff --git a/packages/lambda/src/functions/launch.ts b/packages/lambda/src/functions/launch.ts
index d890c5362d..49cdfbc23d 100644
--- a/packages/lambda/src/functions/launch.ts
+++ b/packages/lambda/src/functions/launch.ts
@@ -247,13 +247,22 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
const reqSend = timer('sending off requests');
- const serializedResolvedProps = await serializeInputProps({
- propsType: 'resolved-props',
- region: getCurrentRegionInFunction(),
- inputProps: comp.props,
- type: 'video-or-audio',
- userSpecifiedBucketName: params.bucketName,
- });
+ const [serializedResolvedProps, serializedDefaultProps] = await Promise.all([
+ serializeInputProps({
+ propsType: 'resolved-props',
+ region: getCurrentRegionInFunction(),
+ inputProps: comp.props,
+ type: 'video-or-audio',
+ userSpecifiedBucketName: params.bucketName,
+ }),
+ serializeInputProps({
+ propsType: 'default-props',
+ region: getCurrentRegionInFunction(),
+ inputProps: comp.defaultProps,
+ type: 'video-or-audio',
+ userSpecifiedBucketName: params.bucketName,
+ }),
+ ]);
const lambdaPayloads = chunks.map((chunkPayload) => {
const payload: LambdaPayload = {
@@ -292,7 +301,7 @@ const innerLaunchHandler = async (params: LambdaPayload, options: Options) => {
version: VERSION,
},
resolvedProps: serializedResolvedProps,
- defaultProps: comp.defaultProps,
+ defaultProps: serializedDefaultProps,
};
return payload;
});
diff --git a/packages/lambda/src/functions/renderer.ts b/packages/lambda/src/functions/renderer.ts
index dc2ae006ab..faf8ed0deb 100644
--- a/packages/lambda/src/functions/renderer.ts
+++ b/packages/lambda/src/functions/renderer.ts
@@ -63,6 +63,14 @@ const renderHandler = async (
propsType: 'resolved-props',
});
+ const defaultPropsPromise = deserializeInputProps({
+ bucketName: params.bucketName,
+ expectedBucketOwner: options.expectedBucketOwner,
+ region: getCurrentRegionInFunction(),
+ serialized: params.defaultProps,
+ propsType: 'default-props',
+ });
+
const browserInstance = await getBrowserInstance(
params.logLevel,
false,
@@ -112,6 +120,8 @@ const renderHandler = async (
const inputProps = await inputPropsPromise;
const resolvedProps = await resolvedPropsPromise;
+ const defaultProps = await defaultPropsPromise;
+
await new Promise<void>((resolve, reject) => {
RenderInternals.internalRenderMedia({
composition: {
@@ -121,7 +131,7 @@ const renderHandler = async (
height: params.height,
width: params.width,
props: resolvedProps,
- defaultProps: params.defaultProps,
+ defaultProps,
},
imageFormat: params.imageFormat,
inputProps,
diff --git a/packages/lambda/src/shared/constants.ts b/packages/lambda/src/shared/constants.ts
index b78e960361..5b4ea7923b 100644
--- a/packages/lambda/src/shared/constants.ts
+++ b/packages/lambda/src/shared/constants.ts
@@ -179,6 +179,10 @@ export const postRenderDataKey = (renderId: string) => {
return `${rendersPrefix(renderId)}/post-render-metadata.json`;
};
+export const defaultPropsKey = (hash: string) => {
+ return `default-props/${hash}.json`;
+};
+
export const inputPropsKey = (hash: string) => {
return `input-props/${hash}.json`;
};
@@ -334,7 +338,7 @@ export type LambdaPayloads = {
timeoutInMilliseconds: number;
chromiumOptions: ChromiumOptions;
resolvedProps: SerializedInputProps;
- defaultProps: Record<string, unknown>;
+ defaultProps: SerializedInputProps;
scale: number;
everyNthFrame: number;
muted: boolean;
diff --git a/packages/lambda/src/shared/serialize-props.ts b/packages/lambda/src/shared/serialize-props.ts
index 4ce75bbc30..4761757987 100644
--- a/packages/lambda/src/shared/serialize-props.ts
+++ b/packages/lambda/src/shared/serialize-props.ts
@@ -1,11 +1,11 @@
import {getOrCreateBucket} from '../api/get-or-create-bucket';
import type {AwsRegion} from '../client';
import {lambdaReadFile, lambdaWriteFile} from '../functions/helpers/io';
-import {inputPropsKey, resolvedPropsKey, type SerializedInputProps} from './constants';
+import {defaultPropsKey, inputPropsKey, resolvedPropsKey, type SerializedInputProps} from './constants';
import {randomHash} from './random-hash';
import {streamToString} from './stream-to-string';
-type PropsType = 'input-props' | 'resolved-props';
+type PropsType = 'input-props' | 'resolved-props' | 'default-props';
export const serializeInputProps = async ({
inputProps,
@@ -65,7 +65,7 @@ export const serializeInputProps = async ({
};
} catch (err) {
throw new Error(
- 'Error serializing inputProps. Check it has no circular references or reduce the size if the object is big.'
+ `Error serializing ${propsType}. Check it has no circular references or reduce the size if the object is big.`
);
}
};
@@ -113,6 +113,10 @@ const makeKey = (type: PropsType, hash: string): string => {
return inputPropsKey(hash);
}
+ if (type === 'default-props') {
+ return defaultPropsKey(hash);
+ }
+
return resolvedPropsKey(hash);
}