Skip to content

Commit ac287ed

Browse files
committed
works correct
1 parent 2f80667 commit ac287ed

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/compile/render-dom/Block.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export default class Block {
164164

165165
if (parent_node) {
166166
this.builders.mount.add_line(`@append(${parent_node}, ${name});`);
167-
if (parent_node === 'document.head') this.builders.destroy.add_line(`@detach(${name});`);
167+
if (parent_node === 'document.head' && !no_detach) this.builders.destroy.add_line(`@detach(${name});`);
168168
} else {
169169
this.builders.mount.add_line(`@insert(#target, ${name}, anchor);`);
170170
if (!no_detach) this.builders.destroy.add_conditional('detaching', `@detach(${name});`);

src/compile/render-dom/wrappers/RawMustacheTag.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,18 @@ export default class RawMustacheTagWrapper extends Tag {
2121
render(block: Block, parent_node: string, parent_nodes: string) {
2222
const name = this.var;
2323

24+
const in_head = parent_node === 'document.head';
25+
const needs_anchors = !parent_node || in_head;
26+
27+
// if in head always needs anchors
28+
if (in_head) {
29+
this.prev = null;
30+
this.next = null;
31+
}
32+
2433
// TODO use is_dom_node instead of type === 'Element'?
25-
const needs_anchor_before = this.prev ? this.prev.node.type !== 'Element' : !parent_node;
26-
const needs_anchor_after = this.next ? this.next.node.type !== 'Element' : !parent_node;
34+
const needs_anchor_before = this.prev ? this.prev.node.type !== 'Element' : needs_anchors;
35+
const needs_anchor_after = this.next ? this.next.node.type !== 'Element' : needs_anchors;
2736

2837
const anchor_before = needs_anchor_before
2938
? block.get_unique_name(`${name}_before`)
@@ -89,7 +98,7 @@ export default class RawMustacheTagWrapper extends Tag {
8998

9099
block.builders.mount.add_line(insert(init));
91100

92-
if (!parent_node) {
101+
if (needs_anchors) {
93102
block.builders.destroy.add_conditional('detaching', needs_anchor_before
94103
? `${detach}\n@detach(${anchor_before});`
95104
: detach);
@@ -100,4 +109,4 @@ export default class RawMustacheTagWrapper extends Tag {
100109
add_anchor_after();
101110
}
102111
}
103-
}
112+
}

0 commit comments

Comments
 (0)