Skip to content

Commit

Permalink
dont detach <svelte:head> contents twice - fixes #2086
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 2, 2019
1 parent 9883a50 commit aee2c9c
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/Element/index.ts
Expand Up @@ -272,7 +272,7 @@ export default class ElementWrapper extends Wrapper {
);

if (parent_node === '@_document.head') {
block.builders.destroy.add_line(`@detach(${node});`);
block.builders.destroy.add_conditional('detaching', `@detach(${node});`);
}
} else {
block.builders.mount.add_line(`@insert(#target, ${node}, anchor);`);
Expand Down
6 changes: 4 additions & 2 deletions test/js/samples/head-no-whitespace/expected.js
Expand Up @@ -33,8 +33,10 @@ function create_fragment(ctx) {
o: noop,

d(detaching) {
detach(meta0);
detach(meta1);
if (detaching) {
detach(meta0);
detach(meta1);
}
}
};
}
Expand Down
@@ -0,0 +1,5 @@
<svelte:head>
<meta name="description" content="A"/>
</svelte:head>

A
@@ -0,0 +1,5 @@
<svelte:head>
<meta name="description" content="B"/>
</svelte:head>

B
15 changes: 15 additions & 0 deletions test/runtime/samples/head-detached-in-dynamic-component/_config.js
@@ -0,0 +1,15 @@
export default {
html: `
A
`,

test({ assert, component, window }) {
component.x = false;

const meta = window.document.querySelectorAll('meta');

assert.equal(meta.length, 1);
assert.equal(meta[0].name, 'description');
assert.equal(meta[0].content, 'B');
}
};
@@ -0,0 +1,8 @@
<script>
import A from './A.svelte';
import B from './B.svelte';
export let x = true;
</script>

<svelte:component this="{x ? A : B}"/>

0 comments on commit aee2c9c

Please sign in to comment.