2022-04-27 14:43:06 +02:00
|
|
|
import Document, { DocumentContext, DocumentInitialProps } 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 {
|
2022-04-27 14:43:06 +02:00
|
|
|
static async getInitialProps(
|
|
|
|
ctx: DocumentContext
|
|
|
|
): Promise<DocumentInitialProps> {
|
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({
|
2020-05-18 21:24:37 +02:00
|
|
|
enhanceApp: (App) => (props) =>
|
|
|
|
sheet.collectStyles(<App {...props} />),
|
2019-01-24 10:16:47 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const initialProps = await Document.getInitialProps(ctx)
|
|
|
|
return {
|
|
|
|
...initialProps,
|
2022-04-27 14:43:06 +02:00
|
|
|
styles: [
|
2019-03-27 21:12:45 +01:00
|
|
|
<>
|
|
|
|
{initialProps.styles}
|
|
|
|
{sheet.getStyleElement()}
|
2022-04-27 14:43:06 +02: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
|
|
|
}
|