2017-01-03 18:06:04 +00:00
|
|
|
import Document, { Head, Main, NextScript } from 'next/document'
|
|
|
|
import { StyleSheetServer } from 'aphrodite'
|
|
|
|
|
|
|
|
export default class MyDocument extends Document {
|
|
|
|
static async getInitialProps ({ renderPage }) {
|
|
|
|
const { html, css } = StyleSheetServer.renderStatic(() => renderPage())
|
2017-05-09 22:33:39 +00:00
|
|
|
const ids = css.renderedClassNames
|
|
|
|
return { ...html, css, ids }
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor (props) {
|
|
|
|
super(props)
|
|
|
|
/* Take the renderedClassNames from aphrodite (as generated
|
|
|
|
in getInitialProps) and assign them to __NEXT_DATA__ so that they
|
|
|
|
are accessible to the client for rehydration. */
|
|
|
|
const { __NEXT_DATA__, ids } = props
|
|
|
|
if (ids) {
|
|
|
|
__NEXT_DATA__.ids = this.props.ids
|
|
|
|
}
|
2017-01-03 18:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-05-09 22:33:39 +00:00
|
|
|
/* Make sure to use data-aphrodite attribute in the style tag here
|
|
|
|
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 */
|
2017-01-03 18:06:04 +00:00
|
|
|
return (
|
|
|
|
<html>
|
|
|
|
<Head>
|
2017-05-09 22:33:39 +00:00
|
|
|
<style data-aphrodite dangerouslySetInnerHTML={{ __html: this.props.css.content }} />
|
2017-01-03 18:06:04 +00:00
|
|
|
</Head>
|
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|