@@ -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
+ checkChildren ( 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
+ checkChildren ( 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,23 @@ export function createPatchFunction (backend) {
453
453
}
454
454
}
455
455
456
+ function checkChildren ( children ) {
457
+ const cache = { }
458
+
459
+ for ( let i = 0 ; i < children . length ; i ++ ) {
460
+ const vnode = children [ i ]
461
+ const key = vnode . key
462
+
463
+ if ( key != null ) {
464
+ if ( cache [ key ] ) {
465
+ warn ( `The duplicate keys: '${ key } ' that is causing an update error.` )
466
+ } else {
467
+ cache [ key ] = true
468
+ }
469
+ }
470
+ }
471
+ }
472
+
456
473
function findIdxInOld ( node , oldCh , start , end ) {
457
474
for ( let i = start ; i < end ; i ++ ) {
458
475
const c = oldCh [ i ]
0 commit comments