diff --git a/src/app/template_helpers.ts b/src/app/template_helpers.ts index 10de502d..86dc3af9 100644 --- a/src/app/template_helpers.ts +++ b/src/app/template_helpers.ts @@ -20,11 +20,7 @@ function callPortal( target: string, content: (ctx: any, node: any, key: string) => BDom ): BDom { - const portal = new VPortal(target, content(ctx, parent, key)) as any; - // make sure we cleanup only once - if (!ctx.__owl) - ctx.__owl__.willDestroy.push(() => portal.cleanup()); - ctx.__owl__.hasPortal = true; + const portal = new VPortal(target, content(ctx, parent, key), ctx.__owl__) as any; return portal; } diff --git a/src/portal.ts b/src/portal.ts index 23fa759b..833038a4 100644 --- a/src/portal.ts +++ b/src/portal.ts @@ -7,13 +7,15 @@ export class VPortal extends VText implements Partial> { realBDom: BDom | null; target: HTMLElement | null = null; - constructor(selector: string, realBDom: BDom) { + constructor(selector: string, realBDom: BDom, ownerComponent: ComponentNode) { super(""); + this.ownerComponent = ownerComponent; this.selector = selector; this.realBDom = realBDom; } mount(parent: HTMLElement, anchor: ChildNode) { super.mount(parent, anchor); + this.ownerComponent.willDestroy.push(() => this.cleanup()); this.target = document.querySelector(this.selector) as any; if (!this.target) { let el: any = this.el;