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

Deduplicate the "Can only update a mounted or mounting component" warning #11140

Closed
gaearon opened this issue Oct 6, 2017 · 10 comments
Closed

Comments

@gaearon
Copy link
Collaborator

gaearon commented Oct 6, 2017

Note: @anushreesubramani is working on this, please don’t send PRs if you aren’t her :-)


Similar to #11081.

@anushreesubramani Wanna take this one as well? It would need to deduplicate based on owner/stack info, similar to how #11120 works.

@imanushree
Copy link

@gaearon Sure .. Would be happy to take it up !

@imanushree
Copy link

Actually @gaearon, do you want me to do a full check on all the warnings? It'll be better than raising individual issues.

@gaearon
Copy link
Collaborator Author

gaearon commented Oct 7, 2017

Yea that would be amazing. I don't think they necessarily always have to be deduped... but it might be easier to discusss specific cases where they shouldn’t, and convert the rest.

@imanushree
Copy link

So, any pointers on how I can go about identifying those specific cases that don't need to be deduped? @gaearon

@gaearon
Copy link
Collaborator Author

gaearon commented Oct 7, 2017

I don't have any clear guideline. I think the most useful one is: does the warning happen during render. If it does then it's likely it'll happen again and again and again, and spam the console. Then it should be deduped.

Whereas if the warning itself can only happen when user calls some specific API, and that API is typically called outside of render phase, it might not make sense to dedupe.

@imanushree
Copy link

I found 2 versions of the "Can only update a mounted or mounting component" warning:
First is from ReactFiberScheduler.js (which is imported by ReactFiberReconciler.js)

Warning: Can only update a mounted or mounting component. This usually means you called >setState, replaceState, or forceUpdate on an unmounted component. This is a no-op.

Please check the code for the App component.

The second one is from ReactNoopUpdateQueue.js (which is imported by ReactBaseClasses.js)

Warning: setState(...): Can only update a mounted or mounting component. This usually means you >called setState() on an unmounted component. This is a no-op.

Please check the code for the App component.

@gaearon Just have a few doubts:

  1. Is this repetition intentional? Do they serve different purposes, if so what are they?
  2. I have to dedupe the warning in ReactFiberScheduler.js alone or both?

Thanks in advance :)

@gaearon
Copy link
Collaborator Author

gaearon commented Oct 11, 2017

The one in ReactBaseClasses is likely to almost never happen. It only happens if somebody creates an instance of a React component manually, e.g. new MyComponent(props), and then tries to call setState.

Let’s dedupe both I think. This means that in the very unlikely case both fire, there will be at most two warnings rather than one. But that’s okay.

imanushree added a commit to imanushree/react that referenced this issue Oct 13, 2017
 * Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()
imanushree added a commit to imanushree/react that referenced this issue Oct 13, 2017
  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()
@imanushree
Copy link

There were totally ~120 warnings in the React codebase. I checked them all and came up with a list of ~20 warnings which were not deduped. I have fixed the ones which I felt will be duplicated during re-render(as per your suggestion) and have given the PR. I still have a list of other warnings which I am unsure if they need deduplication or not. I can share the list if you wish to take a look at it. Apologies for the delay in giving the PR. @gaearon

imanushree added a commit to imanushree/react that referenced this issue Oct 18, 2017
  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()
imanushree added a commit to imanushree/react that referenced this issue Oct 18, 2017
imanushree added a commit to imanushree/react that referenced this issue Oct 18, 2017
  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()
imanushree added a commit to imanushree/react that referenced this issue Oct 18, 2017
imanushree added a commit to imanushree/react that referenced this issue Oct 28, 2017
*  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()

* Code review changes made for facebook#11140
imanushree added a commit to imanushree/react that referenced this issue Oct 28, 2017
*  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()

* Code review changes made for facebook#11140
imanushree added a commit to imanushree/react that referenced this issue Oct 28, 2017
*  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()

* Code review changes made for facebook#11140
imanushree added a commit to imanushree/react that referenced this issue Oct 28, 2017
*  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()

* Code review changes made for facebook#11140
gaearon pushed a commit that referenced this issue Oct 31, 2017
*  Deduplicated many warnings (#11140)

*  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()

* Code review changes made for #11140

* Minor style fix

* Test deduplication for noop updates in server renderer

* Test deduplication for cWRP warning

* Test deduplication for cWM setState warning

* Test deduplication for unnmounted setState warning

* Fix existing Flow typing

* Test deduplication for invalid updates

* Test deduplication of update-in-updater warning
@gaearon
Copy link
Collaborator Author

gaearon commented Nov 3, 2017

This was fixed.

@gaearon gaearon closed this as completed Nov 3, 2017
Ethan-Arrowood pushed a commit to Ethan-Arrowood/react that referenced this issue Dec 8, 2017
*  Deduplicated many warnings (facebook#11140)

*  Deduplicated the following warnings:

1.  Can only update a mounted or mounting component.
    This usually means you called setState, replaceState,
    or forceUpdate on an unmounted component. This is a no-op

2.  %s.componentWillReceiveProps(): Assigning directly to
    this.state is deprecated (except inside a component's
    constructor). Use setState instead.'

3.  An update (setState, replaceState, or forceUpdate) was scheduled
    from inside an update function. Update functions should be pure,
    with zero side-effects. Consider using componentDidUpdate or a
    callback.

4.  setState(...): Cannot call setState() inside getChildContext()

* Code review changes made for facebook#11140

* Minor style fix

* Test deduplication for noop updates in server renderer

* Test deduplication for cWRP warning

* Test deduplication for cWM setState warning

* Test deduplication for unnmounted setState warning

* Fix existing Flow typing

* Test deduplication for invalid updates

* Test deduplication of update-in-updater warning
@lifeeric
Copy link

lifeeric commented Sep 8, 2019

I getting this Error in console, I don't know why

proxyConsole.js:56 Warning: Can only update a mounted or mounting component. This usually means you called setState, replaceState, or forceUpdate on an unmounted component. This is a no-op. Please check the code for the _class2 component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants