2020-05-31 22:20:01 +02:00
|
|
|
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
2017-06-30 22:32:33 +02:00
|
|
|
import { StyleSheetServer } from 'aphrodite'
|
|
|
|
|
2020-05-31 22:20:01 +02:00
|
|
|
class MyDocument extends Document {
|
2019-11-11 04:24:53 +01:00
|
|
|
static async getInitialProps({ renderPage }) {
|
2017-06-30 22:32:33 +02:00
|
|
|
const { html, css } = StyleSheetServer.renderStatic(() => renderPage())
|
|
|
|
const ids = css.renderedClassNames
|
|
|
|
return { ...html, css, ids }
|
|
|
|
}
|
|
|
|
|
2019-11-11 04:24:53 +01:00
|
|
|
render() {
|
2017-06-30 22:32:33 +02:00
|
|
|
/* Make sure to use data-aphrodite attribute in the style tag here
|
2020-05-31 22:20:01 +02:00
|
|
|
so that aphrodite knows which style tag it's in control of when
|
|
|
|
the client goes to render styles. If you don't you'll get a second
|
|
|
|
<style> tag */
|
|
|
|
const { css, ids } = this.props
|
2017-06-30 22:32:33 +02:00
|
|
|
return (
|
2020-05-31 22:20:01 +02:00
|
|
|
<Html>
|
2017-06-30 22:32:33 +02:00
|
|
|
<Head>
|
2018-12-17 17:34:32 +01:00
|
|
|
<style
|
|
|
|
data-aphrodite
|
2020-05-31 22:20:01 +02:00
|
|
|
dangerouslySetInnerHTML={{ __html: css.content }}
|
2018-12-17 17:34:32 +01:00
|
|
|
/>
|
2017-06-30 22:32:33 +02:00
|
|
|
</Head>
|
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
2020-05-31 22:20:01 +02:00
|
|
|
{ids && (
|
|
|
|
<script
|
|
|
|
dangerouslySetInnerHTML={{
|
|
|
|
__html: `
|
|
|
|
window.__REHYDRATE_IDS = ${JSON.stringify(ids)}
|
|
|
|
`,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2017-06-30 22:32:33 +02:00
|
|
|
</body>
|
2020-05-31 22:20:01 +02:00
|
|
|
</Html>
|
2017-06-30 22:32:33 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2020-05-31 22:20:01 +02:00
|
|
|
|
|
|
|
export default MyDocument
|