Skip to content

Commit 2bb3199

Browse files
DanielSanRochayyx990803
authored andcommittedNov 30, 2018
polish: warn duplicate keys when patching children into empty node (#8881)
close #8832
1 parent 7585241 commit 2bb3199

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
 

Diff for: ‎src/core/vdom/patch.js

+3
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ export function createPatchFunction (backend) {
550550
if (isDef(oldCh) && isDef(ch)) {
551551
if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly)
552552
} else if (isDef(ch)) {
553+
if (process.env.NODE_ENV !== 'production') {
554+
checkDuplicateKeys(ch)
555+
}
553556
if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '')
554557
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue)
555558
} else if (isDef(oldCh)) {

Diff for: ‎test/unit/modules/vdom/patch/children.spec.js

+12
Original file line numberDiff line numberDiff line change
@@ -530,4 +530,16 @@ describe('vdom patch: children', () => {
530530
patch(vnode2, vnode3)
531531
expect(`Duplicate keys detected: 'b'`).toHaveBeenWarned()
532532
})
533+
534+
it('should warn with duplicate keys: patchVnode with empty oldVnode', () => {
535+
function makeNode (key) {
536+
return new VNode('li', { key: key })
537+
}
538+
539+
const vnode1 = new VNode('div')
540+
const vnode2 = new VNode('div', undefined, ['1', '2', '3', '4', '4'].map(makeNode))
541+
542+
patch(vnode1, vnode2)
543+
expect(`Duplicate keys detected: '4'`).toHaveBeenWarned()
544+
})
533545
})

0 commit comments

Comments
 (0)