Description
React 18 is now available as preview alpha releases (per https://reactjs.org/blog/2021/06/08/the-plan-for-react-18.html ).
The React team has put together a Working Group discussion forum to describe the changes in React 18 in more detail: https://github.com/reactwg/react-18/discussions
Looking at that forum, there's several issues that may be relevant to React-Redux in some way:
- Overviews:
- Behavior changes:
I'd like to have some folks start trying out React-Redux v7 with React 18 alpha, and report any interesting findings. We could potentially use some of the example apps from the Redux tutorials, and any of the example CodeSandboxes linked in our docs.
You would need to:
- Switch the React version to one of the React 18 alphas, and update the app to use
React.createRoot()
per instructions - Try out the app
- Hand-inspect the behavior to see if anything seems unexpected
We're interested in seeing examples and comparisons with both connect
and useSelector
.
It would also be worth cloning the React-Redux repo, and updating our React devDep to run our tests against the alphas.
The React team has reported that a brief test of a couple Redux-based apps combined with createRoot + StrictMode
did not appear to be working correctly - in particular, no re-rendering happening despite actions being dispatched.
It's very possible that Strict Effects running effects callbacks more than once is causing problems with subscriptions.
We'd appreciate any feedback reports!
Please provide this info:
- Details on the example app used
- Link to updated source code / CodeSandbox if possible
- Description of observed behavior, good or bad ("works okay", "clicking button X doesn't update the UI", etc)
Activity
gaearon commentedon Jun 10, 2021
Note to folks trying — if you have StrictMode on, please test both with StrictMode and without it. This is to see if some issues only occur in StrictMode. (StrictMode has gotten “stricter.”)
timdorr commentedon Jun 11, 2021
We actually have tests for StrictMode in our suite already, so it should be good to test at least the basics here.
markerikson commentedon Jun 11, 2021
Okay. First issue here is that there's this new "Strict Effects" thing which is enabled if you're using
createRoot()
+<StrictMode>
, which double-runs the effects in the same way that<StrictMode>
has traditionally double-run renders. I could easily see that messing up subscriptions.So, we'd need to figure out how to do a React 18 upgrade for our tests, which I assume would mean something with React Testing Library since that's doing the rendering?
nickserv commentedon Jun 11, 2021
If you're asking about Testing Library compatibility, you may want to subscribe to testing-library/react-testing-library#925 (proposed as an alpha).
ryota-murakami commentedon Jun 12, 2021
I have a side project that used to React-Redux v7.2.4, I'd like to try it if React 18 alpha working on CRA v4.0.3.
markerikson commentedon Jun 13, 2021
Comment from the React team on plans for helping the community do updates:
reactwg/react-18#56 (comment)
markerikson commentedon Jun 28, 2021
Mobx has a PR going that's tracking some similar status checks for React 18. Worth keeping an eye on that:
mobxjs/mobx#3005
artem-malko commentedon Aug 3, 2021
Hi @markerikson! I have something interesting for you)
I have a repository with react 18 + SSR + redux for UI state. There is an interactive demo — http://158.101.223.0:5000/
As you can see, there is a button "Patch query string". If you'll click this button, the UI state in a redux-store will be updated with new Date().toString() There is a source code. Top part of the page has a component, that has a subscription to the redux-store vis useSelector.
So, if you will open the demo with a query param strict=true, the whole app will be wrapped with component. If there is no strict query param — without it. Click to the button, that changes the query string works perfectly in strict mode and without it. But, it works in production build only.
If you will clone the repository, exec
npm i && make dev
and open http://localhost:4000?strict=true, you will see, that the UI won't be changed after the button click.Actually, I can not understand, what is the difference between develop and production build in case of redux/react-redux. May be it is because of react?
I understand, the project is quite big. But I've tried to make it easy to repeat the problem. Other stuff from that repo is not so important, as think)
gaearon commentedon Sep 13, 2021
Example of StrictMode + createRoot breaking it, per request from reactwg/react-18#19 (comment): https://codesandbox.io/s/serverless-wood-uouyy?file=/src/index.js
markerikson commentedon Sep 14, 2021
And copying over some excellent detective work from @Andarist at reactwg/react-18#19 (reply in thread) :
[-]Investigation: try React-Redux v7 with React 18 alpha[/-][+]Investigation: try React-Redux v7 / v8 with React 18 alpha[/+]serprex commentedon Apr 2, 2022
https://etg.dek.im https://github.com/serprex/openEtG works okay after updating to react-redux 8.0.0-beta.3 & react 18.0
Code doesn't use any hooks
markerikson commentedon May 22, 2022
React-Redux v8 is out, so I think we can call this done :)