Closed matthooks closed 5 years ago
It's not pretty but I got it working like this https://gist.github.com/vikfroberg/23afed1bfd84fd280645401f1215f4f9
@vikfroberg Feel free to send a pull request
I'll send a pull request when someone approves this solution.
@vikfroberg Confirmed this is working for me as expected. Thanks for digging into this. I'm happy to help you with the PR!
One note -- I needed to change sheet.media
to sheet.attrs.media
on this line to get the media queries to work correctly.
It seems to be broken with version 6.1.2. I'm getting a flash of unstyled content when loading a page for the first time. Can anyone get Styletron to server side render using next.js example setup with versions below?
{
"next": "^6.1.2",
"react": "^16.5.0",
"react-dom": "^16.5.0",
"styletron-engine-atomic": "^1.0.8",
"styletron-react": "^4.3.5"
}
Going to close this as the issue is stale.
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)
yarn create next-app --example with-styletron with-styletron-app
styletron-client
andstyletron-server
from package.json, addstyletron
at^3.0.0
and updatestyletron-react
to^3.0.0
const Styletron = require('styletron-client').default
.<style>
tag that should be re-hydrated is empty.<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