diff --git a/src/generators/dom/visitors/EachBlock.ts b/src/generators/dom/visitors/EachBlock.ts index a4baec1795..7b232b6ef2 100644 --- a/src/generators/dom/visitors/EachBlock.ts +++ b/src/generators/dom/visitors/EachBlock.ts @@ -163,7 +163,7 @@ function keyed( block.addVariable(head); block.addVariable(last); - if (node.children[0] && node.children[0].type === 'Element') { + if (node.children[0] && node.children[0].type === 'Element' && !generator.components.has(node.children[0].name)) { // TODO or text/tag/raw node._block.first = node.children[0]._state.parentNode; // TODO this is highly confusing } else { diff --git a/test/runtime/samples/each-block-keyed-unshift/Nested.html b/test/runtime/samples/each-block-keyed-unshift/Nested.html new file mode 100644 index 0000000000..53ccc03d4a --- /dev/null +++ b/test/runtime/samples/each-block-keyed-unshift/Nested.html @@ -0,0 +1 @@ +

{{title}}

\ No newline at end of file diff --git a/test/runtime/samples/each-block-keyed-unshift/_config.js b/test/runtime/samples/each-block-keyed-unshift/_config.js new file mode 100644 index 0000000000..23e659c622 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-unshift/_config.js @@ -0,0 +1,24 @@ +export default { + data: { + titles: [{ name: 'b' }, { name: 'c' }] + }, + + html: ` +

b

+

c

+ `, + + test (assert, component, target) { + component.set({ + titles: [{ name: 'a' }, { name: 'b' }, { name: 'c' }] + }); + + assert.htmlEqual(target.innerHTML, ` +

a

+

b

+

c

+ `); + + component.destroy(); + } +}; diff --git a/test/runtime/samples/each-block-keyed-unshift/main.html b/test/runtime/samples/each-block-keyed-unshift/main.html new file mode 100644 index 0000000000..854e77ae6f --- /dev/null +++ b/test/runtime/samples/each-block-keyed-unshift/main.html @@ -0,0 +1,13 @@ +{{#each titles as title @name}} + +{{/each}} + + \ No newline at end of file