ReactFragment counts as a node without warning
Fixes #3286.
Ben Alpert committed
Mar 1, 2015 at 11:49 UTC
7ebf7c46f5521e5e03eefc9f5e0899131bc0a7db
3 files changed
+22
-2
src/addons/ReactFragment.js
+2
-1
@@ -141,7 +141,8 @@ var ReactFragment = {
141
warning(
142
didWarnForFragment(fragment),
143
'Any use of a keyed object should be wrapped in ' +
144
- 'React.addons.createFragment(object) before passed as a child.'
144
+ 'React.addons.createFragment(object) before being passed as a ' +
145
+ 'child.'
146
);
147
return fragment;
148
}
src/classic/types/ReactPropTypes.js
+2
@@ -12,6 +12,7 @@
12
'use strict';
13
14
var ReactElement = require('ReactElement');
15
+var ReactFragment = require('ReactFragment');
16
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');
17
18
var emptyFunction = require('emptyFunction');
@@ -301,6 +302,7 @@ function isNode(propValue) {
302
if (ReactElement.isValidElement(propValue)) {
303
return true;
304
}
305
+ propValue = ReactFragment.extractIfFragment(propValue);
306
for (var k in propValue) {
307
if (!isNode(propValue[k])) {
308
return false;
src/classic/types/__tests__/ReactPropTypes-test.js
+18
-1
@@ -13,6 +13,7 @@
13
14
var PropTypes;
15
var React;
16
+var ReactFragment;
17
var ReactPropTypeLocations;
18
var ReactTestUtils;
19
@@ -48,6 +49,7 @@ describe('ReactPropTypes', function() {
49
beforeEach(function() {
50
PropTypes = require('ReactPropTypes');
51
React = require('React');
52
+ ReactFragment = require('ReactFragment');
53
ReactPropTypeLocations = require('ReactPropTypeLocations');
54
ReactTestUtils = require('ReactTestUtils');
55
});
@@ -356,6 +358,7 @@ describe('ReactPropTypes', function() {
358
});
359
360
it('should not warn for valid values', function() {
361
+ spyOn(console, 'warn');
362
typeCheckPass(PropTypes.node, <div />);
363
typeCheckPass(PropTypes.node, false);
364
typeCheckPass(PropTypes.node, <MyComponent />);
@@ -371,7 +374,21 @@ describe('ReactPropTypes', function() {
374
<MyComponent />
375
]);
376
374
- // Object of rendereable things
377
+ // Object of renderable things
378
+ var frag = ReactFragment.create;
379
+ typeCheckPass(PropTypes.node, frag({
380
+ k0: 123,
381
+ k1: 'Some string',
382
+ k2: <div />,
383
+ k3: frag({
384
+ k30: <MyComponent />,
385
+ k31: frag({k310: <a />}),
386
+ k32: 'Another string'
387
+ })
388
+ }));
389
+ expect(console.warn.calls).toEqual([]);
390
+
391
+ // This should also pass, though it warns
392
typeCheckPass(PropTypes.node, {
393
k0: 123,
394
k1: 'Some string',