Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix #8832: duplicate keys detected not warned #8881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
3 changes: 3 additions & 0 deletions src/core/vdom/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,9 @@ export function createPatchFunction (backend) {
if (isDef(oldCh) && isDef(ch)) {
if (oldCh !== ch) updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly)
} else if (isDef(ch)) {
if (process.env.NODE_ENV !== 'production') {
checkDuplicateKeys(ch)
}
if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '')
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue)
} else if (isDef(oldCh)) {
Expand Down
12 changes: 12 additions & 0 deletions test/unit/modules/vdom/patch/children.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,4 +530,16 @@ describe('vdom patch: children', () => {
patch(vnode2, vnode3)
expect(`Duplicate keys detected: 'b'`).toHaveBeenWarned()
})

it('should warn with duplicate keys: patchVnode with empty oldVnode', () => {
function makeNode (key) {
return new VNode('li', { key: key })
}

const vnode1 = new VNode('div')
const vnode2 = new VNode('div', undefined, ['1', '2', '3', '4', '4'].map(makeNode))

patch(vnode1, vnode2)
expect(`Duplicate keys detected: '4'`).toHaveBeenWarned()
})
})