[FIX] component, fiber: subchildren should also patch and destroy their children

Have a GrandParent which controls whether one of its GrandChildren is displayed or not.
First, the GrandChild is displayed. Then, change the state of the GrandParent in order to kill
the GrandChild.

Before this commit the GrandChild is only removed from the DOM, as bdom correctly works.
But it is not destroyed.

After this commit, the GrandChild is correctly destroyed.
This commit is contained in:
Lucas Perais (lpe)
2022-01-13 18:46:27 +01:00
committed by Aaron Bohy
parent a6bdca082a
commit 4a03a60084
4 changed files with 85 additions and 67 deletions
+7 -7
View File
@@ -275,8 +275,11 @@ export class ComponentNode<T extends typeof Component = typeof Component>
}
patch() {
this.bdom!.patch(this!.fiber!.bdom!, false);
this.cleanOutdatedChildren();
const hasChildren = Object.keys(this.children).length > 0;
this.bdom!.patch(this!.fiber!.bdom!, hasChildren);
if (hasChildren) {
this.cleanOutdatedChildren();
}
this.fiber!.appliedToDom = true;
this.fiber = null;
}
@@ -290,12 +293,9 @@ export class ComponentNode<T extends typeof Component = typeof Component>
}
cleanOutdatedChildren() {
const childrenEntries = Object.entries(this.children);
if (!childrenEntries.length) {
return;
}
const children = this.children;
for (const [key, node] of childrenEntries) {
for (const key in children) {
const node = children[key];
const status = node.status;
if (status !== STATUS.MOUNTED) {
delete children[key];