Skip to content

Commit

Permalink
only apply key to keyed each block, not its children - fixes #1202
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Mar 5, 2018
1 parent 3554908 commit 7b4c486
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/generators/dom/Block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export default class Block {
}

child(options: BlockOptions) {
return new Block(Object.assign({}, this, options, { parent: this }));
return new Block(Object.assign({}, this, { key: null }, options, { parent: this }));
}

contextualise(expression: Node, context?: string, isEventHandler?: boolean) {
Expand Down
15 changes: 15 additions & 0 deletions test/runtime/samples/if-in-keyed-each/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
data: {
items: [
{ id: 1, name: 'one' },
{ id: 2, name: 'two' }
]
},

html: `
<ul>
<li>one</li>
<li>two</li>
</ul>
`
};
7 changes: 7 additions & 0 deletions test/runtime/samples/if-in-keyed-each/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ul>
{{#each items as item @id}}
{{#if item.id}}
<li>{{item.name}}</li>
{{/if}}
{{/each}}
</ul>

0 comments on commit 7b4c486

Please sign in to comment.