From a2ac1d91fa6cfb93b19475976742a1daacf8f4eb Mon Sep 17 00:00:00 2001 From: Cris Ward Date: Sun, 2 Feb 2020 21:31:18 +0000 Subject: [PATCH] disconnecting mutation observer on disconnect --- src/compiler/compile/render_dom/index.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index 1dcffff056..55691aecf6 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -446,8 +446,8 @@ export default function dom( this._root =this.attachShadow({ mode: '${options.shadowDom}' }); ` || b` this._copycontent(); - const observer = new MutationObserver(() => this._slotcontent()); - observer.observe(this, {childList: true, subtree: true}); + this.slotObserver = new MutationObserver(() => this._slotcontent()); + this.slotObserver.observe(this, {childList: true, subtree: true}); `} ${css.code && !lightDom && b`this._root.innerHTML = \`\`;`} ${should_add_css && lightDom && b`if (!@_document.getElementById("${component.stylesheet.id}-style")) ${add_css}();`} @@ -544,6 +544,17 @@ export default function dom( } }` as FunctionExpression }); + + declaration.body.body.push({ + type: 'MethodDefinition', + kind: 'method', + static: false, + computed: false, + key: { type: 'Identifier', name: 'disconnectedCallback' }, + value: x`function() { + this.slotObserver.disconnect(); + }` as FunctionExpression + }); } declaration.body.body.push(...accessors);