🎥 Make videos programmatically with React
cancel edit if it is the same
Jonny Burgerd9e75301d71f
diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsxindex 59582ea1ee..e45aa9ca01 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/ZodArrayEditor.tsx@@ -13,6 +13,7 @@ import {Spacing} from '../../layout';import {ValidationMessage} from '../../NewComposition/ValidationMessage';import {optionRow} from '../layout';import {createZodValues} from './create-zod-values';+import {deepEqual} from './deep-equal';import {useLocalState} from './local-state';import {SchemaFieldsetLabel} from './SchemaLabel';import type {JSONPath} from './zod-types';@@ -155,34 +156,3 @@ export const ZodArrayEditor: React.FC<{</div>);};--// eslint-disable-next-line @typescript-eslint/no-explicit-any-function deepEqual(a: any, b: any): boolean {- if (a === b) {- return true;- }-- if (- typeof a !== 'object' ||- a === null ||- typeof b !== 'object' ||- b === null- ) {- return false;- }-- const keysA = Object.keys(a);- const keysB = Object.keys(b);-- if (keysA.length !== keysB.length) {- return false;- }-- for (const key of keysA) {- if (!keysB.includes(key) || !deepEqual(a[key], b[key])) {- return false;- }- }-- return true;-}diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/deep-equal.ts b/packages/cli/src/editor/components/RenderModal/SchemaEditor/deep-equal.tsnew file mode 100644index 0000000000..cb12f097d7--- /dev/null+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/deep-equal.ts@@ -0,0 +1,30 @@+// eslint-disable-next-line @typescript-eslint/no-explicit-any+export function deepEqual(a: any, b: any): boolean {+ if (a === b) {+ return true;+ }++ if (+ typeof a !== 'object' ||+ a === null ||+ typeof b !== 'object' ||+ b === null+ ) {+ return false;+ }++ const keysA = Object.keys(a);+ const keysB = Object.keys(b);++ if (keysA.length !== keysB.length) {+ return false;+ }++ for (const key of keysA) {+ if (!keysB.includes(key) || !deepEqual(a[key], b[key])) {+ return false;+ }+ }++ return true;+}diff --git a/packages/cli/src/editor/components/RenderModal/SchemaEditor/local-state.ts b/packages/cli/src/editor/components/RenderModal/SchemaEditor/local-state.tsindex fe7ef13d69..90083834ba 100644--- a/packages/cli/src/editor/components/RenderModal/SchemaEditor/local-state.ts+++ b/packages/cli/src/editor/components/RenderModal/SchemaEditor/local-state.ts@@ -1,5 +1,6 @@import {useCallback, useRef, useState} from 'react';import type {z} from 'zod';+import {deepEqual} from './deep-equal';import type {UpdaterFunction} from './ZodSwitch';type LocalState<T> = {@@ -30,34 +31,28 @@ export const useLocalState = <T>({const onChange = useCallback((updater: (oldV: T) => T, forceApply: boolean) => {const newValue = updater(stateRef.current.value);+ const isSame = deepEqual(newValue, stateRef.current.value);+ if (isSame) {+ return;+ }+const safeParse = schema.safeParse(newValue);if (safeParse.success || forceApply) {setValue(updater, forceApply);- setLocalValue((oldLocalState) => {- const newState = {- revision: oldLocalState.revision + 1,- value: newValue,- zodValidation: safeParse,- };-- stateRef.current = newState;+ }- return newState;- });- } else {- setLocalValue((oldLocalState) => {- const newState = {- revision: oldLocalState.revision + 1,- value: newValue,- zodValidation: safeParse,- };+ setLocalValue((oldLocalState) => {+ const newState = {+ revision: oldLocalState.revision + 1,+ value: newValue,+ zodValidation: safeParse,+ };- stateRef.current = newState;+ stateRef.current = newState;- return newState;- });- }+ return newState;+ });},[schema, setValue]);