@samitouri / QOS-React / commits / 5103e1d6a1

warn for using maps as children with owner info (#7260)

Keyan Zhang committed Jul 13, 2016 at 08:29 UTC 5103e1d6a122685d9a44931163c7ee7d70bc2819
2 files changed +32 -1
src/shared/utils/__tests__/traverseAllChildren-test.js
+23
@@ -15,11 +15,14 @@ describe('traverseAllChildren', function() {
15 var traverseAllChildren;
16 var React;
17 var ReactFragment;
18 + var ReactTestUtils;
19 +
20 beforeEach(function() {
21 jest.resetModuleRegistry();
22 traverseAllChildren = require('traverseAllChildren');
23 React = require('React');
24 ReactFragment = require('ReactFragment');
25 + ReactTestUtils = require('ReactTestUtils');
26 });
27
28 function frag(obj) {
@@ -536,4 +539,24 @@ describe('traverseAllChildren', function() {
539 );
540 });
541
542 + it('should warn for using maps as children with owner info', function() {
543 + spyOn(console, 'error');
544 +
545 + var Parent = React.createClass({
546 + render() {
547 + return (
548 + <div>{new Map([['foo', 0], ['bar', 1]])}</div>
549 + );
550 + },
551 + });
552 +
553 + ReactTestUtils.renderIntoDocument(<Parent />);
554 +
555 + expect(console.error.calls.count()).toBe(1);
556 + expect(console.error.calls.argsFor(0)[0]).toBe(
557 + 'Warning: Using Maps as children is not yet fully supported. It is an ' +
558 + 'experimental feature that might be removed. Convert it to a sequence ' +
559 + '/ iterable of keyed ReactElements instead. Check the render method of `Parent`.'
560 + );
561 + });
562 });
src/shared/utils/traverseAllChildren.js
+9 -1
@@ -117,11 +117,19 @@ function traverseAllChildrenImpl(
117 }
118 } else {
119 if (__DEV__) {
120 + var mapsAsChildrenAddendum = '';
121 + if (ReactCurrentOwner.current) {
122 + var mapsAsChildrenOwnerName = ReactCurrentOwner.current.getName();
123 + if (mapsAsChildrenOwnerName) {
124 + mapsAsChildrenAddendum = ' Check the render method of `' + mapsAsChildrenOwnerName + '`.';
125 + }
126 + }
127 warning(
128 didWarnAboutMaps,
129 'Using Maps as children is not yet fully supported. It is an ' +
130 'experimental feature that might be removed. Convert it to a ' +
124 - 'sequence / iterable of keyed ReactElements instead.'
131 + 'sequence / iterable of keyed ReactElements instead.%s',
132 + mapsAsChildrenAddendum
133 );
134 didWarnAboutMaps = true;
135 }