@@ -263,6 +263,9 @@ export function createPatchFunction (backend) {
263263
264264 function createChildren ( vnode , children , insertedVnodeQueue ) {
265265 if ( Array . isArray ( children ) ) {
266+ if ( process . env . NODE_ENV !== 'production' ) {
267+ checkDuplicateKeys ( children )
268+ }
266269 for ( let i = 0 ; i < children . length ; ++ i ) {
267270 createElm ( children [ i ] , insertedVnodeQueue , vnode . elm , null , true )
268271 }
@@ -394,6 +397,10 @@ export function createPatchFunction (backend) {
394397 // during leaving transitions
395398 const canMove = ! removeOnly
396399
400+ if ( process . env . NODE_ENV !== 'production' ) {
401+ checkDuplicateKeys ( newCh )
402+ }
403+
397404 while ( oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx ) {
398405 if ( isUndef ( oldStartVnode ) ) {
399406 oldStartVnode = oldCh [ ++ oldStartIdx ] // Vnode has been moved left
@@ -426,13 +433,6 @@ export function createPatchFunction (backend) {
426433 createElm ( newStartVnode , insertedVnodeQueue , parentElm , oldStartVnode . elm )
427434 } else {
428435 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- }
436436 if ( sameVnode ( vnodeToMove , newStartVnode ) ) {
437437 patchVnode ( vnodeToMove , newStartVnode , insertedVnodeQueue )
438438 oldCh [ idxInOld ] = undefined
@@ -453,6 +453,24 @@ export function createPatchFunction (backend) {
453453 }
454454 }
455455
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+
456474 function findIdxInOld ( node , oldCh , start , end ) {
457475 for ( let i = start ; i < end ; i ++ ) {
458476 const c = oldCh [ i ]
0 commit comments