@mui/material-nextjs 7.0.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +197 -0
  2. package/esm/nextCompatRouter.cjs +1 -0
  3. package/esm/nextCompatRouter.d.cts +2 -0
  4. package/esm/v13-appRouter/appRouterV13.js +10 -2
  5. package/esm/v13-appRouter/nextNavigation.cjs +1 -0
  6. package/esm/v13-appRouter/nextNavigation.d.cts +2 -0
  7. package/esm/v13-pagesRouter/createCache.d.ts +4 -1
  8. package/esm/v13-pagesRouter/createCache.js +19 -3
  9. package/esm/v13-pagesRouter/index.d.ts +2 -1
  10. package/esm/v13-pagesRouter/index.js +2 -1
  11. package/esm/v13-pagesRouter/pagesRouterV13App.js +8 -0
  12. package/esm/v13-pagesRouter/pagesRouterV13Document.js +15 -6
  13. package/nextCompatRouter.cjs +1 -0
  14. package/package.json +4 -12
  15. package/v13-appRouter/appRouterV13.js +11 -3
  16. package/v13-appRouter/nextNavigation.cjs +1 -0
  17. package/v13-pagesRouter/createCache.d.ts +4 -1
  18. package/v13-pagesRouter/createCache.js +19 -3
  19. package/v13-pagesRouter/index.d.ts +2 -1
  20. package/v13-pagesRouter/index.js +14 -1
  21. package/v13-pagesRouter/pagesRouterV13App.js +8 -0
  22. package/v13-pagesRouter/pagesRouterV13Document.js +15 -6
  23. package/modern/package.json +0 -1
  24. package/modern/v13-appRouter/appRouterV13.d.ts +0 -27
  25. package/modern/v13-appRouter/appRouterV13.js +0 -103
  26. package/modern/v13-appRouter/index.d.ts +0 -2
  27. package/modern/v13-appRouter/index.js +0 -2
  28. package/modern/v13-pagesRouter/createCache.d.ts +0 -1
  29. package/modern/v13-pagesRouter/createCache.js +0 -17
  30. package/modern/v13-pagesRouter/index.d.ts +0 -2
  31. package/modern/v13-pagesRouter/index.js +0 -2
  32. package/modern/v13-pagesRouter/nextDocument.cjs +0 -1
  33. package/modern/v13-pagesRouter/pagesRouterV13App.d.ts +0 -9
  34. package/modern/v13-pagesRouter/pagesRouterV13App.js +0 -14
  35. package/modern/v13-pagesRouter/pagesRouterV13Document.d.ts +0 -23
  36. package/modern/v13-pagesRouter/pagesRouterV13Document.js +0 -87
  37. package/modern/v14-appRouter/index.d.ts +0 -1
  38. package/modern/v14-appRouter/index.js +0 -1
  39. package/modern/v14-pagesRouter/index.d.ts +0 -1
  40. package/modern/v14-pagesRouter/index.js +0 -1
  41. package/modern/v15-appRouter/index.d.ts +0 -1
  42. package/modern/v15-appRouter/index.js +0 -1
  43. package/modern/v15-pagesRouter/index.d.ts +0 -1
  44. package/modern/v15-pagesRouter/index.js +0 -1
  45. package/tsconfig.build.tsbuildinfo +0 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,202 @@
1
1
  # [Versions](https://mui.com/versions/)
2
2
 
3
+ ## 7.1.0
4
+
5
+ <!-- generated comparing v7.0.2..master -->
6
+
7
+ _May 6, 2025_
8
+
9
+ A big thanks to the 21 contributors who made this release possible. Here are some highlights ✨:
10
+
11
+ - 🎉 Material UI now works with **Tailwind CSS v4**! Check out the [setup guide](https://mui.com/material-ui/integrations/tailwindcss/tailwindcss-v4/).
12
+
13
+ ### `@mui/material@7.1.0`
14
+
15
+ - [InputBase] Text cursor jumps several lines up when inserting text fragment with new line at the end (#45246) @yermartee
16
+ - [OutlinedInput] Add missing `notchedOutline` slot (#45917) @siriwatknp
17
+ - [Snackbar] Skip default `onClickAway` behavior when `defaultMuiPrevented` is provided (#45629) @sai6855
18
+ - [Avatar] Fix img slot types and add missing slots (#45483) @siriwatknp
19
+ - [Badge] Replace useSlotProps with useSlot hook (#45871) @sai6855
20
+ - [BottomNavigationAction] Add slots and slotProps (#45776) @sai6855
21
+ - [CardActionArea] Add slots and slotProps (#45866) @sai6855
22
+ - [useMediaQuery] Add warning and docs for using `useMediaQuery('print')` (#44790) @good-jinu
23
+ - Remove unnecessary clsx usages (#46084) @sai6855
24
+ - Corrected generic type definition in `SelectChangeEvent` (#45941) @SuyashShukla0007
25
+ - Fix theme object changes between renders (#45863) @siriwatknp
26
+
27
+ ### `@mui/material-nextjs@7.1.0`
28
+
29
+ - Add option to enable CSS layers for pages router (#45596) @siriwatknp
30
+ - Do not wrap `@layer` order rules in App Router (#45864) @Nayeem-XTREME
31
+
32
+ ### `@mui/system@7.1.0`
33
+
34
+ - Fix `@mui/system` types organization (#45860) @Janpot
35
+
36
+ ### `@mui/styled-engine@7.1.0`
37
+
38
+ - Infer `ownerState` from props in `styled` (#46083) @siriwatknp
39
+ - Fix style overrides variants type (#45478) @siriwatknp
40
+
41
+ ### Docs
42
+
43
+ - [Avatar] Add avatar upload demo (#45986) @Demianeen
44
+ - [Dialog] Remove deprecated props usage in demos (#45923) @sai6855
45
+ - [Menu] Update `paper` slot JSDoc default from `Paper` to `PopoverPaper` (#45722) @andreachiera
46
+ - [examples] Remove create-react-app usages (#45426) @CodeLeom
47
+ - Add `AccordionSummary` to the v5 breaking change migration (#45947) @siriwatknp
48
+ - Update CSS variable usage in migration guide for Pigment CSS (#46033) @sai6855
49
+ - Fix docs API dark mode color (#46086) @alexfauquette
50
+ - Add a guide for extending Material UI classes in Tailwind CSS (#46039) @siriwatknp
51
+ - Add `InitColorSchemeScript` docs and API (#45927) @siriwatknp
52
+ - Add Tailwind CSS v4 integration guide (#45906) @siriwatknp
53
+ - Fix 301 links to the system v6 (#45931) @oliviertassinari
54
+ - Add notification for MUI X v8 announcement (#45942) @joserodolfofreitas
55
+ - Fix som 301 redirections (ae84b35) @oliviertassinari
56
+ - Fix some 301 redirections (057384e) @oliviertassinari
57
+ - Fix logo is not centered on small screens (#45920) @crabsim
58
+ - Fix line break typo (a2a62d5) @oliviertassinari
59
+ - Fix markdown typo in templates.md (#45914) @scyzoryck
60
+ - Add Next.js App Router guide for custom classnames (#45852) @siriwatknp
61
+
62
+ ### Core
63
+
64
+ - [code-infra] Give a stable name to dev tool app (3889ded) @oliviertassinari
65
+ - [code-infra] Normalize author package in org (8135638) @oliviertassinari
66
+ - [code-infra] Correct some manually curated .d.ts files (#46054) @Janpot
67
+ - [code-infra] Align deps versions (#46048) @Janpot
68
+ - [code-infra] Fix dynamic import in imports resolver (#46046) @Janpot
69
+ - [code-infra] Eliminate `@mui/utils` deep imports (#46004) @Janpot
70
+ - [code-infra] Expand renovate.json for react types (#45935) @Janpot
71
+ - [code-infra] Make Argos upload script reusable (#45883) @Janpot
72
+ - [code-infra] Disallow redundant window prefixes for globals (#45880) @Janpot
73
+ - [code-infra] Remove type generation of modern build (#45912) @Janpot
74
+ - [code-infra] Clean up bundle size checker (#45622) @Janpot
75
+ - [code-infra] Fix `StrictMode` effects not being called twice in React 19 tests (#45812) @bernardobelchior
76
+ - [code-infra] Convert `@mui/utils` to typescript (#45671) @Janpot
77
+ - [docs-infra] Improve export into sandbox package.json (#46044) @oliviertassinari
78
+ - [docs-infra] Update feedback Node.js to v22 (#46064) @oliviertassinari
79
+ - [docs-infra] Normalize netlify.toml in org (b101d5c) @oliviertassinari
80
+ - [docs-infra] Uniformize Vale between repositories (0f79796) @oliviertassinari
81
+ - [docs-infra] Fix Vale no longer working (#46029) @oliviertassinari
82
+ - [docs-infra] Remove demo styling switch (#45926) @Janpot
83
+ - [docs-infra] StackBlitz WebContainer demos (#45924) @Janpot
84
+ - [docs-infra] Fix feedback management (#45872) @alexfauquette
85
+ - [test] Replace `playwright` with `@playwright/test` (#45998) @ZeeshanTamboli
86
+ - Fix internal version duplication (#46051) @oliviertassinari
87
+ - Avoid the need for `@mui/material/themeCssVarsAugmentation` (#46053) @Janpot
88
+ - Add security label to dependabot PRs (0a5c027) @oliviertassinari
89
+ - Remove unecessary versions (#46034) @oliviertassinari
90
+ - Remove redundant overrides resolver (#45970) @romgrk
91
+ - Fix duplicate branch reference (#45915) @oliviertassinari
92
+ - Fix outdated <link rel="shortcut icon" (#45916) @oliviertassinari
93
+ - Fix redirection chains (#45930) @oliviertassinari
94
+ - Run pnpm docs:sync-team (beee09f) @oliviertassinari
95
+ - Add `pkg.pr.new` publishing (#42984) @Aslemammad
96
+ - Remove @mui/base from the master branch (#45857) @mnajdova
97
+
98
+ All contributors of this release in alphabetical order: @alexfauquette, @andreachiera, @Aslemammad, @bernardobelchior, @CodeLeom, @crabsim, @Demianeen, @good-jinu, @Janpot, @joserodolfofreitas, @mnajdova, @Nayeem-XTREME, @oliviertassinari, @renovate[bot], @romgrk, @sai6855, @scyzoryck, @siriwatknp, @SuyashShukla0007, @yermartee, @ZeeshanTamboli
99
+
100
+ ## 7.0.2
101
+
102
+ _Apr 9, 2025_
103
+
104
+ A big thanks to the 12 contributors who made this release possible.
105
+
106
+ ### `@mui/material@7.0.2`
107
+
108
+ - [Autocomplete] Add ability to render custom single value (#45387) @ZeeshanTamboli
109
+ - [Autocomplete] Prevent shrink animation in controlled Autocomplete when initial `value` is provided (#45734) @imadx
110
+ - [AvatarGroup] Fix `spacing` prop ignoring value `0` (#45799) @Kartik-Murthy
111
+ - [Dialog] Deprecate composed classes (#45418) @sai6855
112
+
113
+ ### `@mui/material-nextjs@7.0.2`
114
+
115
+ - Fix nonce issues (#45794) @Janpot
116
+ - Add warnings to nextjs router integration (#45778) @Janpot
117
+
118
+ ### `@mui/styled-engine@7.0.2`
119
+
120
+ - Added caching to `StyledEngineProvider` to improve performance for running tests with Jest (#45846) @siriwatknp
121
+
122
+ ### Core
123
+
124
+ - [blog] Improve upvote video (0646444) @oliviertassinari
125
+ - [code-infra] Remove webpack aliases (#45841) @Janpot
126
+ - [code-infra] Remove .tsbuildinfo from build folder (#45727) @Janpot
127
+ - [code-infra] Stabilize theme viewer screenshot tests (#45768) @Janpot
128
+ - [code-infra] Remove modern bundles (#45808) @Janpot
129
+ - Update buildTypes script to optionally remove css imports (#45835) @brijeshb42
130
+ - Allow repo to be accepted as an argument for releaseTag (#45801) @brijeshb42
131
+ - Update scripts to support base-ui (#45784) @brijeshb42
132
+ - Sync scorecards.yml across codebase (4de5076) @oliviertassinari
133
+ - Remove baseUrl and skipLibCheck (#45806) @Janpot
134
+ - [docs-infra] Fix redirect styles pages (#45848) @siriwatknp
135
+ - [docs-infra] Remove false-positive Vale rules (#45843) @oliviertassinari
136
+ - [docs-infra] Make sure Next.js can find package.json through its aliases (#45840) @Janpot
137
+ - [docs-infra] Fix Next.js brand name coverage (6915f8d) @oliviertassinari
138
+ - [docs-infra] Fix layout shift between MIT and commercial pages (#45760) @oliviertassinari
139
+ - [docs-infra] Non breaking space for ESM (#45758) @oliviertassinari
140
+ - [support-infra] Remove dead 'workflow_call:' (#45736) @oliviertassinari
141
+ - [utils] Support cleanup callbacks in useForkRef (#45621) @DiegoAndai
142
+
143
+ ### Docs
144
+
145
+ - Fix pigment vite integration example (#44746) @brijeshb42
146
+ - Update migration instructions and codemod references for deprecated APIs (#45793) @sai6855
147
+ - Add TanStack Router routing example (#44930) @vetledv
148
+ - Fix layout shifting in icons page (#45779) @sai6855
149
+ - Fix migration instructions (#45762) @oliviertassinari
150
+ - Fix wrong TypeScript support version (#45761) @oliviertassinari
151
+ - Fix link to mui-joy/src/styles/components.d.ts (#45763) @oliviertassinari
152
+ - Fix 301 link (ae94c40) @oliviertassinari
153
+ - Fix 301 links (abd8f63) @oliviertassinari
154
+ - Fix 301 redirection (c7658de) @oliviertassinari
155
+ - [nextjs] Migrate from deprecated "legacyBehavior" prop (#44871) @oliviertassinari
156
+ - [nextjs] Document CSP for Next.js Pages Router (#45798) @Grohden
157
+
158
+ All contributors of this release in alphabetical order: @brijeshb42, @DiegoAndai, @Grohden, @imadx, @Janpot, @Kartik-Murthy, @oliviertassinari, @renovate[bot], @sai6855, @siriwatknp, @vetledv, @ZeeshanTamboli
159
+
160
+ ## 7.0.1
161
+
162
+ <!-- generated comparing v7.0.0..master -->
163
+
164
+ _Mar 28, 2025_
165
+
166
+ A big thanks to the 7 contributors who made this release possible.
167
+
168
+ ### `@mui/material@7.0.1`
169
+
170
+ - Export ThemeProviderProps (#45701) @aarongarciah
171
+ - [Fab] Fix default variant text color when using CSS vars (#45714) @aarongarciah
172
+ - Remove mention of v7 in deprecation messages (#45708) @DiegoAndai
173
+ - [Popover] Allow `null` in `anchorEl` function return type (#45045) @eduter
174
+ - Fix missing CSSProperties/MixinOptions types (#45706) @Janpot
175
+
176
+ ### `@mui/icons-material@7.0.1`
177
+
178
+ - [code-infra] Fix icon-material type resolution under `moduleResolution: "node"` (#45704) @Janpot
179
+ - Bring back individual icon dts (#45711) @Janpot
180
+
181
+ ### Core
182
+
183
+ - Improve the release instructions (#45688) @mnajdova
184
+
185
+ ### Docs
186
+
187
+ - Fix Masonry and Toolpad dark mode demos (#45721) @siriwatknp
188
+ - Update v7 related copy (#45716) @aarongarciah
189
+ - Avoid unwanted undefined in page title (#45718) @aarongarciah
190
+ - Fix joy templates error (#45715) @siriwatknp
191
+ - Rename GitHub icon import (#45709) @micttyoid
192
+ - Fix Safari issue in dark mode (#45696) @mnajdova
193
+ - Fix `Grid`, `GridLegacy`, `Stack`, `Badge`, `Select`, `Autocomplete` demos CSS variables (#45693) @DiegoAndai
194
+ - Add "Material UI v7 is here" to the notifications (#45694) @DiegoAndai
195
+ - Fix `Breadcrumbs`, `List`, `Divider`, and `Typography` dark mode demos (#45692) @siriwatknp
196
+ - Fix Material Icons page in dark mode (#45691) @mnajdova
197
+
198
+ All contributors of this release in alphabetical order: @aarongarciah, @DiegoAndai, @eduter, @Janpot, @micttyoid, @mnajdova, @siriwatknp
199
+
3
200
  ## 7.0.0
4
201
 
5
202
  <!-- generated comparing v7.0.0-rc.0..master -->
@@ -0,0 +1 @@
1
+ module.exports = require('next/compat/router');
@@ -0,0 +1,2 @@
1
+ declare const _exports: typeof import("next/compat/router");
2
+ export = _exports;
@@ -3,7 +3,8 @@
3
3
  import * as React from 'react';
4
4
  import createCache from '@emotion/cache';
5
5
  import { CacheProvider as DefaultCacheProvider } from '@emotion/react';
6
- import { useServerInsertedHTML } from 'next/navigation';
6
+ import { useServerInsertedHTML } from "./nextNavigation.cjs";
7
+ import { useRouter as usePagesRouter } from "../nextCompatRouter.cjs";
7
8
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
9
  /**
9
10
  * Emotion works OK without this provider but it's recommended to use this provider to improve performance.
@@ -11,6 +12,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
12
  * See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153 for why it's a problem.
12
13
  */
13
14
  export default function AppRouterCacheProvider(props) {
15
+ if (process.env.NODE_ENV !== 'production') {
16
+ // eslint-disable-next-line react-hooks/rules-of-hooks
17
+ const router = usePagesRouter();
18
+ if (router) {
19
+ console.error(['The App Router CacheProvider is not compatible with the Pages Router.', 'Please use the Pages Router CacheProvider from `@mui/material-ui-nextjs/vx-pagesRouter` instead.'].join('\n'));
20
+ }
21
+ }
14
22
  const {
15
23
  options,
16
24
  CacheProvider = DefaultCacheProvider,
@@ -26,7 +34,7 @@ export default function AppRouterCacheProvider(props) {
26
34
  let inserted = [];
27
35
  // Override the insert method to support streaming SSR with flush().
28
36
  cache.insert = (...args) => {
29
- if (options?.enableCssLayer) {
37
+ if (options?.enableCssLayer && !args[1].styles.startsWith('@layer')) {
30
38
  args[1].styles = `@layer mui {${args[1].styles}}`;
31
39
  }
32
40
  const [selector, serialized] = args;
@@ -0,0 +1 @@
1
+ module.exports = require('next/navigation');
@@ -0,0 +1,2 @@
1
+ declare const _exports: typeof import("next/navigation");
2
+ export = _exports;
@@ -1 +1,4 @@
1
- export default function createEmotionCache(): import("@emotion/cache").EmotionCache;
1
+ import createCache from '@emotion/cache';
2
+ export default function createEmotionCache(options?: {
3
+ enableCssLayer?: boolean;
4
+ } & Parameters<typeof createCache>[0]): import("@emotion/cache").EmotionCache;
@@ -4,14 +4,30 @@ const isBrowser = typeof document !== 'undefined';
4
4
  // On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
5
5
  // This assures that MUI styles are loaded first.
6
6
  // It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
7
- export default function createEmotionCache() {
7
+ export default function createEmotionCache(options) {
8
8
  let insertionPoint;
9
9
  if (isBrowser) {
10
10
  const emotionInsertionPoint = document.querySelector('meta[name="emotion-insertion-point"]');
11
11
  insertionPoint = emotionInsertionPoint ?? undefined;
12
12
  }
13
- return createCache({
13
+ const {
14
+ enableCssLayer,
15
+ ...rest
16
+ } = options ?? {};
17
+ const emotionCache = createCache({
14
18
  key: 'mui',
15
- insertionPoint
19
+ insertionPoint,
20
+ ...rest
16
21
  });
22
+ if (enableCssLayer) {
23
+ const prevInsert = emotionCache.insert;
24
+ emotionCache.insert = (...args) => {
25
+ if (!args[1].styles.startsWith('@layer')) {
26
+ // avoid nested @layer
27
+ args[1].styles = `@layer mui {${args[1].styles}}`;
28
+ }
29
+ return prevInsert(...args);
30
+ };
31
+ }
32
+ return emotionCache;
17
33
  }
@@ -1,2 +1,3 @@
1
1
  export * from "./pagesRouterV13Document.js";
2
- export * from "./pagesRouterV13App.js";
2
+ export * from "./pagesRouterV13App.js";
3
+ export { default as createEmotionCache } from "./createCache.js";
@@ -1,2 +1,3 @@
1
1
  export * from "./pagesRouterV13Document.js";
2
- export * from "./pagesRouterV13App.js";
2
+ export * from "./pagesRouterV13App.js";
3
+ export { default as createEmotionCache } from "./createCache.js";
@@ -1,12 +1,20 @@
1
1
  import * as React from 'react';
2
2
  import { CacheProvider } from '@emotion/react';
3
3
  import createEmotionCache from "./createCache.js";
4
+ import { useRouter as usePagesRouter } from "../nextCompatRouter.cjs";
4
5
  import { jsx as _jsx } from "react/jsx-runtime";
5
6
  const defaultEmotionCache = createEmotionCache();
6
7
  export function AppCacheProvider({
7
8
  emotionCache = defaultEmotionCache,
8
9
  children
9
10
  }) {
11
+ if (process.env.NODE_ENV !== 'production') {
12
+ // eslint-disable-next-line react-hooks/rules-of-hooks
13
+ const router = usePagesRouter();
14
+ if (!router) {
15
+ console.error(['The Pages router CacheProvider is not compatible with the App router.', 'Please use the App Router CacheProvider from `@mui/material-ui-nextjs/vx-appRouter` instead.'].join('n'));
16
+ }
17
+ }
10
18
  return /*#__PURE__*/_jsx(CacheProvider, {
11
19
  value: emotionCache,
12
20
  children: children
@@ -74,13 +74,22 @@ export async function documentGetInitialProps(ctx, options) {
74
74
  } = extractCriticalToChunks(initialProps.html);
75
75
  return {
76
76
  ...initialProps,
77
- emotionStyleTags: styles.map(style => /*#__PURE__*/_jsx("style", {
78
- "data-emotion": `${style.key} ${style.ids.join(' ')}`,
79
- // eslint-disable-next-line react/no-danger
80
- dangerouslySetInnerHTML: {
81
- __html: style.css
77
+ emotionStyleTags: styles.map(style => {
78
+ if (!style.css.trim()) {
79
+ return null;
82
80
  }
83
- }, style.key))
81
+ const isLayerOrderRule = style.css.startsWith('@layer') && !style.css.match(/\{.*\}/);
82
+ return /*#__PURE__*/_jsx("style", {
83
+ // If the style is a layer order rule, prefix with the cache key to let Emotion hydrate this node.
84
+ // Otherwise, Emotion will hydrate only the non-global styles and they will override the layer order rule.
85
+ "data-emotion": `${isLayerOrderRule ? `${cache.key} ` : ''}${style.key} ${style.ids.join(' ')}`,
86
+ // eslint-disable-next-line react/no-danger
87
+ dangerouslySetInnerHTML: {
88
+ __html: style.css
89
+ },
90
+ nonce: cache.nonce
91
+ }, style.key);
92
+ })
84
93
  };
85
94
  }
86
95
  }, ...(options?.plugins ?? [])])(ctx);
@@ -0,0 +1 @@
1
+ module.exports = require('next/compat/router');
package/package.json CHANGED
@@ -1,7 +1,6 @@
1
1
  {
2
2
  "name": "@mui/material-nextjs",
3
- "version": "7.0.0",
4
- "private": false,
3
+ "version": "7.1.0",
5
4
  "author": "MUI Team",
6
5
  "description": "Collection of utilities for integration between Material UI and Next.js.",
7
6
  "keywords": [
@@ -24,7 +23,7 @@
24
23
  "url": "https://opencollective.com/mui-org"
25
24
  },
26
25
  "dependencies": {
27
- "@babel/runtime": "^7.26.10"
26
+ "@babel/runtime": "^7.27.1"
28
27
  },
29
28
  "peerDependencies": {
30
29
  "@emotion/cache": "^11.11.0",
@@ -64,10 +63,6 @@
64
63
  "import": {
65
64
  "types": "./esm/*/index.d.ts",
66
65
  "default": "./esm/*/index.js"
67
- },
68
- "mui-modern": {
69
- "types": "./modern/*/index.d.ts",
70
- "default": "./modern/*/index.js"
71
66
  }
72
67
  },
73
68
  "./v13-pagesRouter": {
@@ -78,11 +73,8 @@
78
73
  "import": {
79
74
  "types": "./esm/v13-pagesRouter/index.d.ts",
80
75
  "default": "./esm/v13-pagesRouter/index.js"
81
- },
82
- "mui-modern": {
83
- "types": "./modern/v13-pagesRouter/index.d.ts",
84
- "default": "./modern/v13-pagesRouter/index.js"
85
76
  }
86
77
  }
87
- }
78
+ },
79
+ "private": false
88
80
  }
@@ -10,7 +10,8 @@ exports.default = AppRouterCacheProvider;
10
10
  var React = _interopRequireWildcard(require("react"));
11
11
  var _cache = _interopRequireDefault(require("@emotion/cache"));
12
12
  var _react2 = require("@emotion/react");
13
- var _navigation = require("next/navigation");
13
+ var _nextNavigation = require("./nextNavigation.cjs");
14
+ var _nextCompatRouter = require("../nextCompatRouter.cjs");
14
15
  var _jsxRuntime = require("react/jsx-runtime");
15
16
  /**
16
17
  * Emotion works OK without this provider but it's recommended to use this provider to improve performance.
@@ -18,6 +19,13 @@ var _jsxRuntime = require("react/jsx-runtime");
18
19
  * See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153 for why it's a problem.
19
20
  */
20
21
  function AppRouterCacheProvider(props) {
22
+ if (process.env.NODE_ENV !== 'production') {
23
+ // eslint-disable-next-line react-hooks/rules-of-hooks
24
+ const router = (0, _nextCompatRouter.useRouter)();
25
+ if (router) {
26
+ console.error(['The App Router CacheProvider is not compatible with the Pages Router.', 'Please use the Pages Router CacheProvider from `@mui/material-ui-nextjs/vx-pagesRouter` instead.'].join('\n'));
27
+ }
28
+ }
21
29
  const {
22
30
  options,
23
31
  CacheProvider = _react2.CacheProvider,
@@ -33,7 +41,7 @@ function AppRouterCacheProvider(props) {
33
41
  let inserted = [];
34
42
  // Override the insert method to support streaming SSR with flush().
35
43
  cache.insert = (...args) => {
36
- if (options?.enableCssLayer) {
44
+ if (options?.enableCssLayer && !args[1].styles.startsWith('@layer')) {
37
45
  args[1].styles = `@layer mui {${args[1].styles}}`;
38
46
  }
39
47
  const [selector, serialized] = args;
@@ -55,7 +63,7 @@ function AppRouterCacheProvider(props) {
55
63
  flush
56
64
  };
57
65
  });
58
- (0, _navigation.useServerInsertedHTML)(() => {
66
+ (0, _nextNavigation.useServerInsertedHTML)(() => {
59
67
  const inserted = registry.flush();
60
68
  if (inserted.length === 0) {
61
69
  return null;
@@ -0,0 +1 @@
1
+ module.exports = require('next/navigation');
@@ -1 +1,4 @@
1
- export default function createEmotionCache(): import("@emotion/cache").EmotionCache;
1
+ import createCache from '@emotion/cache';
2
+ export default function createEmotionCache(options?: {
3
+ enableCssLayer?: boolean;
4
+ } & Parameters<typeof createCache>[0]): import("@emotion/cache").EmotionCache;
@@ -11,14 +11,30 @@ const isBrowser = typeof document !== 'undefined';
11
11
  // On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
12
12
  // This assures that MUI styles are loaded first.
13
13
  // It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
14
- function createEmotionCache() {
14
+ function createEmotionCache(options) {
15
15
  let insertionPoint;
16
16
  if (isBrowser) {
17
17
  const emotionInsertionPoint = document.querySelector('meta[name="emotion-insertion-point"]');
18
18
  insertionPoint = emotionInsertionPoint ?? undefined;
19
19
  }
20
- return (0, _cache.default)({
20
+ const {
21
+ enableCssLayer,
22
+ ...rest
23
+ } = options ?? {};
24
+ const emotionCache = (0, _cache.default)({
21
25
  key: 'mui',
22
- insertionPoint
26
+ insertionPoint,
27
+ ...rest
23
28
  });
29
+ if (enableCssLayer) {
30
+ const prevInsert = emotionCache.insert;
31
+ emotionCache.insert = (...args) => {
32
+ if (!args[1].styles.startsWith('@layer')) {
33
+ // avoid nested @layer
34
+ args[1].styles = `@layer mui {${args[1].styles}}`;
35
+ }
36
+ return prevInsert(...args);
37
+ };
38
+ }
39
+ return emotionCache;
24
40
  }
@@ -1,2 +1,3 @@
1
1
  export * from "./pagesRouterV13Document.js";
2
- export * from "./pagesRouterV13App.js";
2
+ export * from "./pagesRouterV13App.js";
3
+ export { default as createEmotionCache } from "./createCache.js";
@@ -1,11 +1,22 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
7
+ var _exportNames = {
8
+ createEmotionCache: true
9
+ };
10
+ Object.defineProperty(exports, "createEmotionCache", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _createCache.default;
14
+ }
15
+ });
6
16
  var _pagesRouterV13Document = require("./pagesRouterV13Document");
7
17
  Object.keys(_pagesRouterV13Document).forEach(function (key) {
8
18
  if (key === "default" || key === "__esModule") return;
19
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
9
20
  if (key in exports && exports[key] === _pagesRouterV13Document[key]) return;
10
21
  Object.defineProperty(exports, key, {
11
22
  enumerable: true,
@@ -17,6 +28,7 @@ Object.keys(_pagesRouterV13Document).forEach(function (key) {
17
28
  var _pagesRouterV13App = require("./pagesRouterV13App");
18
29
  Object.keys(_pagesRouterV13App).forEach(function (key) {
19
30
  if (key === "default" || key === "__esModule") return;
31
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
20
32
  if (key in exports && exports[key] === _pagesRouterV13App[key]) return;
21
33
  Object.defineProperty(exports, key, {
22
34
  enumerable: true,
@@ -24,4 +36,5 @@ Object.keys(_pagesRouterV13App).forEach(function (key) {
24
36
  return _pagesRouterV13App[key];
25
37
  }
26
38
  });
27
- });
39
+ });
40
+ var _createCache = _interopRequireDefault(require("./createCache"));
@@ -9,12 +9,20 @@ exports.AppCacheProvider = AppCacheProvider;
9
9
  var React = _interopRequireWildcard(require("react"));
10
10
  var _react2 = require("@emotion/react");
11
11
  var _createCache = _interopRequireDefault(require("./createCache"));
12
+ var _nextCompatRouter = require("../nextCompatRouter.cjs");
12
13
  var _jsxRuntime = require("react/jsx-runtime");
13
14
  const defaultEmotionCache = (0, _createCache.default)();
14
15
  function AppCacheProvider({
15
16
  emotionCache = defaultEmotionCache,
16
17
  children
17
18
  }) {
19
+ if (process.env.NODE_ENV !== 'production') {
20
+ // eslint-disable-next-line react-hooks/rules-of-hooks
21
+ const router = (0, _nextCompatRouter.useRouter)();
22
+ if (!router) {
23
+ console.error(['The Pages router CacheProvider is not compatible with the App router.', 'Please use the App Router CacheProvider from `@mui/material-ui-nextjs/vx-appRouter` instead.'].join('n'));
24
+ }
25
+ }
18
26
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.CacheProvider, {
19
27
  value: emotionCache,
20
28
  children: children
@@ -84,13 +84,22 @@ async function documentGetInitialProps(ctx, options) {
84
84
  } = extractCriticalToChunks(initialProps.html);
85
85
  return {
86
86
  ...initialProps,
87
- emotionStyleTags: styles.map(style => /*#__PURE__*/(0, _jsxRuntime.jsx)("style", {
88
- "data-emotion": `${style.key} ${style.ids.join(' ')}`,
89
- // eslint-disable-next-line react/no-danger
90
- dangerouslySetInnerHTML: {
91
- __html: style.css
87
+ emotionStyleTags: styles.map(style => {
88
+ if (!style.css.trim()) {
89
+ return null;
92
90
  }
93
- }, style.key))
91
+ const isLayerOrderRule = style.css.startsWith('@layer') && !style.css.match(/\{.*\}/);
92
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("style", {
93
+ // If the style is a layer order rule, prefix with the cache key to let Emotion hydrate this node.
94
+ // Otherwise, Emotion will hydrate only the non-global styles and they will override the layer order rule.
95
+ "data-emotion": `${isLayerOrderRule ? `${cache.key} ` : ''}${style.key} ${style.ids.join(' ')}`,
96
+ // eslint-disable-next-line react/no-danger
97
+ dangerouslySetInnerHTML: {
98
+ __html: style.css
99
+ },
100
+ nonce: cache.nonce
101
+ }, style.key);
102
+ })
94
103
  };
95
104
  }
96
105
  }, ...(options?.plugins ?? [])])(ctx);
@@ -1 +0,0 @@
1
- {"type":"module","sideEffects":false}
@@ -1,27 +0,0 @@
1
- import * as React from 'react';
2
- import { EmotionCache, Options as OptionsOfCreateCache } from '@emotion/cache';
3
- export type AppRouterCacheProviderProps = {
4
- /**
5
- * These are the options passed to createCache() from 'import createCache from "@emotion/cache"'.
6
- */
7
- options?: Partial<OptionsOfCreateCache> & {
8
- /**
9
- * If `true`, the generated styles are wrapped within `@layer mui`.
10
- * This is useful if you want to override the Material UI's generated styles with different styling solution, like Tailwind CSS, plain CSS etc.
11
- */
12
- enableCssLayer?: boolean;
13
- };
14
- /**
15
- * By default <CacheProvider /> from 'import { CacheProvider } from "@emotion/react"'.
16
- */
17
- CacheProvider?: React.ElementType<{
18
- value: EmotionCache;
19
- }>;
20
- children: React.ReactNode;
21
- };
22
- /**
23
- * Emotion works OK without this provider but it's recommended to use this provider to improve performance.
24
- * Without it, Emotion will generate a new <style> tag during SSR for every component.
25
- * See https://github.com/mui/material-ui/issues/26561#issuecomment-855286153 for why it's a problem.
26
- */
27
- export default function AppRouterCacheProvider(props: AppRouterCacheProviderProps): React.JSX.Element;