2017-01-23 23:29:15 +00:00
|
|
|
import Document, { Head, Main, NextScript } from 'next/document'
|
2017-06-13 20:50:42 +00:00
|
|
|
import { renderToSheetList } from 'fela-dom'
|
2017-06-28 17:14:18 +00:00
|
|
|
import felaRenderer from '../fela-renderer'
|
2017-01-23 23:29:15 +00:00
|
|
|
|
|
|
|
export default class MyDocument extends Document {
|
|
|
|
static getInitialProps ({ renderPage }) {
|
|
|
|
const page = renderPage()
|
2017-06-28 17:14:18 +00:00
|
|
|
const sheetList = renderToSheetList(felaRenderer)
|
|
|
|
felaRenderer.clear()
|
2017-01-23 23:29:15 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
...page,
|
2017-06-13 20:50:42 +00:00
|
|
|
sheetList
|
2017-01-23 23:29:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2017-06-28 17:14:18 +00:00
|
|
|
const styleNodes = this.props.sheetList.map(({ type, media, css }) =>
|
|
|
|
<style
|
|
|
|
dangerouslySetInnerHTML={{ __html: css }}
|
|
|
|
data-fela-type={type}
|
|
|
|
key={`${type}-${media}`}
|
|
|
|
media={media}
|
|
|
|
/>,
|
|
|
|
)
|
2017-06-13 20:50:42 +00:00
|
|
|
|
2017-01-23 23:29:15 +00:00
|
|
|
return (
|
|
|
|
<html>
|
|
|
|
<Head>
|
|
|
|
<title>My page</title>
|
2017-06-13 20:50:42 +00:00
|
|
|
{styleNodes}
|
2017-01-23 23:29:15 +00:00
|
|
|
</Head>
|
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|