Skip to content

Commit

Permalink
fix(slate): delete orphaned nodes (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
prevwong authored Jan 28, 2021
1 parent 4d34370 commit f201ddc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/slate/src/extend/editable/useCraftStateSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,21 @@ export const useCraftStateSync = () => {

// Save the current selection
state.nodes[id].data.custom.selection = slateSelection;

// Remove any deleted Slate nodes from the Craft state
slateEditor.operations
.filter((op) => op.type === 'remove_node')
.forEach((op) => {
if (!op.node) {
return;
}

if (!state.nodes[op.node.id]) {
return;
}

delete state.nodes[op.node.id];
});
});
};

Expand Down

0 comments on commit f201ddc

Please sign in to comment.