site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

React 16.13 errors with setState: setState called during render

Open tofumatt opened this issue 6 years ago • 7 comments

Bug Description

Looks like we have components (or dependencies) that are calling setState() during render. This can lead to bugs, unexpected behaviour, and is why upgrading past React 16.12 causes console errors.

The linked issue provides debugging help and context, but the issue here is that we need to find out which components are causing this error and fix it. Hopefully they are within our app and not our dependencies; if they are in the latter, we'll need to explore changing them, upgrading them, submitting a fix, or creating a fork.

Steps to reproduce

  1. Upgrade react and react-dom to 16.13.1.
  2. Visit the Site Kit dashboard
  3. Open the browser console
  4. See numerous setState errors

Screenshots

Screenshot 2020-09-10 at 17 53 50

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • After upgrading to React ^16.13.1, there should be no console errors in the browser on any page.

Implementation Brief

  • Determine the components/dependencies that are calling setState() during render and fix them.
  • For our components, this will most likely involve moving setState() calls into useEffect(() => {}) functions based on prop/datastore changes.
  • For dependencies, we'll need to install versions that don't have this bug. We should try (in this order): upgrading, submitting a fix, switching, or forking.

QA Brief

  • Follow the steps to reproduce above and note zero console errors (or at least zero errors related to setState() in render calls)

Changelog entry

tofumatt avatar Sep 10 '20 17:09 tofumatt

Note: I've set this issue as 19 estimate because it could well be quite the rabbit hole (especially if dependencies are involved) and the stack traces for these errors are tough to work with. It could take less time—hopefully it does—but because it's dealing with unknowns I want us to be able to plan for the time sink it is accordingly 😄

tofumatt avatar Sep 10 '20 17:09 tofumatt

IB ✅

felixarntz avatar Sep 10 '20 17:09 felixarntz

Just a quick comment that we're at React version 17.0.1 now, not 16.13.1

ivankruchkoff avatar Dec 06 '20 01:12 ivankruchkoff

@ivankruchkoff we need to adhere React version used by the @wordpress/element package which is 16.14.0 for the latest version of the element package.

eugene-manuilov avatar Dec 07 '20 13:12 eugene-manuilov

@tofumatt My local dev environment is using React 17.0.1 and I have been unable to recreate the errors as described above.

Hazlitte avatar Mar 10 '21 10:03 Hazlitte

I'm actually wondering if some of our recent changes to the Widget rendering has removed this issue. (It's possible that #2612 has affected this issue.)

I updated to React and ReactDOM ^16.13.1 in my package.json and saw this error:

Screenshot 2021-03-15 at 22 03 09

What does your Dashboard look like when you visit it? If you aren't rendering any content then you might not be seeing the bad setState() calls.

tofumatt avatar Mar 15 '21 22:03 tofumatt

Closing as we're on a newer version of React now 🚀

aaemnnosttv avatar Mar 02 '23 04:03 aaemnnosttv