Skip to content

v8.0.0-beta.2

Pre-release
Pre-release
Compare
Choose a tag to compare
@markerikson markerikson released this 22 Dec 22:05
· 492 commits to master since this release

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!

Huge thanks to @Ephem for providing an SSR example to work with, and @acdlite for the API idea.

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.

What's Changed

  • fix: Add types to ensure that there will be no compilation errors when struct: false by @duan602728596 in #1851
  • Port remaining v7 typetests and improve v8 types by @markerikson in #1855
  • Add initial SSR support for React 18 and React-Redux v8 by @markerikson in #1835

Full Changelog: v8.0.0-beta.1...v8.0.0-beta.2