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.

SSR'd React components depending on query not matching client

See original GitHub issue

When use in conjunction with SSR, it seems that when rendered on the server, the location state object doesn’t container the query. So, a mapStateToProps like:

const mapStateToProps = ({location}) => {
  return {
    tabActive:
      get(location, ['query', 'find'], null) ===
      Constants.FIRST_OPTION,
  };
};

Gets the checksum react error for server markup not matching client markup, since on the server location.query is not present, yet on the client it is. Is there a proper way to access the query string from the server side rendering pass?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
Maushundbcommented, Jul 30, 2017

Yup, doing

  const path = req.path + (isEmpty(req.query) ? '' : '?' + queryString.stringify(req.query));
  const history = createHistory({ initialEntries: [path] })

Seems to have done the trick! Cheers.

0reactions
faceyspaceycommented, Jul 30, 2017

Exactly. You have to manually recreate /path?query=foo

Look at the history API. I forget but it might also take a location object instead of a string which will be easier for you to provide without string creation.

Also log history.location after you create the history. If it has the query on it, it will work. …crossing my fingers that the history memory package works the same as the browser one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Warning: Text content did not match. Server: "I'm out" Client
This prevents the component from being included on the server, and dynamically loads it on the client-side only. const Home = dynamic( ()...
Read more >
What I learned from React-Query, and why I won't use it again
Id of the new section is saved to the store as selectedSectionId (client state); Value of selectedSectionData is derived from the siteSections ...
Read more >
Combining Server-Side Rendering and Responsive Design
In this example, the server renders all components despite the breakpoints - so that both “layout” components are part of the rendered markup....
Read more >
SSR | TanStack Query Docs
Create a new QueryClient instance inside of your app, and on an instance ref (or in React state). This ensures that data is...
Read more >
Server-side rendering - Apollo GraphQL Docs
This prevents Apollo Client from refetching queries unnecessarily, ... your React tree directly to a string (instead of the component-based example below), ...
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