Skip to content

fix: respect falsy server snapshots and production context overrides - #2389

Merged
markerikson merged 7 commits into
reduxjs:masterfrom
OskarEichler:codex/provider-state-selection
Sep 30, 2026
Merged

markerikson merged 7 commits into
reduxjs:masterfrom
OskarEichler:codex/provider-state-selection

Conversation

@OskarEichler

Copy link
Copy Markdown

Fixes

  • Honor Provider serverState={0}, false, '', and null instead of silently using the client store's state during server rendering and hydration.
  • Honor a connected component's context prop in production. Currently the context assignment is inside the development-only validation block: production either throws when only a custom provider exists or silently selects the default provider's store when both providers exist.

Implementation

Use an explicit undefined check for the optional server snapshot, and move the custom-context assignment outside the development validation guard. The validation itself remains development-only. The diff changes three lines across two files; subscription and selector logic are unchanged.

Verification

  • Existing upstream suite: 186 tests across 20 files, with no type errors.
  • ESLint, standalone type tests, full package build matrix, targeted Prettier, and git diff --check pass.
  • Inline checks against built development and production packages: 38 scenarios covering hooks and connect, falsy/truthy/omitted snapshots, hydration without recoverable errors, post-hydration store updates, custom-only and nested providers, and changing the context prop on a mounted component.
  • Before the change, all four falsy snapshots used client state; production custom-only context threw and nested contexts read the wrong store.
  • No test files were added or modified. React Doctor flags the existing useSyncExternalStore call inside try/catch; this patch does not alter that error-handling path. Full CI OS/React-version matrices and device tests were not run locally.

Compatibility / breaking changes

No public API, types, dependencies, or supported-platform changes. Explicit falsy server snapshots now take effect as documented; production context overrides now match development behavior. Apps relying on either previous bug will see the corrected state selection. Omitted/undefined snapshots still fall back to store.getState.

@timdorr

timdorr commented Aug 27, 2026

Copy link
Copy Markdown
Member

Can you add some tests to both verify the behavior and ensure this doesn't regress in the future?

@pkg-pr-new

pkg-pr-new Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/react-redux@1cb1906 -D
yarn add https://pkg.pr.new/react-redux@1cb1906.tgz -D
pnpm add https://pkg.pr.new/react-redux@1cb1906.tgz -D
bun add https://pkg.pr.new/react-redux@1cb1906.tgz -D

commit: 1cb1906

@aryaemami59 aryaemami59 added the Needs Tests Tests must be added or updated before this can be completed. label Aug 28, 2026
Comment thread test/components/connect.spec.tsx Outdated
Comment thread test/integration/ssr.spec.tsx Outdated
@OskarEichler

Copy link
Copy Markdown
Author

Applied both suggestions: the production-mode context test and falsy serverState test now use Vitest it.for parameterization. The current check suite is green.

@markerikson
markerikson merged commit b591c94 into reduxjs:master Sep 30, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Tests Tests must be added or updated before this can be completed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants