@@ -263,6 +263,9 @@ export function createPatchFunction (backend) {
263
263
264
264
function createChildren ( vnode , children , insertedVnodeQueue ) {
265
265
if ( Array . isArray ( children ) ) {
266
+ if ( process . env . NODE_ENV !== 'production' ) {
267
+ checkDuplicateKeys ( children )
268
+ }
266
269
for ( let i = 0 ; i < children . length ; ++ i ) {
267
270
createElm ( children [ i ] , insertedVnodeQueue , vnode . elm , null , true )
268
271
}
@@ -394,6 +397,10 @@ export function createPatchFunction (backend) {
394
397
// during leaving transitions
395
398
const canMove = ! removeOnly
396
399
400
+ if ( process . env . NODE_ENV !== 'production' ) {
401
+ checkDuplicateKeys ( newCh )
402
+ }
403
+
397
404
while ( oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx ) {
398
405
if ( isUndef ( oldStartVnode ) ) {
399
406
oldStartVnode = oldCh [ ++ oldStartIdx ] // Vnode has been moved left
@@ -426,13 +433,6 @@ export function createPatchFunction (backend) {
426
433
createElm ( newStartVnode , insertedVnodeQueue , parentElm , oldStartVnode . elm )
427
434
} else {
428
435
vnodeToMove = oldCh [ idxInOld ]
429
- /* istanbul ignore if */
430
- if ( process . env . NODE_ENV !== 'production' && ! vnodeToMove ) {
431
- warn (
432
- 'It seems there are duplicate keys that is causing an update error. ' +
433
- 'Make sure each v-for item has a unique key.'
434
- )
435
- }
436
436
if ( sameVnode ( vnodeToMove , newStartVnode ) ) {
437
437
patchVnode ( vnodeToMove , newStartVnode , insertedVnodeQueue )
438
438
oldCh [ idxInOld ] = undefined
@@ -453,6 +453,24 @@ export function createPatchFunction (backend) {
453
453
}
454
454
}
455
455
456
+ function checkDuplicateKeys ( children ) {
457
+ const seenKeys = { }
458
+ for ( let i = 0 ; i < children . length ; i ++ ) {
459
+ const vnode = children [ i ]
460
+ const key = vnode . key
461
+ if ( isDef ( key ) ) {
462
+ if ( seenKeys [ key ] ) {
463
+ warn (
464
+ `Duplicate keys detected: '${ key } '. This may cause an update error.` ,
465
+ vnode . context
466
+ )
467
+ } else {
468
+ seenKeys [ key ] = true
469
+ }
470
+ }
471
+ }
472
+ }
473
+
456
474
function findIdxInOld ( node , oldCh , start , end ) {
457
475
for ( let i = start ; i < end ; i ++ ) {
458
476
const c = oldCh [ i ]
0 commit comments