-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[material-ui-nextjs] Fix build size (#40436)
- Loading branch information
1 parent
f59569c
commit 5518265
Showing
4 changed files
with
40 additions
and
34 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
packages/mui-material-nextjs/src/v13-pagesRouter/createCache.ts
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 |
---|---|---|
@@ -0,0 +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() { | ||
let insertionPoint; | ||
|
||
if (isBrowser) { | ||
const emotionInsertionPoint = document.querySelector<HTMLMetaElement>( | ||
'meta[name="emotion-insertion-point"]', | ||
); | ||
insertionPoint = emotionInsertionPoint ?? undefined; | ||
} | ||
|
||
return createCache({ key: 'mui', 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 +1,2 @@ | ||
export * from './pagesRouterV13'; | ||
export * from './pagesRouterV13Document'; | ||
export * from './pagesRouterV13App'; |
16 changes: 16 additions & 0 deletions
16
packages/mui-material-nextjs/src/v13-pagesRouter/pagesRouterV13App.tsx
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as React from 'react'; | ||
import { CacheProvider, EmotionCache } from '@emotion/react'; | ||
import createEmotionCache from './createCache'; | ||
|
||
export interface EmotionCacheProviderProps { | ||
emotionCache?: EmotionCache; | ||
} | ||
|
||
const defaultEmotionCache = createEmotionCache(); | ||
|
||
export function AppCacheProvider({ | ||
emotionCache = defaultEmotionCache, | ||
children, | ||
}: React.PropsWithChildren<EmotionCacheProviderProps>) { | ||
return <CacheProvider value={emotionCache}>{children}</CacheProvider>; | ||
} |
36 changes: 3 additions & 33 deletions
36
...js/src/v13-pagesRouter/pagesRouterV13.tsx → ...13-pagesRouter/pagesRouterV13Document.tsx
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