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

Better debugging of Expected props argument to be a plain object #7332

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/isomorphic/classic/element/ReactElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ ReactElement.createElement = function(type, config, children) {
/* eslint-disable no-proto */
config.__proto__ == null || config.__proto__ === Object.prototype,
/* eslint-enable no-proto */
'React.createElement(...): Expected props argument to be a plain object. ' +
'Properties defined in its prototype chain will be ignored.'
'React.createElement(...): Expected props argument of ' + displayName(type) +
Copy link
Contributor

Choose a reason for hiding this comment

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

Better to say 'argument of type X' as it's more in line with the language I've seen in other places

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@alexzherdev Wouldn't it confuse people? "Expected props argument of type div", as if "@param {div} props".

' to be a plain object. Properties defined in its prototype chain will be ignored.'
);
}

Expand Down Expand Up @@ -213,10 +213,6 @@ ReactElement.createElement = function(type, config, children) {
}
}
if (__DEV__) {
var displayName = typeof type === 'function' ?
(type.displayName || type.name || 'Unknown') :
type;

// Create dummy `key` and `ref` property to `props` to warn users against its use
var warnAboutAccessingKey = function() {
if (!specialPropKeyWarningShown) {
Expand All @@ -227,7 +223,7 @@ ReactElement.createElement = function(type, config, children) {
'in `undefined` being returned. If you need to access the same ' +
'value within the child component, you should pass it as a different ' +
'prop. (https://fb.me/react-special-props)',
displayName
displayName(type)
);
}
return undefined;
Expand All @@ -243,7 +239,7 @@ ReactElement.createElement = function(type, config, children) {
'in `undefined` being returned. If you need to access the same ' +
'value within the child component, you should pass it as a different ' +
'prop. (https://fb.me/react-special-props)',
displayName
displayName(type)
);
}
return undefined;
Expand Down Expand Up @@ -408,4 +404,10 @@ ReactElement.isValidElement = function(object) {

ReactElement.REACT_ELEMENT_TYPE = REACT_ELEMENT_TYPE;

function displayName(type) {
return typeof type === 'function' ?
(type.displayName || type.name || 'ReactElement') :
type;
}

module.exports = ReactElement;
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ describe('ReactElement', function() {
React.createElement('div', Object.create({foo: 1}));
expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'React.createElement(...): Expected props argument to be a plain object. ' +
'React.createElement(...): Expected props argument of div ' +
'to be a plain object. ' +
'Properties defined in its prototype chain will be ignored.'
);
});
Expand Down