import {createEmotionCacheRtl} from "@/core/utils/createEmotionCache"; import theme from "@/core/utils/theme"; import createEmotionServer from "@emotion/server/create-instance"; import Document, {Head, Html, Main, NextScript} from "next/document"; export default function MyDocument(props) { const {emotionStyleTags} = props; return ( {emotionStyleTags}
); } MyDocument.getInitialProps = async (ctx) => { const originalRenderPage = ctx.renderPage; let cache; switch (ctx.locale) { case "fa": cache = createEmotionCacheRtl(); break; } const {extractCriticalToChunks} = createEmotionServer(cache); ctx.renderPage = () => originalRenderPage({ enhanceApp: (App) => function EnhanceApp(props) { return ; }, }); const initialProps = await Document.getInitialProps(ctx); const emotionStyles = extractCriticalToChunks(initialProps.html); const emotionStyleTags = emotionStyles.styles.map((style) => (