createEmotionCache.ts 710 B

12345678910111213141516171819
  1. import createCache from "@emotion/cache";
  2. const isBrowser = typeof document !== "undefined";
  3. // On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
  4. // This assures that MUI styles are loaded first.
  5. // It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
  6. export default function createEmotionCache() {
  7. let insertionPoint;
  8. if (isBrowser) {
  9. const emotionInsertionPoint = document.querySelector<HTMLMetaElement>(
  10. 'meta[name="emotion-insertion-point"]',
  11. );
  12. insertionPoint = emotionInsertionPoint ?? undefined;
  13. }
  14. return createCache({ key: "mui-style", insertionPoint });
  15. }