Skip to content

🎥 Make videos programmatically with React

don't serialize if not in the json tab

Jonny Burger90002c6e8479
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
index 1ce34279c6..03dfcd07ef 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalData.tsx
@@ -137,15 +137,15 @@ export const RenderModalData: React.FC<{
() => getPersistedShowWarningState()
);
- const serializedJSON: SerializedJSONWithDate = useMemo(() => {
+ const inJSONEditor = mode === 'json';
+ const serializedJSON: SerializedJSONWithDate | null = useMemo(() => {
+ if (!inJSONEditor) {
+ return null;
+ }
+
const value = inputProps ?? {};
return serializeJSONWithDate(value, 2);
- }, [inputProps]);
-
- const isCustomDateUsed = serializedJSON.customDateUsed;
- const [localValue, setLocalValue] = React.useState<State>(() => {
- return parseJSON(serializedJSON.serializedString);
- });
+ }, [inJSONEditor, inputProps]);
const cliProps = getInputProps();
const [canSaveDefaultProps, setCanSaveDefaultProps] =
@@ -250,11 +250,17 @@ export const RenderModalData: React.FC<{
return getRenderModalWarnings({
canSaveDefaultProps,
cliProps,
- isCustomDateUsed,
- inJSONEditor: mode === 'json',
+ isCustomDateUsed: serializedJSON ? serializedJSON.customDateUsed : false,
+ inJSONEditor,
propsEditType,
});
- }, [canSaveDefaultProps, cliProps, isCustomDateUsed, mode, propsEditType]);
+ }, [
+ canSaveDefaultProps,
+ cliProps,
+ inJSONEditor,
+ propsEditType,
+ serializedJSON,
+ ]);
if (connectionStatus === 'disconnected') {
return (
@@ -329,8 +335,7 @@ export const RenderModalData: React.FC<{
onSave={onUpdate}
valBeforeSafe={valBeforeSafe}
showSaveButton={showSaveButton}
- localValue={localValue}
- setLocalValue={setLocalValue}
+ serializedJSON={serializedJSON}
parseJSON={parseJSON}
/>
)}
diff --git a/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx b/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx
index 0e7906a12f..c79e34ff6f 100644
--- a/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx
+++ b/packages/cli/src/editor/components/RenderModal/RenderModalJSONPropsEditor.tsx
@@ -6,6 +6,7 @@ import {Row, Spacing} from '../layout';
import {RemTextarea} from '../NewComposition/RemTextarea';
import {ValidationMessage} from '../NewComposition/ValidationMessage';
import type {State} from './RenderModalData';
+import type {SerializedJSONWithDate} from './SchemaEditor/date-serialization';
const style: React.CSSProperties = {
fontFamily: 'monospace',
@@ -37,9 +38,8 @@ export const RenderModalJSONPropsEditor: React.FC<{
onSave: () => void;
valBeforeSafe: unknown;
showSaveButton: boolean;
- localValue: State;
- setLocalValue: React.Dispatch<React.SetStateAction<State>>;
parseJSON: (str: string) => State;
+ serializedJSON: SerializedJSONWithDate | null;
}> = ({
setValue,
value,
@@ -48,12 +48,19 @@ export const RenderModalJSONPropsEditor: React.FC<{
onSave,
valBeforeSafe,
showSaveButton,
- localValue,
- setLocalValue,
parseJSON,
+ serializedJSON,
}) => {
+ if (serializedJSON === null) {
+ throw new Error('expecting serializedJSON to be defined');
+ }
+
const keybindings = useKeybinding();
+ const [localValue, setLocalValue] = React.useState<State>(() => {
+ return parseJSON(serializedJSON.serializedString);
+ });
+
const onPretty = useCallback(() => {
if (!localValue.validJSON) {
return;