-
Notifications
You must be signed in to change notification settings - Fork 47.1k
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
Add more specific error messages for bad callback in setState, replaceState, and ReactDOM.render #6310
Conversation
I also noticed that top-level render does not have a similar protection and just fails with |
@gaearon updated the pull request. |
@gaearon updated the pull request. |
@gaearon updated the pull request. |
@gaearon updated the pull request. |
@@ -138,14 +145,6 @@ var ReactUpdateQueue = { | |||
}, | |||
|
|||
enqueueCallbackInternal: function(internalInstance, callback) { | |||
invariant( |
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.
I removed this one because it’s not enough for ReactDOM.render()
code path. ReactMount
calls the callback synchronously on the initial render so we would fail to print the error if we only checked here.
Currently ReactMount
is the only thing using enqueueCallbackInternal
. I could put an additional validateCallback
call here too but then it would run twice on every initial render.
👍 |
This builds on #5193 and introduces an important, in my opinion, detail (constructor function name) that makes issues like #6306 more easily identified.
Additionally, this removes the mention of methods that have been removed (
setProps
andreplaceProps
).When using
onClick={this.setState.bind(this, nextState)}
by mistake, the error message says:0.14
After #5193
After this PR
Why?
setProps
,replaceProps
).enqueueCallback()
is an implementation detail and is confusing to the user.SyntheticMouseEvent
) makes it much more clear why you get issues like 'Bind' will result in errors in onClick handler #6306.ReactDOM.render()
instead of just failing with a TypeError.