react-redux icon indicating copy to clipboard operation
react-redux copied to clipboard

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

Open markerikson opened this issue 1 year ago • 7 comments

  • Ref: https://github.com/reduxjs/redux-toolkit/issues/3842 and many others

I wonder if we could somehow do a debug check inside of <Provider> , check for the existence of useIsomorphicLayoutEffect, and throw a more informative error if it doesn't exist?

I know we added the "react-server" condition in v9 beta - not sure how these play together

markerikson avatar Nov 11 '23 04:11 markerikson

image

v9 already handles this.

phryneas avatar Nov 11 '23 10:11 phryneas

Still worth doing something for v8, especially since it doesn't have the "react-server" condition available?

markerikson avatar Nov 12 '23 22:11 markerikson

Totally up to you 😊

phryneas avatar Nov 13 '23 07:11 phryneas

How about adding use client on the top of <Provider /> file?

ryota-murakami avatar Nov 13 '23 16:11 ryota-murakami

@ryota-murakami the props Provider needs (store, context) aren't serializeable, so it would still need to be called from a client component as far as i know

EskiMojo14 avatar Nov 13 '23 16:11 EskiMojo14

@EskiMojo14 I think that's right too. I just felt that if I had explicitly stated Client Compoment, Next would have given a friendly error message. My memory is a bit fuzzy around here, sorry.

ryota-murakami avatar Nov 13 '23 17:11 ryota-murakami

@ryota-murakami no worries - my suspicion is that with the "use client" pragma added, it would throw an error message relating to store.dispatch not being serializeable instead of hooks not existing

neither is ideal which is why it'd be good to have an explicit check so we can control the error message

EskiMojo14 avatar Nov 13 '23 17:11 EskiMojo14