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