mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] components: avoid leaks when children are outdated/destroyed
Every use case involving some sort of key set on a component would give birth to a leak in an async context: - If a key of a component changed, the outdated one was never destroyed. - destroyed component were never removed from their parent's reference map. This commit solves both issues, that are tightly linked anyway.
This commit is contained in:
committed by
Aaron Bohy
parent
38f39b6755
commit
c221721d7f
@@ -644,6 +644,7 @@ export class CodeGenerator {
|
||||
index: block!.childNumber,
|
||||
forceNewBlock: false,
|
||||
isLast: ctx.isLast && i === children.length - 1,
|
||||
tKeyExpr: ctx.tKeyExpr,
|
||||
});
|
||||
this.compileAST(child, subCtx);
|
||||
}
|
||||
|
||||
@@ -276,6 +276,7 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
||||
|
||||
patch() {
|
||||
this.bdom!.patch(this!.fiber!.bdom!, false);
|
||||
this.cleanOutdatedChildren();
|
||||
this.fiber!.appliedToDom = true;
|
||||
this.fiber = null;
|
||||
}
|
||||
@@ -287,4 +288,21 @@ export class ComponentNode<T extends typeof Component = typeof Component>
|
||||
remove() {
|
||||
this.bdom!.remove();
|
||||
}
|
||||
|
||||
cleanOutdatedChildren() {
|
||||
const childrenEntries = Object.entries(this.children);
|
||||
if (!childrenEntries.length) {
|
||||
return;
|
||||
}
|
||||
const children = this.children;
|
||||
for (const [key, node] of childrenEntries) {
|
||||
const status = node.status;
|
||||
if (status !== STATUS.MOUNTED) {
|
||||
delete children[key];
|
||||
if (status !== STATUS.DESTROYED) {
|
||||
node.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,6 +144,7 @@ export class RootFiber extends Fiber {
|
||||
|
||||
// Step 2: patching the dom
|
||||
node.bdom!.patch(this.bdom!, Object.keys(node.children).length > 0);
|
||||
node.cleanOutdatedChildren();
|
||||
this.appliedToDom = true;
|
||||
|
||||
this.locked = false;
|
||||
|
||||
Reference in New Issue
Block a user