diff --git a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts index 63889dd829..1e6213cf02 100644 --- a/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts +++ b/src/compiler/compile/render_dom/wrappers/RawMustacheTag.ts @@ -53,8 +53,8 @@ export default class RawMustacheTagWrapper extends Tag { const update_anchor = in_head ? 'null' : needs_anchor ? html_anchor : this.next ? this.next.var : 'null'; - block.chunks.hydrate.push(b`${html_tag} = new @HtmlTag(${init}, ${update_anchor});`); - block.chunks.mount.push(b`${html_tag}.m(${parent_node || '#target'}, ${parent_node ? null : '#anchor'});`); + block.chunks.hydrate.push(b`${html_tag} = new @HtmlTag(${update_anchor});`); + block.chunks.mount.push(b`${html_tag}.m(${init}, ${parent_node || '#target'}, ${parent_node ? null : '#anchor'});`); if (needs_anchor) { block.add_element(html_anchor, x`@empty()`, x`@empty()`, parent_node); diff --git a/src/runtime/internal/dom.ts b/src/runtime/internal/dom.ts index 02fd3dc23e..a497e02136 100644 --- a/src/runtime/internal/dom.ts +++ b/src/runtime/internal/dom.ts @@ -294,7 +294,7 @@ export function add_resize_listener(node: HTMLElement, fn: () => void) { } else if (unsubscribe && iframe.contentWindow) { unsubscribe(); } - + detach(iframe); }; } @@ -319,29 +319,31 @@ export class HtmlTag { t: HTMLElement; a: HTMLElement; - constructor(html: string, anchor: HTMLElement = null) { - this.e = element('div'); + constructor(anchor: HTMLElement = null) { this.a = anchor; - this.u(html); } - m(target: HTMLElement, anchor: HTMLElement = null) { - for (let i = 0; i < this.n.length; i += 1) { - insert(target, this.n[i], anchor); + m(html: string, target: HTMLElement, anchor: HTMLElement = null) { + if (!this.e) { + this.e = element(target.nodeName as keyof HTMLElementTagNameMap); + this.t = target; } - this.t = target; + this.u(html, anchor); } - u(html: string) { + u(html: string, anchor) { this.e.innerHTML = html; this.n = Array.from(this.e.childNodes); + + for (let i = 0; i < this.n.length; i += 1) { + insert(this.t, this.n[i], anchor); + } } p(html: string) { this.d(); - this.u(html); - this.m(this.t, this.a); + this.u(html, this.a); } d() {