diff --git a/src/shared/utils/__tests__/traverseAllChildren-test.js b/src/shared/utils/__tests__/traverseAllChildren-test.js index 8469abe76a2b7..caf6661072273 100644 --- a/src/shared/utils/__tests__/traverseAllChildren-test.js +++ b/src/shared/utils/__tests__/traverseAllChildren-test.js @@ -15,11 +15,14 @@ describe('traverseAllChildren', function() { var traverseAllChildren; var React; var ReactFragment; + var ReactTestUtils; + beforeEach(function() { jest.resetModuleRegistry(); traverseAllChildren = require('traverseAllChildren'); React = require('React'); ReactFragment = require('ReactFragment'); + ReactTestUtils = require('ReactTestUtils'); }); function frag(obj) { @@ -536,4 +539,24 @@ describe('traverseAllChildren', function() { ); }); + it('should warn for using maps as children with owner info', function() { + spyOn(console, 'error'); + + var Parent = React.createClass({ + render() { + return ( +
{new Map([['foo', 0], ['bar', 1]])}
+ ); + }, + }); + + ReactTestUtils.renderIntoDocument(); + + expect(console.error.calls.count()).toBe(1); + expect(console.error.calls.argsFor(0)[0]).toBe( + 'Warning: Using Maps as children is not yet fully supported. It is an ' + + 'experimental feature that might be removed. Convert it to a sequence ' + + '/ iterable of keyed ReactElements instead. Check the render method of `Parent`.' + ); + }); }); diff --git a/src/shared/utils/traverseAllChildren.js b/src/shared/utils/traverseAllChildren.js index 7d03dc02d1792..20d6e8eb520fb 100644 --- a/src/shared/utils/traverseAllChildren.js +++ b/src/shared/utils/traverseAllChildren.js @@ -117,11 +117,19 @@ function traverseAllChildrenImpl( } } else { if (__DEV__) { + var mapsAsChildrenAddendum = ''; + if (ReactCurrentOwner.current) { + var mapsAsChildrenOwnerName = ReactCurrentOwner.current.getName(); + if (mapsAsChildrenOwnerName) { + mapsAsChildrenAddendum = ' Check the render method of `' + mapsAsChildrenOwnerName + '`.'; + } + } warning( didWarnAboutMaps, 'Using Maps as children is not yet fully supported. It is an ' + 'experimental feature that might be removed. Convert it to a ' + - 'sequence / iterable of keyed ReactElements instead.' + 'sequence / iterable of keyed ReactElements instead.%s', + mapsAsChildrenAddendum ); didWarnAboutMaps = true; }