New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Redux store not found in context #84

Closed
cdoublev opened this Issue Dec 12, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@cdoublev
Copy link

cdoublev commented Dec 12, 2018

Hello,

I have an issue with the latest version of react-redux (v6.0.0) by using this package for SSRing in development. One of its maintainers suggested that the issue is coming from how this package is requiring the serverRender chunk, ie. via require-from-string I presume. In my previous research, I already saw that the context was server side rendered as empty.

As I saw that you also have a React/Redux boilerplate repository, do you have any thoughts on this?

@richardscarrott

This comment has been minimized.

Copy link
Member

richardscarrott commented Dec 13, 2018

@cdoublev looks like React is behaving differently when bundled with Webpack target 'node' vs running directly in Node -- if you add 'react' to your externals 'keep' array in your Webpack config it fixes it.

Pretty certain it's unrelated to require-from-string as last time I looked that works exactly the same way as require but without the restriction of reading from disk...

@richardscarrott

This comment has been minimized.

Copy link
Member

richardscarrott commented Dec 13, 2018

I've got a hunch it's something to do with multiple instances of React and context -- although I'd have thought marking it as external would ensure there is just a single instance.

@cdoublev

This comment has been minimized.

Copy link

cdoublev commented Dec 14, 2018

Thank you for the feed back. It led me to the right place, I think.

The logic below for Context differs depending on PROD or DEV mode. In DEV mode, we create a separate object for Context.Consumer that acts like a proxy to Context. This proxy object adds unnecessary code in PROD so we use the old behaviour (Context.Consumer references Context) to reduce size and overhead. The separate object references context via a property called "_context", which also gives us the ability to check in DEV mode if this property exists or not and warn if it does not.

I'm still wrapping my head for what it entirely means, but in the meantime, using React directly from NodeJS is a working and totally acceptable solution. Thank you a lot!

Edit: ok, this is what you actually mean by "React is behaving differently when bundled with Webpack target 'node'", ie. the PROD package is used even if we run NODE_ENV=development node server/index.js.

@cdoublev cdoublev closed this Dec 14, 2018

@cdoublev

This comment has been minimized.

Copy link

cdoublev commented Dec 14, 2018

This was an error on my Webpack config. I had mode: 'production' set for the server build, which was setting NODE_ENV to production. Thank you again! :)

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