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 needs a default width to render the same as the client

See original GitHub issue

Describe the bug When using SSR the returned html is different than the one generated by the client, That’s because of the conditional rendering like display={{md: "none", sm: "block"}} Is there a way to define the default width when one is not set? For example material-ui has an initialWidth that you can set on your theme, so the content that comes from the server is the same, in most cases.

 initialWidth: isMobile ? "sm" : "lg" // Breakpoint being globally set 🌎!

To know if it is mobile or a presumeably bigger monitor you can check the agent that is sent to the server. Actually it seems it is using mediaqueries for that, which is good, but then why does it generates 2 different classes? I will investigate more

Expected Behavior Code sent to the client from SSR should be the same as the one generated in the client.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
DevAliencommented, Apr 16, 2020

Basically the extractCritical was the solution.

import { renderToString } from 'react-dom/server'
import { extractCritical } from 'emotion-server'
import App from './App'

const { html, ids, css } = extractCritical(renderToString(<App />))

an example on next.js => https://github.com/zeit/next.js/blob/master/examples/with-emotion/pages/_document.js

And the emotion documentation => https://emotion.sh/docs/ssr#extractcritical

1reaction
DevAliencommented, Apr 16, 2020

Installing emotion and emotion-server and setting it up solved the issue.

https://emotion.sh/docs/ssr

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is server-side rendering and how does it improve site ...
Server-side rendering (SSR) addresses the performance and search engine optimization issues of single-page JavaScript applications.
Read more >
Client Side Rendering vs. Server Side Rendering vs. Static ...
The three approaches include Client Side Rendering (CSR), Server Side Rendering (SSR) and Static Site Generation (Pre-rendering).
Read more >
Combining Server-Side Rendering and Responsive Design
Let's explain the challenge that comes up when mixing SSR and responsive design, and introduce a couple of possible strategies to approach ...
Read more >
Screen width with SSR? - reactjs - Stack Overflow
I use NextJS and I need to get screen width on server side, because I have case when I need render one component...
Read more >
The Benefits of Server Side Rendering Over Client ... - Medium
Due to the benefits of SSR, when we transformed our stack to React ... React will need to be downloaded and go through...
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