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.

Next 5.0+ and Styletron server-side rendering is broken

See original GitHub issue
  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

I’m trying to upgrade from Next 4.2.3 to 5.1. I have styletron set up as per the example provided here with a few tweaks to make it work for version 3 of styletron. When using Next 5.1, the server side rendering isn’t rendering the styles correctly. Client-side rehydration is still happening. This is causing a flash of unstyled content when loading a page for the first time.

Current Behavior

In the example, the styletron object is loaded in the getInitialProps function of a custom Document. In 4.2.3, this object is there, but for some reason it’s undefined/null in 5.1+.

See here: https://github.com/zeit/next.js/blob/canary/examples/with-styletron/pages/_document.js#L7

Steps to Reproduce (for bugs)

  1. yarn create next-app --example with-styletron with-styletron-app
  2. Remove styletron-client and styletron-server from package.json, add styletron at ^3.0.0 and update styletron-react to ^3.0.0
  3. Change line 11 in styletron.js to const Styletron = require('styletron-client').default.
  4. Run the development server, experience the flash of unstyled content. Also observe that the <style> tag that should be re-hydrated is empty.
  5. Try it on 4.2.3. No flash of unstyled content. The rehydrated <style> tag is not empty.

In 5.1.0, the styletron object on this line is undefined/null when server side rendering happens.

Context

Just trying to upgrade to 5+ to take advantage of the improvements! I’d be more than happy to update the styletron example to the latest version of styletron if we can get this working.

Your Environment

Tech Version
next 5.1.0
node 8.1.3
OS Mac
browser Chrome

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
matthookscommented, May 23, 2018

One note – I needed to change sheet.media to sheet.attrs.media on this line to get the media queries to work correctly.

0reactions
timneutkenscommented, Dec 31, 2018

Going to close this as the issue is stale.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next 5.0+ and Styletron server-side rendering is broken #4216
When using Next 5.1, the server side rendering isn't rendering the styles correctly. Client-side rehydration is still happening. This is causing ...
Read more >
Getting Started - Styletron
Styletron also supports server-side rendering so you can generate the styles on the server and then "hydrate" the client. This can significantly improve...
Read more >
Not working Server side rendering Styled-Components with ...
Not working Server side rendering Styled-Components with Next JS · Can't see anything wrong with your styled-components setup. The error seems to ...
Read more >
styled components not working in prod nextjs - You.com
What we actually have to do is inject server-side rendered styles to the head so it can render the page and its styles...
Read more >
next - npm
Data returned from getInitialProps is serialized when server rendering, similar to a JSON.stringify . Make sure the returned object from getInitialProps is a ......
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