unmount head children correctly

pull/1024/head
Rich Harris 7 years ago
parent ed44f7d1fa
commit 291a0baa16

@ -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});`);

@ -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);`);

@ -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, "");

Loading…
Cancel
Save