From 2d2e4ab17975f34ec3045b75cc387dea3152ecc9 Mon Sep 17 00:00:00 2001 From: Amirhossein Mahmoodi Date: Wed, 31 Jul 2024 11:09:30 +0330 Subject: [PATCH] fixed bug cache mui --- src/core/utils/cacheRtl.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/core/utils/cacheRtl.js b/src/core/utils/cacheRtl.js index 1393e2e..80ac1c4 100644 --- a/src/core/utils/cacheRtl.js +++ b/src/core/utils/cacheRtl.js @@ -4,13 +4,25 @@ import { prefixer } from "stylis"; import stylisRTLPlugin from "stylis-plugin-rtl"; import { CacheProvider } from "@emotion/react"; -const cache = createCache({ - key: "mui-rtl", - stylisPlugins: [prefixer, stylisRTLPlugin], -}); +const isBrowser = typeof document !== 'undefined'; + +const createEmotionCache = () => { + let insertionPoint; + + if (isBrowser) { + const emotionInsertionPoint = document.querySelector('meta[name="emotion-insertion-point"]'); + insertionPoint = emotionInsertionPoint ?? undefined; + } + + return createCache({ + insertionPoint, + key: "mui-rtl", + stylisPlugins: [prefixer, stylisRTLPlugin], + });; +}; const cacheProviderRtl = (props) => { - return {props.children}; + return {props.children}; }; export default cacheProviderRtl;