2018-11-08 11:43:16 +00:00
|
|
|
import Document from 'next/document'
|
2017-05-07 12:25:33 +00:00
|
|
|
import { ServerStyleSheet } from 'styled-components'
|
2016-12-22 05:10:54 +00:00
|
|
|
|
|
|
|
export default class MyDocument extends Document {
|
2018-11-08 11:43:16 +00:00
|
|
|
static async getInitialProps (ctx) {
|
2017-05-07 12:25:33 +00:00
|
|
|
const sheet = new ServerStyleSheet()
|
2018-11-08 11:43:16 +00:00
|
|
|
const originalRenderPage = ctx.renderPage
|
|
|
|
|
2019-01-24 09:16:47 +00:00
|
|
|
try {
|
|
|
|
ctx.renderPage = () =>
|
|
|
|
originalRenderPage({
|
|
|
|
enhanceApp: App => props => sheet.collectStyles(<App {...props} />)
|
|
|
|
})
|
|
|
|
|
|
|
|
const initialProps = await Document.getInitialProps(ctx)
|
|
|
|
return {
|
|
|
|
...initialProps,
|
|
|
|
styles: [...initialProps.styles, ...sheet.getStyleElement()]
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
sheet.seal()
|
2018-12-17 16:34:32 +00:00
|
|
|
}
|
2016-12-22 05:10:54 +00:00
|
|
|
}
|
2018-10-20 15:00:01 +00:00
|
|
|
}
|