2021-06-04 00:58:40 +00:00
|
|
|
import Document, { Html, Head, NextScript, Main } from 'next/document';
|
|
|
|
|
import { ServerStyleSheet } from 'styled-components';
|
|
|
|
|
|
|
|
|
|
export default class MyDocument extends Document {
|
2022-11-10 22:24:11 +00:00
|
|
|
static async getInitialProps(ctx) {
|
2021-06-04 00:58:40 +00:00
|
|
|
const sheet = new ServerStyleSheet();
|
2022-11-10 22:24:11 +00:00
|
|
|
const originalRenderPage = ctx.renderPage;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
2021-06-04 00:58:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<Html lang="en-US">
|
|
|
|
|
<Head />
|
|
|
|
|
<body>
|
|
|
|
|
<Main />
|
|
|
|
|
<NextScript />
|
|
|
|
|
</body>
|
|
|
|
|
</Html>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|