-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[examples] Change createEmotionCache to use
insertionPoint
(#32104)
- Loading branch information
1 parent
8f89246
commit 1270c0b
Showing
6 changed files
with
42 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import createCache from '@emotion/cache'; | ||
|
||
// prepend: true moves MUI styles to the top of the <head> so they're loaded first. | ||
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; | ||
|
||
if (isBrowser) { | ||
const emotionInsertionPoint = document.querySelector<HTMLMetaElement>( | ||
'meta[name="emotion-insertion-point"]', | ||
); | ||
insertionPoint = emotionInsertionPoint ?? undefined; | ||
} | ||
|
||
return createCache({ key: 'mui-style', insertionPoint }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import createCache from '@emotion/cache'; | ||
|
||
// prepend: true moves MUI styles to the top of the <head> so they're loaded first. | ||
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; | ||
|
||
if (isBrowser) { | ||
const emotionInsertionPoint = document.querySelector('meta[name="emotion-insertion-point"]'); | ||
insertionPoint = emotionInsertionPoint ?? undefined; | ||
} | ||
|
||
return createCache({ key: 'mui-style', insertionPoint }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import createCache from '@emotion/cache'; | ||
|
||
// prepend: true moves MUI styles to the top of the <head> so they're loaded first. | ||
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; | ||
|
||
if (isBrowser) { | ||
const emotionInsertionPoint = document.querySelector('meta[name="emotion-insertion-point"]'); | ||
insertionPoint = emotionInsertionPoint ?? undefined; | ||
} | ||
|
||
return createCache({ key: 'mui-style', insertionPoint }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters