Global styles not applied until page refresh
When applying global styles to a custom document the styles are not applied until you refresh the page, example:
import Document, { Head, Main, NextScript } from 'next/document'
export default class MyDocument extends Document {
render () {
return (
<html>
<Head>
<meta charSet="utf-8" />
<meta name="viewport" content="initial-scale=1.0, width=device-width" />
<style jsx global>{`.welcome { color: red; }`}</style>
</Head>
<body>
<Main />
<NextScript />
</body>
</html>
)
}
};
index.js
export default () => (
<div className="welcome">Welcome to next.js!</div>
)
If you close your localhost tab, npm run dev, then open up a fresh tab you will get this:

If you refresh the page you get this:

This also happens when you serve a production build of the project.
Not exactly sure about how this happens. But you should not styles like this with the custom document. Whole purpose of the custom document should to customize your HTML page. Inside the custom layout, we don't have access to the React app.
So, try to move your styles to a common layout. See this related discussion: https://github.com/zeit/next.js/issues/873#issuecomment-275008448
@arunoda actually we've seen this before. using styled-jsx inside of <Head> is not supported. Since it won't render an element. In this case styled-jsx is obsolete since
<style>{.welcome { color: red; }}</style> will be global. Using just the <style> fixes your issue 👍
I fixed with thankyou @timneutkens but I have a question. Why it work?
This thread has been automatically locked because it has not had recent activity. Please open a new issue for related bugs and link to relevant comments in this thread.