Skip to content

Commit

Permalink
warn for using maps as children with owner info
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyan Zhang committed Jul 13, 2016
1 parent e5513ec commit 0149b05
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/shared/utils/__tests__/traverseAllChildren-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 (
<div>{new Map([['foo', 0], ['bar', 1]])}</div>
);
},
});

ReactTestUtils.renderIntoDocument(<Parent />);

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`.'
);
});
});
10 changes: 9 additions & 1 deletion src/shared/utils/traverseAllChildren.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0149b05

Please sign in to comment.