import type { EmotionJSX } from '@emotion/react/types/jsx-namespace'; import createEmotionServer from '@emotion/server/create-instance'; import type { DocumentContext } from 'next/document'; import Document, { Head, Html, Main, NextScript } from 'next/document'; import * as React from 'react'; import createEmotionCache from '../utils/create-emotion-cache'; export default class AppDocument extends Document<{ emotionStyleTags: EmotionJSX.Element[]; }> { static getInitialProps = async (ctx: DocumentContext) => { const originalRenderPage = ctx.renderPage; const cache = createEmotionCache(); const { extractCriticalToChunks } = createEmotionServer(cache); ctx.renderPage = () => originalRenderPage({ enhanceApp: (App: any) => function EnhanceApp(props) { return ; }, }); const initialProps = await Document.getInitialProps(ctx); const emotionStyles = extractCriticalToChunks(initialProps.html); const emotionStyleTags = emotionStyles.styles.map(style => (