You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This beta release makes several fixes to the TypeScript types for v8, fixes several dev dependencies that were accidentally listed as dependencies, and adds initial React 18 SSR support.
Changelog
TypeScript Fixes
The initial TS conversion effort ported a chunk of the typetests from the React-Redux v7 types in DefinitelyTyped. We've ported over the remainder of the typetests, which uncovered a few bugs and missing types (such as the useStore hook not being generic).
Those issues are now fixed, and after some additional tweaks all of the typetests are now passing. This means that existing TS usage of React-Redux v7 should be able to work entirely as-is with v8.
React 18 SSR Support
The new React 18 useSyncExternalStore hook accepts a function to supply the current state when called, which is normally the Redux store.getState method. However, a mutable store like Redux could change before or during an initial hydration render (such as a manual store.dispatch() before calling hydrateRoot(), or React components dispatching actions during the mount process). To avoid that, useSyncExternalStore also requires that you provide a getServerSnapshot function that can return a consistent single state value. uSES will use that all the way through the initial hydration render, and then check to see if any further updates are needed based on the latest state after the hydration render is complete.
The Provider component now accepts an optional serverState prop. If you're doing SSR, serialize your Redux store state on the server and pass that in to Provider as <Provider store={store} serverState={window.initialServerState}>, similar to how you would initialize a Redux store with that value.
We've updated both useSelector and connect to use the serverState value if it exists and pass that to useSyncExternalStore. This has been only briefly tested so far, but it appears to correctly eliminate hydration mismatch warnings.
We would really like more users to try this out and give us feedback!
Dependency Updates
React-Redux now expects React 18 RC as a peer dep.
Several test libraries were accidentally added as dependencies in the previous betas, so they would get installed in user projects as well. Those have been moved back to devDependencies as intended.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
This beta release makes several fixes to the TypeScript types for v8, fixes several dev dependencies that were accidentally listed as
dependencies, and adds initial React 18 SSR support.Changelog
TypeScript Fixes
The initial TS conversion effort ported a chunk of the typetests from the React-Redux v7 types in DefinitelyTyped. We've ported over the remainder of the typetests, which uncovered a few bugs and missing types (such as the
useStorehook not being generic).Those issues are now fixed, and after some additional tweaks all of the typetests are now passing. This means that existing TS usage of React-Redux v7 should be able to work entirely as-is with v8.
React 18 SSR Support
The new React 18
useSyncExternalStorehook accepts a function to supply the current state when called, which is normally the Reduxstore.getStatemethod. However, a mutable store like Redux could change before or during an initial hydration render (such as a manualstore.dispatch()before callinghydrateRoot(), or React components dispatching actions during the mount process). To avoid that,useSyncExternalStorealso requires that you provide agetServerSnapshotfunction that can return a consistent single state value.uSESwill use that all the way through the initial hydration render, and then check to see if any further updates are needed based on the latest state after the hydration render is complete.The
Providercomponent now accepts an optionalserverStateprop. If you're doing SSR, serialize your Redux store state on the server and pass that in toProvideras<Provider store={store} serverState={window.initialServerState}>, similar to how you would initialize a Redux store with that value.We've updated both
useSelectorandconnectto use theserverStatevalue if it exists and pass that touseSyncExternalStore. This has been only briefly tested so far, but it appears to correctly eliminate hydration mismatch warnings.We would really like more users to try this out and give us feedback!
Dependency Updates
React-Redux now expects React 18 RC as a peer dep.
Several test libraries were accidentally added as
dependenciesin the previous betas, so they would get installed in user projects as well. Those have been moved back todevDependenciesas intended.What's Changed
Full Changelog: v8.0.0-beta.1...v8.0.0-beta.2
This discussion was created from the release v8.0.0-beta.2.
BetaWas this translation helpful?Give feedback.
All reactions