-
Notifications
You must be signed in to change notification settings - Fork 26.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
styled-jsx does not render server side with custom _document.js #2593
Comments
I moved everything from _document.js into my Layout components and everything is working as expected. I did some logging inside style.js from styled-jsx and it doesn't look like it was finding any components to add to stylesMap. |
Try to use this as getInitialProps: static async getInitialProps (ctx) {
return Document.getInitialProps (ctx)
} |
The document.js signature has changed. Looks like the above now. That's why Arunoda is suggesting calling the parent 👍 |
Okay so using
does work, I have access to a styles prop. |
Hi @mattfca, @timneutkens, @arunoda And changing it to solves it. But can you please explain why? Also where can I find documentation about document.js and all its capabilities and features? Thanks! |
This is really weird... When I rewrite getInitialProps with exact same code as original Document, I can not get styles: static getInitialProps ({ renderPage }) {
const { html, head, errorHtml, chunks } = renderPage();
const styles = flush();
return { html, head, errorHtml, chunks, styles };
} When I use original |
Out of curiosity, is it necessary to call |
@pruhstal it's the way to flush all the styles into a string and make sure they're rendered server side, so yes, if you're using styled-jsx. If you're not using styled-jsx at all you don't need it. |
I am using styled-jsx throughout my app and I am getting a flicker when the server loads the initial page.
This only happens when I use a custom _document.js, so it must be something with that page.
This is the code:
Output:
The console output for props.style is always empty arrays. Should this be done in a different way? I'm unsure what to do as the docs seem to say this is all that is needed.
Your Environment
The text was updated successfully, but these errors were encountered: