@mui/material-nextjs 5.15.0 → 5.15.4
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.
- package/README.md +1 -1
- package/{CHANGELOG.md → build/CHANGELOG.md} +263 -4
- package/build/README.md +3 -0
- package/build/legacy/v13-pagesRouter/createCache.js +17 -0
- package/build/legacy/v13-pagesRouter/index.js +2 -0
- package/build/legacy/v13-pagesRouter/pagesRouterV13App.js +14 -0
- package/{legacy/v13-pagesRouter/pagesRouterV13.js → build/legacy/v13-pagesRouter/pagesRouterV13Document.js} +12 -38
- package/build/modern/v13-pagesRouter/createCache.js +17 -0
- package/build/modern/v13-pagesRouter/index.js +2 -0
- package/build/modern/v13-pagesRouter/pagesRouterV13App.js +14 -0
- package/{modern/v13-pagesRouter/pagesRouterV13.js → build/modern/v13-pagesRouter/pagesRouterV13Document.js} +6 -31
- package/build/node/v13-pagesRouter/createCache.js +24 -0
- package/build/node/v13-pagesRouter/index.js +27 -0
- package/build/node/v13-pagesRouter/pagesRouterV13App.js +23 -0
- package/{node/v13-pagesRouter/pagesRouterV13.js → build/node/v13-pagesRouter/pagesRouterV13Document.js} +7 -33
- package/build/package.json +52 -0
- package/build/v13-pagesRouter/createCache.d.ts +1 -0
- package/build/v13-pagesRouter/createCache.js +17 -0
- package/build/v13-pagesRouter/index.d.ts +2 -0
- package/build/v13-pagesRouter/index.js +2 -0
- package/build/v13-pagesRouter/pagesRouterV13App.d.ts +6 -0
- package/build/v13-pagesRouter/pagesRouterV13App.js +14 -0
- package/{v13-pagesRouter/pagesRouterV13.d.ts → build/v13-pagesRouter/pagesRouterV13Document.d.ts} +0 -4
- package/{v13-pagesRouter/pagesRouterV13.js → build/v13-pagesRouter/pagesRouterV13Document.js} +6 -31
- package/package.json +25 -5
- package/src/v13-appRouter/appRouterV13.tsx +102 -0
- package/src/v13-appRouter/index.ts +3 -0
- package/src/v13-pagesRouter/createCache.ts +19 -0
- package/src/v13-pagesRouter/index.ts +2 -0
- package/src/v13-pagesRouter/pagesRouterV13App.tsx +16 -0
- package/src/v13-pagesRouter/pagesRouterV13Document.tsx +115 -0
- package/src/v14-appRouter/index.ts +2 -0
- package/src/v14-pagesRouter/index.ts +1 -0
- package/tsconfig.build.json +15 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +7 -0
- package/legacy/v13-pagesRouter/index.js +0 -1
- package/modern/v13-pagesRouter/index.js +0 -1
- package/node/v13-pagesRouter/index.js +0 -16
- package/v13-pagesRouter/index.d.ts +0 -1
- package/v13-pagesRouter/index.js +0 -1
- /package/{LICENSE → build/LICENSE} +0 -0
- /package/{legacy → build/legacy}/v13-appRouter/appRouterV13.js +0 -0
- /package/{legacy → build/legacy}/v13-appRouter/index.js +0 -0
- /package/{legacy → build/legacy}/v14-appRouter/index.js +0 -0
- /package/{legacy → build/legacy}/v14-pagesRouter/index.js +0 -0
- /package/{modern → build/modern}/v13-appRouter/appRouterV13.js +0 -0
- /package/{modern → build/modern}/v13-appRouter/index.js +0 -0
- /package/{modern → build/modern}/v14-appRouter/index.js +0 -0
- /package/{modern → build/modern}/v14-pagesRouter/index.js +0 -0
- /package/{node → build/node}/v13-appRouter/appRouterV13.js +0 -0
- /package/{node → build/node}/v13-appRouter/index.js +0 -0
- /package/{node → build/node}/v14-appRouter/index.js +0 -0
- /package/{node → build/node}/v14-pagesRouter/index.js +0 -0
- /package/{v13-appRouter → build/v13-appRouter}/appRouterV13.d.ts +0 -0
- /package/{v13-appRouter → build/v13-appRouter}/appRouterV13.js +0 -0
- /package/{v13-appRouter → build/v13-appRouter}/index.d.ts +0 -0
- /package/{v13-appRouter → build/v13-appRouter}/index.js +0 -0
- /package/{v13-appRouter → build/v13-appRouter}/package.json +0 -0
- /package/{v13-pagesRouter → build/v13-pagesRouter}/package.json +0 -0
- /package/{v14-appRouter → build/v14-appRouter}/index.d.ts +0 -0
- /package/{v14-appRouter → build/v14-appRouter}/index.js +0 -0
- /package/{v14-appRouter → build/v14-appRouter}/package.json +0 -0
- /package/{v14-pagesRouter → build/v14-pagesRouter}/index.d.ts +0 -0
- /package/{v14-pagesRouter → build/v14-pagesRouter}/index.js +0 -0
- /package/{v14-pagesRouter → build/v14-pagesRouter}/package.json +0 -0
|
@@ -4,46 +4,18 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.AppCacheProvider = AppCacheProvider;
|
|
8
7
|
exports.DocumentHeadTags = DocumentHeadTags;
|
|
9
8
|
exports.createGetInitialProps = createGetInitialProps;
|
|
10
9
|
exports.documentGetInitialProps = documentGetInitialProps;
|
|
11
10
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
11
|
var React = _interopRequireWildcard(require("react"));
|
|
13
|
-
var _react2 = require("@emotion/react");
|
|
14
|
-
var _cache = _interopRequireDefault(require("@emotion/cache"));
|
|
15
12
|
var _createInstance = _interopRequireDefault(require("@emotion/server/create-instance"));
|
|
16
13
|
var _document = _interopRequireDefault(require("next/document"));
|
|
14
|
+
var _createCache = _interopRequireDefault(require("./createCache"));
|
|
17
15
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
18
16
|
var _meta;
|
|
19
17
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
18
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
|
-
const isBrowser = typeof document !== 'undefined';
|
|
22
|
-
|
|
23
|
-
// On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
|
|
24
|
-
// This assures that MUI styles are loaded first.
|
|
25
|
-
// It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
|
|
26
|
-
function createEmotionCache() {
|
|
27
|
-
let insertionPoint;
|
|
28
|
-
if (isBrowser) {
|
|
29
|
-
const emotionInsertionPoint = document.querySelector('meta[name="emotion-insertion-point"]');
|
|
30
|
-
insertionPoint = emotionInsertionPoint != null ? emotionInsertionPoint : undefined;
|
|
31
|
-
}
|
|
32
|
-
return (0, _cache.default)({
|
|
33
|
-
key: 'mui',
|
|
34
|
-
insertionPoint
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const defaultEmotionCache = createEmotionCache();
|
|
38
|
-
function AppCacheProvider({
|
|
39
|
-
emotionCache = defaultEmotionCache,
|
|
40
|
-
children
|
|
41
|
-
}) {
|
|
42
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react2.CacheProvider, {
|
|
43
|
-
value: emotionCache,
|
|
44
|
-
children: children
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
19
|
/**
|
|
48
20
|
* A utility to compose multiple `getInitialProps` functions.
|
|
49
21
|
*/
|
|
@@ -97,7 +69,12 @@ async function documentGetInitialProps(ctx, options) {
|
|
|
97
69
|
|
|
98
70
|
// You can consider sharing the same Emotion cache between all the SSR requests to speed up performance.
|
|
99
71
|
// However, be aware that it can have global side effects.
|
|
100
|
-
const cache = (_options$emotionCache = options == null ? void 0 : options.emotionCache) != null ? _options$emotionCache :
|
|
72
|
+
const cache = (_options$emotionCache = options == null ? void 0 : options.emotionCache) != null ? _options$emotionCache : (0, _createCache.default)();
|
|
73
|
+
// The createEmotionServer has to be called directly after the cache creation due to the side effect of cache.compat = true,
|
|
74
|
+
// otherwise the <style> tag will not come with the HTML string from the server.
|
|
75
|
+
const {
|
|
76
|
+
extractCriticalToChunks
|
|
77
|
+
} = (0, _createInstance.default)(cache);
|
|
101
78
|
return createGetInitialProps([{
|
|
102
79
|
enhanceApp: App => function EnhanceApp(props) {
|
|
103
80
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(App, (0, _extends2.default)({
|
|
@@ -105,9 +82,6 @@ async function documentGetInitialProps(ctx, options) {
|
|
|
105
82
|
}, props));
|
|
106
83
|
},
|
|
107
84
|
resolveProps: async initialProps => {
|
|
108
|
-
const {
|
|
109
|
-
extractCriticalToChunks
|
|
110
|
-
} = (0, _createInstance.default)(cache);
|
|
111
85
|
const {
|
|
112
86
|
styles
|
|
113
87
|
} = extractCriticalToChunks(initialProps.html);
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mui/material-nextjs",
|
|
3
|
+
"version": "5.15.4",
|
|
4
|
+
"private": false,
|
|
5
|
+
"author": "MUI Team",
|
|
6
|
+
"description": "Collection of utilities for integration between Material UI and Next.js.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"react",
|
|
9
|
+
"next",
|
|
10
|
+
"material-ui"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/mui/material-ui.git",
|
|
15
|
+
"directory": "packages/mui-material-nextjs"
|
|
16
|
+
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/mui/material-ui/issues"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://mui.com/material-ui/guides/nextjs/",
|
|
22
|
+
"funding": {
|
|
23
|
+
"type": "opencollective",
|
|
24
|
+
"url": "https://opencollective.com/mui-org"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"@emotion/cache": "^11.11.0",
|
|
28
|
+
"@emotion/server": "^11.11.0",
|
|
29
|
+
"@mui/material": "^5.0.0",
|
|
30
|
+
"@types/react": "^17.0.0 || ^18.0.0",
|
|
31
|
+
"next": "^13.0.0 || ^14.0.0",
|
|
32
|
+
"react": "^17.0.0 || ^18.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependenciesMeta": {
|
|
35
|
+
"@types/react": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"@emotion/cache": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"@emotion/server": {
|
|
42
|
+
"optional": true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"sideEffects": false,
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=12.0.0"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function createEmotionCache(): import("@emotion/cache").EmotionCache;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import createCache from '@emotion/cache';
|
|
2
|
+
const isBrowser = typeof document !== 'undefined';
|
|
3
|
+
|
|
4
|
+
// On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
|
|
5
|
+
// This assures that MUI styles are loaded first.
|
|
6
|
+
// It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
|
|
7
|
+
export default function createEmotionCache() {
|
|
8
|
+
let insertionPoint;
|
|
9
|
+
if (isBrowser) {
|
|
10
|
+
const emotionInsertionPoint = document.querySelector('meta[name="emotion-insertion-point"]');
|
|
11
|
+
insertionPoint = emotionInsertionPoint != null ? emotionInsertionPoint : undefined;
|
|
12
|
+
}
|
|
13
|
+
return createCache({
|
|
14
|
+
key: 'mui',
|
|
15
|
+
insertionPoint
|
|
16
|
+
});
|
|
17
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { EmotionCache } from '@emotion/react';
|
|
3
|
+
export interface EmotionCacheProviderProps {
|
|
4
|
+
emotionCache?: EmotionCache;
|
|
5
|
+
}
|
|
6
|
+
export declare function AppCacheProvider({ emotionCache, children, }: React.PropsWithChildren<EmotionCacheProviderProps>): React.JSX.Element;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CacheProvider } from '@emotion/react';
|
|
3
|
+
import createEmotionCache from './createCache';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
const defaultEmotionCache = createEmotionCache();
|
|
6
|
+
export function AppCacheProvider({
|
|
7
|
+
emotionCache = defaultEmotionCache,
|
|
8
|
+
children
|
|
9
|
+
}) {
|
|
10
|
+
return /*#__PURE__*/_jsx(CacheProvider, {
|
|
11
|
+
value: emotionCache,
|
|
12
|
+
children: children
|
|
13
|
+
});
|
|
14
|
+
}
|
package/{v13-pagesRouter/pagesRouterV13.d.ts → build/v13-pagesRouter/pagesRouterV13Document.d.ts}
RENAMED
|
@@ -2,10 +2,6 @@ import * as React from 'react';
|
|
|
2
2
|
import { AppType } from 'next/app';
|
|
3
3
|
import { EmotionCache } from '@emotion/react';
|
|
4
4
|
import { DocumentContext, DocumentInitialProps } from 'next/document';
|
|
5
|
-
interface EmotionCacheProviderProps {
|
|
6
|
-
emotionCache?: EmotionCache;
|
|
7
|
-
}
|
|
8
|
-
export declare function AppCacheProvider({ emotionCache, children, }: React.PropsWithChildren<EmotionCacheProviderProps>): React.JSX.Element;
|
|
9
5
|
interface Plugin {
|
|
10
6
|
enhanceApp: (App: React.ComponentType<React.ComponentProps<AppType>>) => (props: any) => JSX.Element;
|
|
11
7
|
resolveProps: (initialProps: DocumentInitialProps) => Promise<DocumentInitialProps>;
|
package/{v13-pagesRouter/pagesRouterV13.js → build/v13-pagesRouter/pagesRouterV13Document.js}
RENAMED
|
@@ -1,38 +1,11 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
var _meta;
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { CacheProvider } from '@emotion/react';
|
|
5
|
-
import createCache from '@emotion/cache';
|
|
6
4
|
import createEmotionServer from '@emotion/server/create-instance';
|
|
7
5
|
import Document from 'next/document';
|
|
6
|
+
import createEmotionCache from './createCache';
|
|
8
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
8
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
-
const isBrowser = typeof document !== 'undefined';
|
|
11
|
-
|
|
12
|
-
// On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
|
|
13
|
-
// This assures that MUI styles are loaded first.
|
|
14
|
-
// It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
|
|
15
|
-
function createEmotionCache() {
|
|
16
|
-
let insertionPoint;
|
|
17
|
-
if (isBrowser) {
|
|
18
|
-
const emotionInsertionPoint = document.querySelector('meta[name="emotion-insertion-point"]');
|
|
19
|
-
insertionPoint = emotionInsertionPoint != null ? emotionInsertionPoint : undefined;
|
|
20
|
-
}
|
|
21
|
-
return createCache({
|
|
22
|
-
key: 'mui',
|
|
23
|
-
insertionPoint
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
const defaultEmotionCache = createEmotionCache();
|
|
27
|
-
export function AppCacheProvider({
|
|
28
|
-
emotionCache = defaultEmotionCache,
|
|
29
|
-
children
|
|
30
|
-
}) {
|
|
31
|
-
return /*#__PURE__*/_jsx(CacheProvider, {
|
|
32
|
-
value: emotionCache,
|
|
33
|
-
children: children
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
9
|
/**
|
|
37
10
|
* A utility to compose multiple `getInitialProps` functions.
|
|
38
11
|
*/
|
|
@@ -87,6 +60,11 @@ export async function documentGetInitialProps(ctx, options) {
|
|
|
87
60
|
// You can consider sharing the same Emotion cache between all the SSR requests to speed up performance.
|
|
88
61
|
// However, be aware that it can have global side effects.
|
|
89
62
|
const cache = (_options$emotionCache = options == null ? void 0 : options.emotionCache) != null ? _options$emotionCache : createEmotionCache();
|
|
63
|
+
// The createEmotionServer has to be called directly after the cache creation due to the side effect of cache.compat = true,
|
|
64
|
+
// otherwise the <style> tag will not come with the HTML string from the server.
|
|
65
|
+
const {
|
|
66
|
+
extractCriticalToChunks
|
|
67
|
+
} = createEmotionServer(cache);
|
|
90
68
|
return createGetInitialProps([{
|
|
91
69
|
enhanceApp: App => function EnhanceApp(props) {
|
|
92
70
|
return /*#__PURE__*/_jsx(App, _extends({
|
|
@@ -94,9 +72,6 @@ export async function documentGetInitialProps(ctx, options) {
|
|
|
94
72
|
}, props));
|
|
95
73
|
},
|
|
96
74
|
resolveProps: async initialProps => {
|
|
97
|
-
const {
|
|
98
|
-
extractCriticalToChunks
|
|
99
|
-
} = createEmotionServer(cache);
|
|
100
75
|
const {
|
|
101
76
|
styles
|
|
102
77
|
} = extractCriticalToChunks(initialProps.html);
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/material-nextjs",
|
|
3
|
-
"version": "5.15.
|
|
3
|
+
"version": "5.15.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "MUI Team",
|
|
6
6
|
"description": "Collection of utilities for integration between Material UI and Next.js.",
|
|
7
7
|
"keywords": [
|
|
8
8
|
"react",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"utils"
|
|
9
|
+
"next",
|
|
10
|
+
"material-ui"
|
|
12
11
|
],
|
|
13
12
|
"repository": {
|
|
14
13
|
"type": "git",
|
|
@@ -19,11 +18,19 @@
|
|
|
19
18
|
"bugs": {
|
|
20
19
|
"url": "https://github.com/mui/material-ui/issues"
|
|
21
20
|
},
|
|
22
|
-
"homepage": "
|
|
21
|
+
"homepage": "https://mui.com/material-ui/guides/nextjs/",
|
|
23
22
|
"funding": {
|
|
24
23
|
"type": "opencollective",
|
|
25
24
|
"url": "https://opencollective.com/mui-org"
|
|
26
25
|
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@emotion/cache": "^11.11.0",
|
|
28
|
+
"@emotion/react": "^11.11.3",
|
|
29
|
+
"@emotion/server": "^11.11.0",
|
|
30
|
+
"@types/react": "^18.2.46",
|
|
31
|
+
"next": "13.4.19",
|
|
32
|
+
"react": "^18.2.0"
|
|
33
|
+
},
|
|
27
34
|
"peerDependencies": {
|
|
28
35
|
"@emotion/cache": "^11.11.0",
|
|
29
36
|
"@emotion/server": "^11.11.0",
|
|
@@ -49,5 +56,18 @@
|
|
|
49
56
|
},
|
|
50
57
|
"engines": {
|
|
51
58
|
"node": ">=12.0.0"
|
|
59
|
+
},
|
|
60
|
+
"scripts": {
|
|
61
|
+
"build": "pnpm build:legacy && pnpm build:modern && pnpm build:node && pnpm build:stable && pnpm build:types && pnpm build:copy-files",
|
|
62
|
+
"build:legacy": "node ../../scripts/build.mjs legacy",
|
|
63
|
+
"build:modern": "node ../../scripts/build.mjs modern",
|
|
64
|
+
"build:node": "node ../../scripts/build.mjs node",
|
|
65
|
+
"build:stable": "node ../../scripts/build.mjs stable",
|
|
66
|
+
"build:copy-files": "node ../../scripts/copyFiles.mjs",
|
|
67
|
+
"build:types": "node ../../scripts/buildTypes.mjs",
|
|
68
|
+
"prebuild": "rimraf build tsconfig.build.tsbuildinfo",
|
|
69
|
+
"release": "pnpm build && npm publish build",
|
|
70
|
+
"test": "cd ../../ && cross-env NODE_ENV=test mocha 'packages/mui-utils/**/*.test.{js,ts,tsx}'",
|
|
71
|
+
"typescript": "tsc -p tsconfig.json"
|
|
52
72
|
}
|
|
53
73
|
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import createCache from '@emotion/cache';
|
|
4
|
+
import { useServerInsertedHTML } from 'next/navigation';
|
|
5
|
+
import { CacheProvider as DefaultCacheProvider } from '@emotion/react';
|
|
6
|
+
import type { EmotionCache, Options as OptionsOfCreateCache } from '@emotion/cache';
|
|
7
|
+
|
|
8
|
+
export type AppRouterCacheProviderProps = {
|
|
9
|
+
/** These are the options passed to createCache() from 'import createCache from "@emotion/cache"' */
|
|
10
|
+
options?: Partial<OptionsOfCreateCache> & {
|
|
11
|
+
/**
|
|
12
|
+
* If `true`, the generated styles are wrapped within `@layer mui`.
|
|
13
|
+
* This is useful if you want to override the Material UI's generated styles with different styling solution, like Tailwind, plain CSS etc.
|
|
14
|
+
*/
|
|
15
|
+
enableCssLayer?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/** By default <CacheProvider /> from 'import { CacheProvider } from "@emotion/react"' */
|
|
18
|
+
CacheProvider?: (props: {
|
|
19
|
+
value: EmotionCache;
|
|
20
|
+
children: React.ReactNode;
|
|
21
|
+
}) => React.JSX.Element | null;
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default function AppRouterCacheProvider(props: AppRouterCacheProviderProps) {
|
|
26
|
+
const { options, CacheProvider = DefaultCacheProvider, children } = props;
|
|
27
|
+
|
|
28
|
+
const [registry] = React.useState(() => {
|
|
29
|
+
const cache = createCache({ ...options, key: options?.key ?? 'mui' });
|
|
30
|
+
cache.compat = true;
|
|
31
|
+
const prevInsert = cache.insert;
|
|
32
|
+
let inserted: { name: string; isGlobal: boolean }[] = [];
|
|
33
|
+
cache.insert = (...args) => {
|
|
34
|
+
if (options?.enableCssLayer) {
|
|
35
|
+
args[1].styles = `@layer mui {${args[1].styles}}`;
|
|
36
|
+
}
|
|
37
|
+
const [selector, serialized] = args;
|
|
38
|
+
if (cache.inserted[serialized.name] === undefined) {
|
|
39
|
+
inserted.push({
|
|
40
|
+
name: serialized.name,
|
|
41
|
+
isGlobal: !selector,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return prevInsert(...args);
|
|
45
|
+
};
|
|
46
|
+
const flush = () => {
|
|
47
|
+
const prevInserted = inserted;
|
|
48
|
+
inserted = [];
|
|
49
|
+
return prevInserted;
|
|
50
|
+
};
|
|
51
|
+
return { cache, flush };
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
useServerInsertedHTML(() => {
|
|
55
|
+
const inserted = registry.flush();
|
|
56
|
+
if (inserted.length === 0) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
let styles = '';
|
|
60
|
+
let dataEmotionAttribute = registry.cache.key;
|
|
61
|
+
|
|
62
|
+
const globals: {
|
|
63
|
+
name: string;
|
|
64
|
+
style: string;
|
|
65
|
+
}[] = [];
|
|
66
|
+
|
|
67
|
+
inserted.forEach(({ name, isGlobal }) => {
|
|
68
|
+
const style = registry.cache.inserted[name];
|
|
69
|
+
|
|
70
|
+
if (typeof style !== 'boolean') {
|
|
71
|
+
if (isGlobal) {
|
|
72
|
+
globals.push({ name, style });
|
|
73
|
+
} else {
|
|
74
|
+
styles += style;
|
|
75
|
+
dataEmotionAttribute += ` ${name}`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<React.Fragment>
|
|
82
|
+
{globals.map(({ name, style }) => (
|
|
83
|
+
<style
|
|
84
|
+
key={name}
|
|
85
|
+
data-emotion={`${registry.cache.key}-global ${name}`}
|
|
86
|
+
// eslint-disable-next-line react/no-danger
|
|
87
|
+
dangerouslySetInnerHTML={{ __html: style }}
|
|
88
|
+
/>
|
|
89
|
+
))}
|
|
90
|
+
{styles && (
|
|
91
|
+
<style
|
|
92
|
+
data-emotion={dataEmotionAttribute}
|
|
93
|
+
// eslint-disable-next-line react/no-danger
|
|
94
|
+
dangerouslySetInnerHTML={{ __html: styles }}
|
|
95
|
+
/>
|
|
96
|
+
)}
|
|
97
|
+
</React.Fragment>
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return <CacheProvider value={registry.cache}>{children}</CacheProvider>;
|
|
102
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import createCache from '@emotion/cache';
|
|
2
|
+
|
|
3
|
+
const isBrowser = typeof document !== 'undefined';
|
|
4
|
+
|
|
5
|
+
// On the client side, Create a meta tag at the top of the <head> and set it as insertionPoint.
|
|
6
|
+
// This assures that MUI styles are loaded first.
|
|
7
|
+
// It allows developers to easily override MUI styles with other styling solutions, like CSS modules.
|
|
8
|
+
export default function createEmotionCache() {
|
|
9
|
+
let insertionPoint;
|
|
10
|
+
|
|
11
|
+
if (isBrowser) {
|
|
12
|
+
const emotionInsertionPoint = document.querySelector<HTMLMetaElement>(
|
|
13
|
+
'meta[name="emotion-insertion-point"]',
|
|
14
|
+
);
|
|
15
|
+
insertionPoint = emotionInsertionPoint ?? undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return createCache({ key: 'mui', insertionPoint });
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { CacheProvider, EmotionCache } from '@emotion/react';
|
|
3
|
+
import createEmotionCache from './createCache';
|
|
4
|
+
|
|
5
|
+
export interface EmotionCacheProviderProps {
|
|
6
|
+
emotionCache?: EmotionCache;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const defaultEmotionCache = createEmotionCache();
|
|
10
|
+
|
|
11
|
+
export function AppCacheProvider({
|
|
12
|
+
emotionCache = defaultEmotionCache,
|
|
13
|
+
children,
|
|
14
|
+
}: React.PropsWithChildren<EmotionCacheProviderProps>) {
|
|
15
|
+
return <CacheProvider value={emotionCache}>{children}</CacheProvider>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AppType } from 'next/app';
|
|
3
|
+
import { EmotionCache } from '@emotion/react';
|
|
4
|
+
import createEmotionServer from '@emotion/server/create-instance';
|
|
5
|
+
import Document, { DocumentContext, DocumentInitialProps } from 'next/document';
|
|
6
|
+
import { EmotionCacheProviderProps } from './pagesRouterV13App';
|
|
7
|
+
import createEmotionCache from './createCache';
|
|
8
|
+
|
|
9
|
+
interface Plugin {
|
|
10
|
+
enhanceApp: (
|
|
11
|
+
App: React.ComponentType<React.ComponentProps<AppType>>,
|
|
12
|
+
) => (props: any) => JSX.Element;
|
|
13
|
+
resolveProps: (initialProps: DocumentInitialProps) => Promise<DocumentInitialProps>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A utility to compose multiple `getInitialProps` functions.
|
|
18
|
+
*/
|
|
19
|
+
export function createGetInitialProps(plugins: Plugin[]) {
|
|
20
|
+
return async function getInitialProps(ctx: DocumentContext) {
|
|
21
|
+
const originalRenderPage = ctx.renderPage;
|
|
22
|
+
|
|
23
|
+
ctx.renderPage = () =>
|
|
24
|
+
originalRenderPage({
|
|
25
|
+
enhanceApp: (App) => plugins.reduce((result, plugin) => plugin.enhanceApp(result), App),
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const initialProps = await Document.getInitialProps(ctx);
|
|
29
|
+
|
|
30
|
+
const finalProps = await plugins.reduce(
|
|
31
|
+
async (result, plugin) => plugin.resolveProps(await result),
|
|
32
|
+
Promise.resolve(initialProps),
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
return finalProps;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface DocumentHeadTagsProps {
|
|
40
|
+
emotionStyleTags: React.JSX.Element[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function DocumentHeadTags({ emotionStyleTags }: DocumentHeadTagsProps) {
|
|
44
|
+
return (
|
|
45
|
+
<React.Fragment>
|
|
46
|
+
<meta name="emotion-insertion-point" content="" />
|
|
47
|
+
{emotionStyleTags}
|
|
48
|
+
</React.Fragment>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// `getInitialProps` belongs to `_document` (instead of `_app`),
|
|
53
|
+
// it's compatible with static-site generation (SSG).
|
|
54
|
+
export async function documentGetInitialProps(
|
|
55
|
+
ctx: DocumentContext,
|
|
56
|
+
options?: {
|
|
57
|
+
emotionCache?: EmotionCache;
|
|
58
|
+
plugins?: Plugin[];
|
|
59
|
+
},
|
|
60
|
+
) {
|
|
61
|
+
// Resolution order
|
|
62
|
+
//
|
|
63
|
+
// On the server:
|
|
64
|
+
// 1. app.getInitialProps
|
|
65
|
+
// 2. page.getInitialProps
|
|
66
|
+
// 3. document.getInitialProps
|
|
67
|
+
// 4. app.render
|
|
68
|
+
// 5. page.render
|
|
69
|
+
// 6. document.render
|
|
70
|
+
//
|
|
71
|
+
// On the server with error:
|
|
72
|
+
// 1. document.getInitialProps
|
|
73
|
+
// 2. app.render
|
|
74
|
+
// 3. page.render
|
|
75
|
+
// 4. document.render
|
|
76
|
+
//
|
|
77
|
+
// On the client
|
|
78
|
+
// 1. app.getInitialProps
|
|
79
|
+
// 2. page.getInitialProps
|
|
80
|
+
// 3. app.render
|
|
81
|
+
// 4. page.render
|
|
82
|
+
|
|
83
|
+
// You can consider sharing the same Emotion cache between all the SSR requests to speed up performance.
|
|
84
|
+
// However, be aware that it can have global side effects.
|
|
85
|
+
const cache = options?.emotionCache ?? createEmotionCache();
|
|
86
|
+
// The createEmotionServer has to be called directly after the cache creation due to the side effect of cache.compat = true,
|
|
87
|
+
// otherwise the <style> tag will not come with the HTML string from the server.
|
|
88
|
+
const { extractCriticalToChunks } = createEmotionServer(cache);
|
|
89
|
+
|
|
90
|
+
return createGetInitialProps([
|
|
91
|
+
{
|
|
92
|
+
enhanceApp: (
|
|
93
|
+
App: React.ComponentType<React.ComponentProps<AppType> & EmotionCacheProviderProps>,
|
|
94
|
+
) =>
|
|
95
|
+
function EnhanceApp(props) {
|
|
96
|
+
return <App emotionCache={cache} {...props} />;
|
|
97
|
+
},
|
|
98
|
+
resolveProps: async (initialProps) => {
|
|
99
|
+
const { styles } = extractCriticalToChunks(initialProps.html);
|
|
100
|
+
return {
|
|
101
|
+
...initialProps,
|
|
102
|
+
emotionStyleTags: styles.map((style) => (
|
|
103
|
+
<style
|
|
104
|
+
data-emotion={`${style.key} ${style.ids.join(' ')}`}
|
|
105
|
+
key={style.key}
|
|
106
|
+
// eslint-disable-next-line react/no-danger
|
|
107
|
+
dangerouslySetInnerHTML={{ __html: style.css }}
|
|
108
|
+
/>
|
|
109
|
+
)),
|
|
110
|
+
};
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
...(options?.plugins ?? []),
|
|
114
|
+
])(ctx) as Promise<DocumentInitialProps & DocumentHeadTagsProps>;
|
|
115
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../v13-pagesRouter';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
// This config is for emitting declarations (.d.ts) only
|
|
3
|
+
// Actual .ts source files are transpiled via babel
|
|
4
|
+
"extends": "./tsconfig.json",
|
|
5
|
+
"compilerOptions": {
|
|
6
|
+
"composite": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"noEmit": false,
|
|
9
|
+
"emitDeclarationOnly": true,
|
|
10
|
+
"outDir": "build",
|
|
11
|
+
"rootDir": "./src"
|
|
12
|
+
},
|
|
13
|
+
"include": ["./src/**/*.ts*"],
|
|
14
|
+
"exclude": ["src/**/*.spec.ts*", "src/**/*.test.ts*"]
|
|
15
|
+
}
|