diff --git a/src/classic/element/ReactElementValidator.js b/src/classic/element/ReactElementValidator.js index 1f25c23d42..90f412e693 100644 --- a/src/classic/element/ReactElementValidator.js +++ b/src/classic/element/ReactElementValidator.js @@ -134,7 +134,8 @@ function validatePropertyKey(name, element, parentType) { */ function warnAndMonitorForKeyUse(message, element, parentType) { var ownerName = getCurrentOwnerDisplayName(); - var parentName = parentType.displayName || parentType.name; + var parentName = typeof parentType === 'string' ? + parentType : parentType.displayName || parentType.name; var useName = ownerName || parentName; var memoizer = ownerHasKeyUseWarning[message] || ( @@ -145,9 +146,10 @@ function warnAndMonitorForKeyUse(message, element, parentType) { } memoizer[useName] = true; - message += ownerName ? - ` Check the render method of ${ownerName}.` : - ` Check the React.render call using <${parentName}>.`; + message += + ownerName ? ` Check the render method of ${ownerName}.` : + parentName ? ` Check the React.render call using <${parentName}>.` : + ''; // Usually the current owner is the offender, but if it accepts children as a // property, it may be the creator of the child that's responsible for diff --git a/src/classic/element/__tests__/ReactElementValidator-test.js b/src/classic/element/__tests__/ReactElementValidator-test.js index 9555335c48..98de236f28 100644 --- a/src/classic/element/__tests__/ReactElementValidator-test.js +++ b/src/classic/element/__tests__/ReactElementValidator-test.js @@ -80,6 +80,46 @@ describe('ReactElementValidator', function() { ); }); + it('warns for keys for arrays with no owner or parent info', function() { + spyOn(console, 'warn'); + + var Anonymous = React.createClass({ + displayName: undefined, + render: function() { + return
; + } + }); + + var divs = [ + , + + ]; + ReactTestUtils.renderIntoDocument(