forked from LaconicNetwork/icns-frontend
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import Document, {
|
|
DocumentContext,
|
|
Html,
|
|
Head,
|
|
Main,
|
|
NextScript,
|
|
} from "next/document";
|
|
import { ServerStyleSheet } from "styled-components";
|
|
|
|
class MyDocument extends Document {
|
|
static async getInitialProps(ctx: DocumentContext) {
|
|
const sheet = new ServerStyleSheet();
|
|
const originalRenderPage = ctx.renderPage;
|
|
|
|
try {
|
|
// Run the React rendering logic synchronously
|
|
ctx.renderPage = () =>
|
|
originalRenderPage({
|
|
// Useful for wrapping the whole react tree
|
|
enhanceApp: (App) => (props) =>
|
|
sheet.collectStyles(<App {...props} />),
|
|
// Useful for wrapping in a per-page basis
|
|
enhanceComponent: (Component) => Component,
|
|
});
|
|
|
|
// Run the parent `getInitialProps`, it now includes the custom `renderPage`
|
|
const initialProps = await Document.getInitialProps(ctx);
|
|
|
|
return {
|
|
...initialProps,
|
|
styles: (
|
|
<div>
|
|
{initialProps.styles}
|
|
{sheet.getStyleElement()}
|
|
</div>
|
|
),
|
|
};
|
|
} finally {
|
|
sheet.seal();
|
|
}
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<Html>
|
|
<Head>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
<link
|
|
rel="preconnect"
|
|
href="https://fonts.gstatic.com"
|
|
crossOrigin="use-credentials"
|
|
/>
|
|
<link
|
|
href="https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"
|
|
rel="stylesheet"
|
|
/>
|
|
</Head>
|
|
<body>
|
|
<Main />
|
|
<NextScript />
|
|
</body>
|
|
</Html>
|
|
);
|
|
}
|
|
}
|
|
|
|
export default MyDocument;
|