Fix modal draft state overwriting store-managed children
Problem: Child nodes created via NodePicker while editing a parent node would disappear when clicking "Done" on the modal. This caused: - Child nodes not appearing in tree after closing modal - Validation errors about non-existent nodes - Tree unable to save Root cause: Modal used structuredClone() to create local draft state, which included a stale `children: []` array. When saving, this overwrote the actual children that were added to the store via addNode(). Fix: Exclude `children` from the draft when saving, since children are managed separately by addNode/deleteNode store actions. Also documented this critical pattern in LESSONS-LEARNED.md for future reference when implementing modals with local draft state. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,10 @@ export function NodeEditorModal({ node, onClose, isNewNode = false }: NodeEditor
|
||||
|
||||
const handleSave = () => {
|
||||
// Commit all draft changes to the store
|
||||
updateNode(node.id, draft)
|
||||
// IMPORTANT: Exclude 'children' from the update - children are managed separately
|
||||
// by addNode/deleteNode and we don't want to overwrite them with stale draft data
|
||||
const { children, ...draftWithoutChildren } = draft
|
||||
updateNode(node.id, draftWithoutChildren)
|
||||
onClose()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user