This bugfix release fixes connect type inference under TS 7, fixes several connect and Provider runtime bugs, adds dev-mode logging for errors thrown in mapStateToProps, and updates our build tooling and TypeScript support matrix.
Warning
While connect is still published and technically supported, we officially deprecated connect in 9.3.0 and strongly recommend migrating to use the hooks APIs instead.
Changelog
connect Types and TS 7
We had reports that connect sometimes inferred the wrong props when mapStateToProps or mapDispatchToProps was a factory function. The connected component's props would collapse to {}, and a required prop would show up as "missing" at the call site.
Turns out the connect overloads typed those arguments as unions of the factory form (() => (state) => props) and the plain form. TS7 changed the ordering of which union member got selected, so this broke.
As Anders suggested in microsoft/typescript-go#977, we've split those unions into separate overloads listed in order of preference, factory form first. Overload matching no longer depends on how the compiler orders a union. We then applied the same fix to the mergeProps overloads, which still failed under TS 7.
Bug Fixes
Provider now uses serverState when it's a falsy value like 0, false, or ''. Previously it checked for truthiness, so a falsy root state fell back to the client store's state during SSR and hydration. null and undefined are still treated as "no server state".
A connected component's context prop is now honored in production. The assignment that picked up the custom context sat inside the development-only validation block. In production, a component with only a custom provider would throw, and one rendered under both providers would read the default provider's store.
connect no longer overrides a ref passed as a regular prop when forwardRef isn't enabled (#2251). With React 19's ref-as-prop, the wrapper was always passing its own ref (undefined without forwardRef), which replaced the one you passed in.
An explicit dependsOnOwnProps = false on a mapStateToProps or mapDispatchToProps function is now respected. We had been ignoring it for functions declared with two parameters, even though the option exists specifically for functions whose length isn't reliable.
Rendering <Provider> in a React Server Component without "use client" now throws a clear dev-mode error that tells you what's wrong, instead of failing with "useIsomorphicLayoutEffect is not a function" (#2082). Setups that resolve the react-server export condition already got a clear error. This covers the setups that don't.
mapStateToProps Error Logging
Since v8, an error thrown in mapStateToProps during a store update has been caught in the subscription callback and then effectively swallowed. The component just kept rendering its previous props (#1942). connect now logs those errors to console.error in development, so they show up in DevTools. Production behavior is unchanged.
TypeScript Support
The internal NoInfer helper type has been replaced with TypeScript's built-in NoInfer, which was added in TS 5.4. That makes TS 5.4 the minimum version for React-Redux's types. Our CI matrix now covers TS 5.6 through 5.9, 6.0, 7.0, and next.
Build Tooling
We've moved the repo to pnpm, Oxlint, and Oxfmt, and switched the library build from tsup to tsdown. The package exports layout is unchanged, but the build output comes from a different bundler. If you see any packaging or import problems with this release, please file an issue.
What's Changed
- ci: publish preview packages via
pkg.pr.newby @aryaemami59 in #2323 - chore(deps): update
vitestto latest version by @aryaemami59 in #2317 - fix(
connect): logmapStateToPropserrors toconsole.errorin dev (#1942) by @webdevelopersrinu in #2306 - feat!: switch to native
NoInferutility type by @aryaemami59 in #2316 - fix(
connect): splitmapStateToProps/mapDispatchToPropsunions into ordered overloads (#2244) by @veksa in #2340 - Modern Tooling, Part 1: PNPM by @markerikson in #2379
- Fix TS7 errors and update TS matrix by @markerikson in #2407
- fix(
Provider): throw a clearer error when rendered in a React Server Component (#2082) by @veksa in #2342 - fix: respect falsy server snapshots and production context overrides by @OskarEichler in #2389
- Don't override ref property when not configured to. by @PSpSynedra in #2252
- fix: honour explicit
dependsOnOwnProps=falsein getDependsOnOwnProps by @JSap0914 in #2331
Full Changelog: v9.3.0...v9.3.1