2017-06-29 05:44:48 +00:00
|
|
|
import Document, { Head, Main, NextScript } from 'next/document'
|
2017-08-24 06:27:49 +00:00
|
|
|
import { extractCritical } from 'emotion-server'
|
2017-07-15 07:32:14 +00:00
|
|
|
import { flush } from 'emotion'
|
|
|
|
|
|
|
|
const dev = process.env.NODE_ENV !== 'production'
|
2017-06-29 05:44:48 +00:00
|
|
|
|
|
|
|
export default class MyDocument extends Document {
|
|
|
|
static getInitialProps ({ renderPage }) {
|
2017-07-15 07:32:14 +00:00
|
|
|
if (dev) { flush() }
|
2017-06-29 05:44:48 +00:00
|
|
|
const page = renderPage()
|
2017-07-06 05:44:46 +00:00
|
|
|
const styles = extractCritical(page.html)
|
2017-06-29 05:44:48 +00:00
|
|
|
return { ...page, ...styles }
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor (props) {
|
|
|
|
super(props)
|
|
|
|
const { __NEXT_DATA__, ids } = props
|
|
|
|
if (ids) {
|
2017-08-09 15:26:45 +00:00
|
|
|
__NEXT_DATA__.ids = ids
|
2017-06-29 05:44:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<html>
|
|
|
|
<Head>
|
|
|
|
<title>With Emotion</title>
|
|
|
|
<style dangerouslySetInnerHTML={{ __html: this.props.css }} />
|
|
|
|
</Head>
|
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|