Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReactFragment counts as a node without warning #3293

Merged
merged 1 commit into from
Mar 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/addons/ReactFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ var ReactFragment = {
warning(
didWarnForFragment(fragment),
'Any use of a keyed object should be wrapped in ' +
'React.addons.createFragment(object) before passed as a child.'
'React.addons.createFragment(object) before being passed as a ' +
'child.'
);
return fragment;
}
Expand Down
2 changes: 2 additions & 0 deletions src/classic/types/ReactPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
'use strict';

var ReactElement = require('ReactElement');
var ReactFragment = require('ReactFragment');
var ReactPropTypeLocationNames = require('ReactPropTypeLocationNames');

var emptyFunction = require('emptyFunction');
Expand Down Expand Up @@ -301,6 +302,7 @@ function isNode(propValue) {
if (ReactElement.isValidElement(propValue)) {
return true;
}
propValue = ReactFragment.extractIfFragment(propValue);
for (var k in propValue) {
if (!isNode(propValue[k])) {
return false;
Expand Down
19 changes: 18 additions & 1 deletion src/classic/types/__tests__/ReactPropTypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

var PropTypes;
var React;
var ReactFragment;
var ReactPropTypeLocations;
var ReactTestUtils;

Expand Down Expand Up @@ -48,6 +49,7 @@ describe('ReactPropTypes', function() {
beforeEach(function() {
PropTypes = require('ReactPropTypes');
React = require('React');
ReactFragment = require('ReactFragment');
ReactPropTypeLocations = require('ReactPropTypeLocations');
ReactTestUtils = require('ReactTestUtils');
});
Expand Down Expand Up @@ -356,6 +358,7 @@ describe('ReactPropTypes', function() {
});

it('should not warn for valid values', function() {
spyOn(console, 'warn');
typeCheckPass(PropTypes.node, <div />);
typeCheckPass(PropTypes.node, false);
typeCheckPass(PropTypes.node, <MyComponent />);
Expand All @@ -371,7 +374,21 @@ describe('ReactPropTypes', function() {
<MyComponent />
]);

// Object of rendereable things
// Object of renderable things
var frag = ReactFragment.create;
typeCheckPass(PropTypes.node, frag({
k0: 123,
k1: 'Some string',
k2: <div />,
k3: frag({
k30: <MyComponent />,
k31: frag({k310: <a />}),
k32: 'Another string'
})
}));
expect(console.warn.calls).toEqual([]);

// This should also pass, though it warns
typeCheckPass(PropTypes.node, {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a little weird to me how this warns, but this seems to match the behavior of key warnings on element creation where it warns if any of the object values is an element.

k0: 123,
k1: 'Some string',
Expand Down