Ensure dispatch from `useFormState` works in `StrictMode`
Summary
Closes https://github.com/facebook/react/issues/28556
We didn't follow the Rules of Hooks in the rerender implementation for mounts.
Test plan
- Added test based on "useFormState updates state asynchronously and queues multiple actions" but with StrictMode and less dispatches (because it repros on the first attempt)
Comparing: bbc571aee431d44799ae6a70832ea834325a5af9...e32f38a05b1861af1be67ce223dafbf5f83e4799
Critical size changes
Includes critical production bundles, as well as any change greater than 2%:
| Name | +/- | Base | Current | +/- gzip | Base gzip | Current gzip |
|---|---|---|---|---|---|---|
| oss-stable/react-dom/cjs/react-dom.production.min.js | = | 176.83 kB | 176.84 kB | +0.02% | 54.91 kB | 54.92 kB |
| oss-experimental/react-dom/cjs/react-dom.production.min.js | = | 173.55 kB | 173.55 kB | = | 54.11 kB | 54.11 kB |
| facebook-www/ReactDOM-prod.classic.js | = | 594.04 kB | 594.07 kB | = | 104.37 kB | 104.38 kB |
| facebook-www/ReactDOM-prod.modern.js | = | 577.30 kB | 577.33 kB | = | 101.42 kB | 101.43 kB |
| test_utils/ReactAllWarnings.js | Deleted | 66.87 kB | 0.00 kB | Deleted | 16.36 kB | 0.00 kB |
Significant size changes
Includes any change greater than 0.2%:
Expand to show
| Name | +/- | Base | Current | +/- gzip | Base gzip | Current gzip |
|---|---|---|---|---|---|---|
| test_utils/ReactAllWarnings.js | Deleted | 66.87 kB | 0.00 kB | Deleted | 16.36 kB | 0.00 kB |
Generated by :no_entry_sign: dangerJS against e32f38a05b1861af1be67ce223dafbf5f83e4799
This was introduced by https://github.com/facebook/react/pull/28514. Easy oversight to make, glad we caught it quickly.
Note that it doesn't just affect StrictMode, the same issue happen if you called setState during render to trigger a re-render. Or if you suspended with use after useFormState has already been called. That last one is the most idiomatic so I'd probably write the regression test using that pattern.