question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug: too hard to fix "Cannot update a component from inside the function body of a different component."

See original GitHub issue

Note: React 16.13.1 fixed some cases where this was overfiring. If upgrading React and ReactDOM to 16.13.1 doesn’t fix the warning, read this: https://github.com/facebook/react/issues/18178#issuecomment-595846312


React version:

16.13.0

Steps To Reproduce

  1. Build a time machine.
  2. Go to the year 2017.
  3. Build a huge application of 10K lines of code.
  4. Get 80 (!) dependencies at package.json file including ones that become no longer maintained.
  5. Update React to the latest version at February 27, 2020.
  6. Get tons of errors that you don’t know how to fix.
  7. Tell your client that fixes are going to take unknown time and it’s going to cost $$$ + days or weeks of investigation or we’re going to get stuck with the outdated version of React and related libraries forever which will cost more $$$ but later.

Being serious, the business I work for isn’t interested on that at all. Obviously I’d never made it happen to get such warnings to appear if I’d get them earlier. Currently that’s impossibly hard to make the errors to be fixed because I get them at many different cases and with a huge stack trace. I tried to fix at least one of the appearing errors and it already took a lot of time. I tried to debug some of used libraries but got no luck.

Just one example:

image

There we can notice the use of an outdated react-router, an outdated redux-connect (which I had to put to the project source to fix errors of outdated componentWillReceiveProps method), some HOCs created by recompose etc. It isn’t just a simple virtual DOM tree where I can walk thru components developed by me and search by setState string to fix the bug, that’s way more complicated than that.

Please make an “UNSAFE” option to disable this error or provide a simpler way to find where the error is thrown 🙏

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:29
  • Comments:109 (43 by maintainers)

github_iconTop GitHub Comments

30reactions
gaearoncommented, Mar 6, 2020

To the future commenters. I understand seeing a new warning is frustrating. But it points out legitimate issues that are likely causing bugs in your code. We would very much appreciate if you could refrain from expressing sarcasm and annoyance.

If you can’t understand where it’s coming from in the stack traces, please post screenshots or create reproducing sandboxes and we’ll try to help. Most of these are probably coming from a few libraries, so the most productive thing to do is to reduce these cases and then file issues with those libraries.

Thank you all.

15reactions
gaearoncommented, Mar 19, 2020

We fixed the cases where the warning was over-firing in 16.13.1. The remaining cases are legit and need to be fixed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot update a component from inside the function body of a ...
If you call setState during a render on a different component, you will now see a warning: Warning: Cannot update a component from...
Read more >
How to fix the "cannot update a component while rendering a ...
A quick guide to how I solved a confusing React error.
Read more >
Cannot update a component (`MessageScreen`) while ...
To locate the bad setState() call inside Swipeable, follow the stack trace as described in Bug: too hard to fix "Canno…
Read more >
cannot update a component while rendering a ... - You.com
The problem is when one component queues an update in another component, while the first component is rendering. (Bug: too hard to fix...
Read more >
和田ベンゾウ on Twitter: "むむっ。 Bug: too hard to fix "Cannot ...
むむっ。 Bug: too hard to fix "Cannot update a component from inside the function body of a different component." · Issue #18178 ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found