fix: 修复 #9418 调整带来的编辑器预览错误问题 (#9427) (#9430)

This commit is contained in:
liaoxuezhi 2024-01-15 11:41:03 +08:00 committed by GitHub
parent b313e11263
commit 2417fbd053
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -624,7 +624,25 @@ export const EditorNode = types
if (!node) { if (!node) {
return; return;
} }
(getRoot(self) as any).unsetNode(node);
// 因为 react 的钩子是 父级先执行 willUnmout所以顶级的节点先删除
// 节点删除了,再去读取 mst 又会报错
// 所以在节点删除之前,先把所有孩子节点从 root.map 中删除
// 否则 root.map 里面会残存很多已经销毁的节点
const pool = [node];
const list = [];
while (pool.length) {
const item = pool.shift();
list.push(item);
pool.push(...item.children);
}
const root = getRoot(self) as any;
list.forEach((item: any) => {
root.unsetNode(item);
});
self.children.splice(idx, 1); self.children.splice(idx, 1);
}, },