Skip to content

Commit

Permalink
fix: emotion cache (#298)
Browse files Browse the repository at this point in the history
* fix: enable emotion cache

* fix: update favicon to use new boxed logo as svg
  • Loading branch information
spaenleh authored Jul 21, 2023
1 parent 85160d5 commit c1acf01
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ if (SENTRY_DSN) {
});
}

// Client-side cache, shared for the whole session of the user in the browser.
const clientSideEmotionCache = createEmotionCache();

export interface MyAppProps extends AppProps {
emotionCache?: EmotionCache;
}
Expand Down
3 changes: 2 additions & 1 deletion pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const GraaspLibraryDocument = ({ emotionStyleTags }: MyDocumentProps) => {
return (
<Html lang={DEFAULT_LANG}>
<Head>
<link rel="icon" type="image/svg+xml" href="/graasp.svg" />
<meta name="theme-color" />
<link rel="stylesheet" />
{emotionStyleTags}
Expand Down Expand Up @@ -71,7 +72,7 @@ GraaspLibraryDocument.getInitialProps = async (ctx: DocumentContext) => {
) =>
function EnhanceApp(props) {
// eslint-disable-next-line react/jsx-props-no-spreading
return <App {...props} />;
return <App emotionCache={cache} {...props} />;
},
});

Expand Down
50 changes: 50 additions & 0 deletions public/graasp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 15 additions & 1 deletion src/config/createEmotionCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
import createCache from '@emotion/cache';

const isBrowser = typeof document !== 'undefined';

// On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
// This assures that MUI styles are loaded first.
// It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
export default function createEmotionCache() {
return createCache({ key: 'css', prepend: true });
let insertionPoint: HTMLElement | undefined;

if (isBrowser) {
const emotionInsertionPoint: HTMLElement | null = document.querySelector(
'meta[name="emotion-insertion-point"]',
);
insertionPoint = emotionInsertionPoint ?? undefined;
}

return createCache({ key: 'mui-style', insertionPoint });
}

0 comments on commit c1acf01

Please sign in to comment.