From 73b8cf206e6eecfcf598701b5dc3239b0a711f87 Mon Sep 17 00:00:00 2001 From: trafficlunar Date: Sat, 28 Mar 2026 23:29:25 +0000 Subject: [PATCH] fix: edit form missing properties --- src/components/submit-form/edit-form.tsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/submit-form/edit-form.tsx b/src/components/submit-form/edit-form.tsx index 4fe5826..d841b6b 100644 --- a/src/components/submit-form/edit-form.tsx +++ b/src/components/submit-form/edit-form.tsx @@ -25,6 +25,25 @@ interface Props { likes: number; } +function deepMerge(target: T, source: Partial): T { + const output = structuredClone(target); + + if (typeof source !== "object" || source === null) return output; + + for (const key in source) { + const sourceValue = source[key]; + const targetValue = (output as any)[key]; + + if (typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue)) { + (output as any)[key] = deepMerge(targetValue, sourceValue); + } else { + (output as any)[key] = sourceValue; + } + } + + return output; +} + export default function EditForm({ mii, likes }: Props) { const [files, setFiles] = useState([]); @@ -46,7 +65,7 @@ export default function EditForm({ mii, likes }: Props) { const [makeup, setMakeup] = useState(mii.makeup ?? "PARTIAL"); const hasFilesChanged = useRef(false); - const instructions = useRef({ ...defaultInstructions, ...(mii.instructions as object as Partial) }); + const instructions = useRef(deepMerge(defaultInstructions, (mii.instructions as object) ?? {})); const handleSubmit = async () => { // Validate before sending request