Skip to content
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

store couldn't be found in context with renderToString #1121

Closed
cdoublev opened this issue Dec 12, 2018 · 2 comments
Closed

store couldn't be found in context with renderToString #1121

cdoublev opened this issue Dec 12, 2018 · 2 comments

Comments

@cdoublev
Copy link

Do you want to request a feature or report a bug?

A bug (imho).

What is the current behavior?

I'm not aware of a service for code demo with SSR. So I'm linking to a minimal repository to demonstrate the current behavior of a React/Redux app with SSR.

npm run start (with SSR)

Visiting http://localhost:8080 (white screen), terminal outputs this error: { Invariant Violation: Could not find "store" in the context of "Connect(Component)". [...].

npm run start:client

Normal behavior.

What is the expected behavior?

I expected react-redux to find store with SSR.

Which versions of Redux, and which browser and OS are affected by this issue? Did this work in previous versions of Redux?

    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-redux": "^6.0.0",
    "redux": "^4.0.1",

Chrome and Debian Stretch as a Vagrant guest inside Windows.

The expected behavior is still obtained with the previous versions of React Redux (5.1.1).

Additional notes

It might be related to how renderToString works. renderToStaticMarkup doesn't work either. I'm not very familiar with the logic of those functions.

I really hope it's not a usage error on my side.

@timdorr
Copy link
Member

timdorr commented Dec 12, 2018

Just looking at things, it's likely something to do with webpack-hot-server-middleware. It does weird things around the rendering function and requiring from a string value of the file's contents, not just requiring the file itself. This is likely breaking out the code into a separate VM realm, so the Context instance in the server renderer isn't the same as the client. Looks like a caveat of that package, not React Redux.

@timdorr timdorr closed this as completed Dec 12, 2018
@cdoublev
Copy link
Author

cdoublev commented Dec 12, 2018

Indeed, it's working with my production build. I will look at what's going on inside webpack-hot-server-middleware. Thank you for your help and sorry to not have thought to test it in production before creating this issue.

EDIT (solution): for people SSRing in development and struggling with this Could not find "store" in the context error, make sure that your server bundle was not built with Webpack mode: production.

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

No branches or pull requests

2 participants