React 16.13 errors with setState: setState called during render
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
- Upgrade
reactandreact-domto16.13.1. - Visit the Site Kit dashboard
- Open the browser console
- See numerous
setStateerrors
Screenshots
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 intouseEffect(() => {})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
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 😄
IB ✅
Just a quick comment that we're at React version 17.0.1 now, not 16.13.1
@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.
@tofumatt My local dev environment is using React 17.0.1 and I have been unable to recreate the errors as described above.
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:
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.
Closing as we're on a newer version of React now 🚀