From 291a0baa16dffe2988bf6d25b2543e95ae0ae1f8 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 13 Dec 2017 20:16:39 -0500 Subject: [PATCH] unmount head children correctly --- src/generators/dom/Block.ts | 3 ++- src/generators/nodes/Element.ts | 6 +++++- test/runtime/index.js | 6 ++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/generators/dom/Block.ts b/src/generators/dom/Block.ts index ad452b930e..036b4e9014 100644 --- a/src/generators/dom/Block.ts +++ b/src/generators/dom/Block.ts @@ -134,8 +134,9 @@ export default class Block { this.builders.create.addLine(`${name} = ${renderStatement};`); this.builders.claim.addLine(`${name} = ${claimStatement || renderStatement};`); - if (parentNode && parentNode !== 'document.head') { + if (parentNode) { this.builders.mount.addLine(`@appendNode(${name}, ${parentNode});`); + if (parentNode === 'document.head') this.builders.unmount.addLine(`@detachNode(${name});`); } else { this.builders.mount.addLine(`@insertNode(${name}, #target, anchor);`); this.builders.unmount.addLine(`@detachNode(${name});`); diff --git a/src/generators/nodes/Element.ts b/src/generators/nodes/Element.ts index fdd09d676f..02b679bac1 100644 --- a/src/generators/nodes/Element.ts +++ b/src/generators/nodes/Element.ts @@ -193,10 +193,14 @@ export default class Element extends Node { } } - if (initialMountNode && initialMountNode !== 'document.head') { + if (initialMountNode) { block.builders.mount.addLine( `@appendNode(${name}, ${initialMountNode});` ); + + if (initialMountNode === 'document.head') { + block.builders.unmount.addLine(`@detachNode(${name});`); + } } else { block.builders.mount.addLine(`@insertNode(${name}, #target, anchor);`); diff --git a/test/runtime/index.js b/test/runtime/index.js index 1ead0a11cb..fa3482337b 100644 --- a/test/runtime/index.js +++ b/test/runtime/index.js @@ -52,7 +52,7 @@ describe("runtime", () => { throw new Error("Forgot to remove `solo: true` from test"); } - (config.skip ? it.skip : config.solo ? it.only : it)(`${dir} (${shared ? 'shared' : 'inline'} helpers)`, () => { + (config.skip ? it.skip : config.solo ? it.only : it)(`${dir} (${shared ? 'shared' : 'inline'} helpers${hydrate ? ' , hydration' : ''})`, () => { if (failed.has(dir)) { // this makes debugging easier, by only printing compiled output once throw new Error('skipping test, already failed'); @@ -183,7 +183,9 @@ describe("runtime", () => { } if (config.test) { - return config.test(assert, component, target, window, raf); + return Promise.resolve(config.test(assert, component, target, window, raf)).then(() => { + component.destroy(); + }); } else { component.destroy(); assert.equal(target.innerHTML, "");