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'
|
2018-03-06 13:27:47 +00:00
|
|
|
|
|
|
|
import FelaProvider from '../FelaProvider'
|
|
|
|
import getFelaRenderer from '../getFelaRenderer'
|
2017-01-23 23:29:15 +00:00
|
|
|
|
|
|
|
export default class MyDocument extends Document {
|
|
|
|
static getInitialProps ({ renderPage }) {
|
2018-03-06 13:27:47 +00:00
|
|
|
const serverRenderer = getFelaRenderer()
|
|
|
|
|
|
|
|
const page = renderPage(App => props => (
|
|
|
|
<FelaProvider renderer={serverRenderer}>
|
|
|
|
<App {...props} />
|
|
|
|
</FelaProvider>
|
|
|
|
))
|
|
|
|
|
|
|
|
const sheetList = renderToSheetList(serverRenderer)
|
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 () {
|
2018-03-06 13:27:47 +00:00
|
|
|
const styleNodes = this.props.sheetList.map(
|
|
|
|
({ type, rehydration, support, media, css }) => (
|
|
|
|
<style
|
|
|
|
dangerouslySetInnerHTML={{ __html: css }}
|
|
|
|
data-fela-rehydration={rehydration}
|
|
|
|
data-fela-support={support}
|
|
|
|
data-fela-type={type}
|
|
|
|
key={`${type}-${media}`}
|
|
|
|
media={media}
|
|
|
|
/>
|
|
|
|
)
|
2017-06-28 17:14:18 +00:00
|
|
|
)
|
2017-06-13 20:50:42 +00:00
|
|
|
|
2017-01-23 23:29:15 +00:00
|
|
|
return (
|
|
|
|
<html>
|
2018-12-17 16:34:32 +00:00
|
|
|
<Head>{styleNodes}</Head>
|
2017-01-23 23:29:15 +00:00
|
|
|
<body>
|
|
|
|
<Main />
|
|
|
|
<NextScript />
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|