-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Warn if calling setState in getChildContext #6114
Comments
We should warn if you call setState in getChildContext. |
getChildContext
I'll do it! |
Reproduced error (in the console) |
What's a good way to start on this? |
@raineroviir Find the places that |
Ok, thank you! |
Can you give me some more pointers.. I'm stuck figuring out whether Here's the warning code shown when trying to react/src/renderers/shared/reconciler/ReactUpdateQueue.js Lines 49 to 51 in 3b96650
|
getChildContext might not be the immediate caller, so that won't work. You're going to need to set some state before and after getChildContext. We already warn when users call setState in render, take a look at that code. |
should ReactCurrentOwner.current be set during a getChildContext call? Looks like it currently is not. and |
@dan-weaver No, I think we only set the owner in render. |
FYI this is being worked on in #6121. |
Fix #6114 - Calling setState inside getChildContext should warn
Hi @raineroviir I am a Ph.D. student. I am doing research about helping newcomers participate in OSS projects. I noticed that many projects are using labels such as 'good first issue/bug, difficulty/newcomer' for issues to recommend that newcomers start from these tasks. I noticed that you tried to solve this issue, but unfortunately, you had not contributed successfully. I also found there are many newcomers feel difficult when submitting their first pr. Therefore, I want to optimize this mechanism, which needs your help. I have some questions and wish your valuable feedback.
I am looking forward to hearing from you soon. Thank you very much! |
This code causes a maximum call stack:
These sort of errors are hard to track down as the stack trace is deep in react. Is this a place we can give a user an invariant to let them know what they did wrong?
The text was updated successfully, but these errors were encountered: