-
Notifications
You must be signed in to change notification settings - Fork 47.4k
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
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@@ -163,12 +163,17 @@ ReactElement.createElement = function(type, config, children) { | |||
|
|||
if (config != null) { | |||
if (__DEV__) { | |||
var displayName = typeof type === 'function' ? | |||
(type.displayName || type.name || 'Unknown') : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Unkown'
is a weird default, imagine getting an error message like:
React.createElement(...): Expected props argument to be a plain object. Properties defined in its prototype chain will be ignored. Unknown.
Why not make it an empty string and leave as-is by default?
I'd also change the error message instead of appending the name, what about something like this:
'React.createElement(...): Expected props argument of ' + displayName +
' to be a plain object. Properties defined in its prototype chain will be ignored.'
@mxstbr I've added your proposed changes to the commit.
line 166: warning(
/* eslint-disable no-proto */
config.__proto__ == null || config.__proto__ === Object.prototype,
/* eslint-enable no-proto */
'React.createElement(...): Expected props argument of ' + displayName(type) +
' to be a plain object. Properties defined in its prototype chain will be ignored.'
); |
@@ -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) + |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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".
Thanks for the PR @halt-hammerzeit! We actually removed this warning all together in #7724 so this change is no longer needed. |
Because no one's gonna have an idea where this warning is coming from