import type { DocumentContext, DocumentInitialProps } from "next/document"; import NextDocument, { Head, Html, Main, NextScript } from "next/document"; import { ServerStyleSheet } from "styled-components"; import { DEFAULT_LOCALE } from "utils/constants"; const withStyledComponents = async ( ctx: DocumentContext ): Promise => { const { renderPage } = ctx; const sheet = new ServerStyleSheet(); try { ctx.renderPage = () => renderPage({ enhanceApp: (App) => (props) => sheet.collectStyles(), }); const { styles, ...initialProps } = await NextDocument.getInitialProps(ctx); return { ...initialProps, styles: [styles, sheet.getStyleElement()], }; } finally { sheet.seal(); } }; class Document extends NextDocument { public static async getInitialProps( ctx: DocumentContext ): Promise { return withStyledComponents(ctx); } public render(): JSX.Element { return (
); } } export default Document;