diff --git a/src/generators/nodes/Component.ts b/src/generators/nodes/Component.ts index 551f54b8ec..95b29fcbd3 100644 --- a/src/generators/nodes/Component.ts +++ b/src/generators/nodes/Component.ts @@ -289,6 +289,8 @@ export default class Component extends Node { `if (${name}) ${name}._mount(${parentNode || '#target'}, ${parentNode ? 'null' : 'anchor'});` ); + const updateMountNode = this.getUpdateMountNode(anchor); + block.builders.update.addBlock(deindent` if (${switch_vars.value} !== (${switch_vars.value} = ${snippet})) { if (${name}) ${name}.destroy(); @@ -298,7 +300,7 @@ export default class Component extends Node { ${name}._fragment.c(); ${this.children.map(child => remount(generator, child, name))} - ${name}._mount(${anchor}.parentNode, ${anchor}); + ${name}._mount(${updateMountNode}, ${anchor}); ${eventHandlers.map(handler => deindent` ${name}.on("${handler.name}", ${handler.var}); diff --git a/test/runtime/samples/dynamic-component-inside-element/Bar.html b/test/runtime/samples/dynamic-component-inside-element/Bar.html new file mode 100644 index 0000000000..7c21e68c89 --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/Bar.html @@ -0,0 +1 @@ +
{{x}}, therefore Bar
\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-inside-element/Foo.html b/test/runtime/samples/dynamic-component-inside-element/Foo.html new file mode 100644 index 0000000000..2303a92c0a --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/Foo.html @@ -0,0 +1 @@ +{{x}}, therefore Foo
\ No newline at end of file diff --git a/test/runtime/samples/dynamic-component-inside-element/_config.js b/test/runtime/samples/dynamic-component-inside-element/_config.js new file mode 100644 index 0000000000..de1dbfdac2 --- /dev/null +++ b/test/runtime/samples/dynamic-component-inside-element/_config.js @@ -0,0 +1,19 @@ +export default { + data: { + x: true + }, + + html: ` +true, therefore Foo
false, therefore Bar