Skip to content
This repository was archived by the owner on Apr 4, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/htmlbars-compiler/tests/diffing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,18 @@ test("Morph order is preserved when rerendering with duplicate keys", function()
equalTokens(result.fragment, `<ul><li>B1</li><li>A2</li></ul>`);
deepEqual(getNames(), ['B1', 'A1']);
});

test("duplicate keys are allowed when duplicate is last morph", function() {
var template = compile(`<ul>{{#each items as |item|}}<li>{{item.name}}</li>{{/each}}</ul>`);

let a1 = { key: "a", name: "A1" };
let a2 = { key: "a", name: "A2" };

var result = template.render({ items: [ ] }, env);

result.rerender(env, { items: [ a1 ] });
equalTokens(result.fragment, `<ul><li>A1</li></ul>`);

result.rerender(env, { items: [a1, a2] });
equalTokens(result.fragment, `<ul><li>A1</li><li>A2</li></ul>`);
});
2 changes: 1 addition & 1 deletion packages/htmlbars-runtime/lib/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function yieldItem(template, env, parentScope, morph, renderState, visitor) {
let handledMorphs = renderState.handledMorphs;
let key;

if (handledMorphs[_key]) {
if (_key in handledMorphs) {
// In this branch we are dealing with a duplicate key. The strategy
// is to take the original key and append a counter to it that is
// incremented every time the key is reused. In order to greatly
Expand Down