diff --git a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts index 8b99861a2f..66610c7985 100644 --- a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts +++ b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts @@ -47,10 +47,10 @@ export default class RawMustacheTagWrapper extends Tag { content => `${html_tag}.p(${content});` ); - const anchor = in_head ? 'null' : needs_anchor ? html_anchor : this.next ? this.next.var : 'null'; + const update_anchor = in_head ? 'null' : needs_anchor ? html_anchor : this.next ? this.next.var : 'null'; - block.builders.hydrate.add_line(`${html_tag} = new @HtmlTag(${init}, ${anchor});`); - block.builders.mount.add_line(`${html_tag}.m(${parent_node || '#target'}, anchor);`); + block.builders.hydrate.add_line(`${html_tag} = new @HtmlTag(${init}, ${update_anchor});`); + block.builders.mount.add_line(`${html_tag}.m(${parent_node || '#target'}${parent_node ? '' : ', anchor'});`); if (needs_anchor) { block.add_element(html_anchor, '@empty()', '@empty()', parent_node); diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index b5123ba48d..6faf3d9c60 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -252,7 +252,7 @@ export class HtmlTag { this.u(html); } - m(target: HTMLElement, anchor: HTMLElement) { + m(target: HTMLElement, anchor: HTMLElement = null) { for (let i = 0; i < this.n.length; i += 1) { insert(target, this.n[i], anchor); } diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js index 6c72bcfae6..f6c9d52dc4 100644 --- a/test/js/samples/each-block-changed-check/expected.js +++ b/test/js/samples/each-block-changed-check/expected.js @@ -55,7 +55,7 @@ function create_each_block(ctx) { append(span, t4); append(span, t5); append(div, t6); - html_tag.m(div, anchor); + html_tag.m(div); }, p(changed, ctx) { diff --git a/test/runtime/samples/each-block-keyed-html-b/_config.js b/test/runtime/samples/each-block-keyed-html-b/_config.js new file mode 100644 index 0000000000..6343a31769 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-html-b/_config.js @@ -0,0 +1,14 @@ +export default { + html: ` +