question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server-side rendering doesn't work

See original GitHub issue

When using SSR with ReactDOMServer.renderToString I get following exception:

    Invariant Violation: Could not find "store" in the context of "Connect(ConnectedRouterWithContext)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(ConnectedRouterWithContext) in connect options.
        at invariant (/home/user/app/node_modules/invariant/invariant.js:40:15)
        at Connect.renderWrappedComponent (/home/user/app/node_modules/react-redux/lib/components/connectAdvanced.js:162:32)
        at ReactDOMServerRenderer.render (/home/user/app/dist/node_modules/react-dom/cjs/react-dom-server.node.development.js:2494:55)
        at ReactDOMServerRenderer.read (/home/user/app/dist/node_modules/react-dom/cjs/react-dom-server.node.development.js:2357:19)
        at Object.renderToString (/home/user/app/dist/node_modules/react-dom/cjs/react-dom-server.node.development.js:2729:25)
        at renderToString (/home/user/app/dist/server/webpack:/src/server/indexServer.js:220:18)

Dependencies:

    "connected-react-router": "6.0.0",
    "react": "16.7.0",
    "react-dom": "16.7.0",
    "react-redux": "6.0.0",
    "react-router-dom": "4.3.1",
    "redux": "4.0.1",

Compoents:

    <Provider store={store}>
      <ErrorCatcher>
        <ConnectedRouter history={history}>
          <Switch>
            <Route path="/recorder/" component={Recorder} />
            <Route path="/" component={Regular} />
          </Switch>
        </ConnectedRouter>
      </ErrorCatcher>
    </Provider>

Rendering client-side only works.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

3reactions
rodrigobacellicommented, Feb 27, 2019

Me too, without SSR

3reactions
kevindicecommented, Dec 21, 2018

You may want to use <StaticRouter> on the server side. Here’s an example from a repo that adds SSR to a non-ejected CRA starter app. https://github.com/cereallarceny/cra-ssr/blob/master/server/loader.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server-side rendering not working on production in Next.js ...
When using server-side rendering with next@12.1.6, the context doesn't get passed down to the children component.
Read more >
Server-side rendering not working on production Next.js
If I understand it correctly, my code is located at the main home page at pages/index.tsx. Does this page not support getServerSideProps ?...
Read more >
Why doesn't React.useEffect run on React server-side renders ...
The conclusion that React. useEffect doesn't run during a server-side render (SSR) is left to the reader however.
Read more >
What is server-side rendering and how does it improve site ...
Server -side rendering ensures that website content appears quickly, without first having to download and run application code.
Read more >
Server-Side Rendering (SSR) - Vue.js
For example, if you are building an internal dashboard where an extra few hundred milliseconds on initial load doesn't matter that much, SSR...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found