Skip to content

🎥 Make videos programmatically with React

Remotion Studio: Fix saving back staticFile()'s

Jonny Burger5f01cee0068e
diff --git a/packages/cli/src/codemods/stringify-with-path.ts b/packages/cli/src/codemods/stringify-with-path.ts
index 9cb3aeb3a3..eafedaf757 100644
--- a/packages/cli/src/codemods/stringify-with-path.ts
+++ b/packages/cli/src/codemods/stringify-with-path.ts
@@ -23,14 +23,12 @@ export const stringifyDefaultProps = ({
}: {
props: unknown;
enumPaths: EnumPath[];
-}) =>
- JSON.stringify(
+}) => {
+ return JSON.stringify(
props,
replacerWithPath(function (key, value, path) {
- /* Don't replace with arrow function */ const item = this[key];
- if (item instanceof Date) {
- return `__REMOVEQUOTE__new Date('${item.toISOString()}')__REMOVEQUOTE__`;
- }
+ /* Don't replace with arrow function! This function uses `this` */
+ const item = this[key];
if (typeof item === 'string' && doesMatchPath(path, enumPaths)) {
return `${item}__ADD_AS_CONST__`;
@@ -42,6 +40,12 @@ export const stringifyDefaultProps = ({
)}__WRAP_IN_STATIC_FILE_END____REMOVEQUOTE__`;
}
+ if (typeof item === 'string' && item.startsWith(Internals.DATE_TOKEN)) {
+ return `__REMOVEQUOTE____WRAP_IN_DATE_START__${decodeURIComponent(
+ item.replace(Internals.DATE_TOKEN, '')
+ )}__WRAP_IN_DATE_END____REMOVEQUOTE__`;
+ }
+
return value;
})
)
@@ -49,7 +53,10 @@ export const stringifyDefaultProps = ({
.replace(/__REMOVEQUOTE__"/g, '')
.replace(/__ADD_AS_CONST__"/g, '" as const')
.replace(/__WRAP_IN_STATIC_FILE_START__/g, 'staticFile("')
- .replace(/__WRAP_IN_STATIC_FILE_END__/g, '")');
+ .replace(/__WRAP_IN_STATIC_FILE_END__/g, '")')
+ .replace(/__WRAP_IN_DATE_START__/g, 'new Date("')
+ .replace(/__WRAP_IN_DATE_END__/g, '")');
+};
function replacerWithPath(
replacer: (
diff --git a/packages/cli/src/preview-server/routes/update-default-props.ts b/packages/cli/src/preview-server/routes/update-default-props.ts
index da28eeb3fe..e526039643 100644
--- a/packages/cli/src/preview-server/routes/update-default-props.ts
+++ b/packages/cli/src/preview-server/routes/update-default-props.ts
@@ -1,5 +1,4 @@
import {readFileSync, writeFileSync} from 'node:fs';
-import {Internals} from 'remotion';
import {updateDefaultProps} from '../../codemods/update-default-props';
import type {ApiHandler} from '../api-types';
import {getProjectInfo} from '../project-info';
@@ -24,7 +23,7 @@ export const updateDefaultPropsHandler: ApiHandler<
const updated = await updateDefaultProps({
compositionId,
input: readFileSync(projectInfo.videoFile, 'utf-8'),
- newDefaultProps: Internals.deserializeJSONWithCustomFields(defaultProps),
+ newDefaultProps: JSON.parse(defaultProps),
enumPaths,
});
diff --git a/packages/core/src/input-props-serialization.ts b/packages/core/src/input-props-serialization.ts
index cd67a61023..0b5efc64a6 100644
--- a/packages/core/src/input-props-serialization.ts
+++ b/packages/core/src/input-props-serialization.ts
@@ -10,7 +10,7 @@ export type SerializedJSONWithCustomFields = {
setUsed: boolean;
};
-const DATE_TOKEN = 'remotion-date:';
+export const DATE_TOKEN = 'remotion-date:';
export const FILE_TOKEN = 'remotion-file:';
export const serializeJSONWithDate = ({
diff --git a/packages/core/src/internals.ts b/packages/core/src/internals.ts
index 4ce2c49780..6866ffa93e 100644
--- a/packages/core/src/internals.ts
+++ b/packages/core/src/internals.ts
@@ -31,6 +31,7 @@ import {
} from './get-preview-dom-element.js';
import type {SerializedJSONWithCustomFields} from './input-props-serialization.js';
import {
+ DATE_TOKEN,
deserializeJSONWithCustomFields,
FILE_TOKEN,
serializeJSONWithDate,
@@ -153,6 +154,7 @@ export const Internals = {
serializeJSONWithDate,
deserializeJSONWithCustomFields,
FILE_TOKEN,
+ DATE_TOKEN,
NativeLayersProvider,
ClipComposition,
} as const;