Skip to content

fix(Provider): throw a clearer error when rendered in a React Server Component (#2082)#2342

Open
veksa wants to merge 1 commit into
reduxjs:masterfrom
veksa:fix/provider-rsc-dev-check
Open

fix(Provider): throw a clearer error when rendered in a React Server Component (#2082)#2342
veksa wants to merge 1 commit into
reduxjs:masterfrom
veksa:fix/provider-rsc-dev-check

Conversation

@veksa

@veksa veksa commented Jul 20, 2026

Copy link
Copy Markdown

Closes #2082.

If you render <Provider> in a Server Component you currently get a pretty useless error. In React's react-server build the effect hooks just don't exist (useEffect/useLayoutEffect/useRef/useState are all undefined — only useMemo, use, useId and friends survive), so useIsomorphicLayoutEffect ends up undefined and you hit useIsomorphicLayoutEffect is not a function. Adding "use client" doesn't really help either — as noted in the issue, store/context aren't serializable so you just trade it for a different confusing error.

So this does what the thread landed on: an explicit dev-only check at the top of <Provider>, before any hook runs, that throws a message actually telling you what's wrong and to add "use client".

The "react-server" export condition already handles the normal Next.js case, but only when the bundler applies it to react-redux too. This is the fallback for the "and many others" setups where React resolves to its server build but we don't — and since every app renders <Provider>, that's a good enough place to catch it.

On testing (which came up in the thread): we don't need a real RSC environment. The whole thing hinges on useIsomorphicLayoutEffect being undefined, so the test just mocks it to undefined and checks <Provider> throws. Without the guard you'd get ... is not a function instead, which doesn't match, so the test really is hitting the new branch.

Kept it scoped to <Provider> — the hooks would blow up in RSC too, but the Provider is the earliest thing everyone renders.

Changes:

  • src/components/Provider.tsx — the guard (dev only, stripped in prod)
  • test/components/Provider-rsc.spec.tsx — new test, separate file so the module mock doesn't leak into the other Provider tests

@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 3bc503b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a debug check to <Provider> to throw a more detailed error when used in Next

1 participant