import theme from "@/core/utils/theme"; import createEmotionServer from "@emotion/server/create-instance"; import Document, { Head, Html, Main, NextScript } from "next/document"; import { createEmotionCacheLtr, createEmotionCacheRtl } from "@witel/webapp-builder"; import languageList from "@/core/data/languageList"; export default function MyDocument(props) { const { emotionStyleTags } = props; return ( {emotionStyleTags}
); } MyDocument.getInitialProps = async (ctx) => { const originalRenderPage = ctx.renderPage; let cache; for (const lang of languageList) { if (ctx.locale !== lang.key) continue; if (lang.dir === "rtl") { cache = createEmotionCacheRtl(); } else { cache = createEmotionCacheLtr(); } } 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) => (