From 31924ee706c5886726c9d6adb222779d957a3d8c Mon Sep 17 00:00:00 2001 From: Olivier Tassinari Date: Fri, 24 Dec 2021 22:21:51 +0100 Subject: [PATCH] [examples] Fix CSS modules integration (#30381) --- docs/pages/_app.js | 1 + docs/src/modules/components/Head.js | 1 - docs/src/modules/components/Link.tsx | 2 +- docs/src/pages/guides/routing/routing.md | 2 +- .../README.md | 4 +++ examples/create-react-app/README.md | 4 +++ examples/gatsby/README.md | 6 ----- .../gatsby-plugin-mui-emotion/gatsby-ssr.js | 18 ++++++++++++-- .../getEmotionCache.js | 2 ++ examples/gatsby/sandbox.config.json | 5 ---- examples/joy-cra-typescript/README.md | 2 ++ examples/nextjs-with-typescript/.editorconfig | 23 ------------------ .../nextjs-with-typescript/.eslintrc.json | 5 ---- examples/nextjs-with-typescript/README.md | 2 ++ examples/nextjs-with-typescript/next-env.d.ts | 1 - examples/nextjs-with-typescript/package.json | 3 ++- .../{src => }/pages/_app.tsx | 5 ++-- .../{src => }/pages/_document.tsx | 11 +++++---- .../{src => }/pages/about.tsx | 6 ++--- .../{src => }/pages/index.tsx | 6 ++--- .../nextjs-with-typescript/public/vercel.svg | 4 --- .../sandbox.config.json | 5 ---- .../src/{components => }/Copyright.tsx | 0 .../src/{components => }/Link.tsx | 3 ++- .../src/{components => }/ProTip.tsx | 0 .../src/createEmotionCache.ts | 7 ++++++ .../src/pages/api/hello.ts | 10 -------- .../src/{styles => }/theme.ts | 0 .../src/utils/createEmotionCache.ts | 5 ---- examples/nextjs/README.md | 2 ++ examples/nextjs/next.config.js | 3 +++ examples/nextjs/package.json | 19 +++++++++------ examples/nextjs/pages/_app.js | 1 - examples/nextjs/pages/_document.js | 6 +++-- examples/nextjs/public/favicon.ico | Bin 0 -> 25931 bytes examples/nextjs/sandbox.config.json | 5 ---- examples/nextjs/src/createEmotionCache.js | 2 ++ examples/preact/README.md | 6 ----- examples/remix-with-typescript/.stackblitzrc | 3 +++ examples/remix-with-typescript/README.md | 2 ++ examples/ssr/README.md | 6 ----- examples/ssr/createEmotionCache.js | 2 ++ examples/ssr/sandbox.config.json | 5 ---- .../StyledEngineProvider.js | 3 ++- 44 files changed, 90 insertions(+), 118 deletions(-) delete mode 100644 examples/gatsby/sandbox.config.json delete mode 100644 examples/nextjs-with-typescript/.editorconfig delete mode 100644 examples/nextjs-with-typescript/.eslintrc.json rename examples/nextjs-with-typescript/{src => }/pages/_app.tsx (87%) rename examples/nextjs-with-typescript/{src => }/pages/_document.tsx (87%) rename examples/nextjs-with-typescript/{src => }/pages/about.tsx (87%) rename examples/nextjs-with-typescript/{src => }/pages/index.tsx (85%) delete mode 100644 examples/nextjs-with-typescript/public/vercel.svg delete mode 100644 examples/nextjs-with-typescript/sandbox.config.json rename examples/nextjs-with-typescript/src/{components => }/Copyright.tsx (100%) rename examples/nextjs-with-typescript/src/{components => }/Link.tsx (95%) rename examples/nextjs-with-typescript/src/{components => }/ProTip.tsx (100%) create mode 100644 examples/nextjs-with-typescript/src/createEmotionCache.ts delete mode 100644 examples/nextjs-with-typescript/src/pages/api/hello.ts rename examples/nextjs-with-typescript/src/{styles => }/theme.ts (100%) delete mode 100644 examples/nextjs-with-typescript/src/utils/createEmotionCache.ts create mode 100644 examples/nextjs/next.config.js create mode 100644 examples/nextjs/public/favicon.ico delete mode 100644 examples/nextjs/sandbox.config.json create mode 100644 examples/remix-with-typescript/.stackblitzrc delete mode 100644 examples/ssr/sandbox.config.json diff --git a/docs/pages/_app.js b/docs/pages/_app.js index d506bd7ddb6ace..cbbf2a0391a4b4 100644 --- a/docs/pages/_app.js +++ b/docs/pages/_app.js @@ -214,6 +214,7 @@ function AppWrapper(props) { return ( + {fonts.map((font) => ( ))} diff --git a/docs/src/modules/components/Head.js b/docs/src/modules/components/Head.js index 4a753687b64cf0..a7ae243b4a2c71 100644 --- a/docs/src/modules/components/Head.js +++ b/docs/src/modules/components/Head.js @@ -21,7 +21,6 @@ export default function Head(props) { const preview = card.startsWith('http') ? card : `${HOST}${card}`; return ( - {title} {/* Twitter */} diff --git a/docs/src/modules/components/Link.tsx b/docs/src/modules/components/Link.tsx index 27b166e411df07..97731549c33700 100644 --- a/docs/src/modules/components/Link.tsx +++ b/docs/src/modules/components/Link.tsx @@ -11,7 +11,7 @@ import { useUserLanguage } from 'docs/src/modules/utils/i18n'; * * - /docs/src/modules/components/Link.tsx * - /examples/nextjs/src/Link.tsx - * - /examples/nextjs-with-typescript/src/components/Link.tsx + * - /examples/nextjs-with-typescript/src/Link.tsx */ // Add support for the sx prop for consistency with the other branches. diff --git a/docs/src/pages/guides/routing/routing.md b/docs/src/pages/guides/routing/routing.md index bd2fb31d34c51e..aad05eeb556b93 100644 --- a/docs/src/pages/guides/routing/routing.md +++ b/docs/src/pages/guides/routing/routing.md @@ -97,7 +97,7 @@ const LinkBehavior = React.forwardRef((props, ref) => ( Next.js has [a custom Link component](https://nextjs.org/docs/api-reference/next/link). The [example folder](https://github.com/mui-org/material-ui/tree/HEAD/examples/nextjs-with-typescript) provides adapters for usage with MUI. -- The first version of the adapter is the [`NextLinkComposed`](https://github.com/mui-org/material-ui/blob/HEAD/examples/nextjs-with-typescript/src/components/Link.tsx) component. +- The first version of the adapter is the [`NextLinkComposed`](https://github.com/mui-org/material-ui/blob/HEAD/examples/nextjs-with-typescript/src/Link.tsx) component. This component is unstyled and only responsible for handling the navigation. The prop `href` was renamed `to` to avoid a naming conflict. This is similar to react-router's Link component. diff --git a/examples/create-react-app-with-typescript/README.md b/examples/create-react-app-with-typescript/README.md index ca8c6861e9aefb..49dcb4a937385b 100644 --- a/examples/create-react-app-with-typescript/README.md +++ b/examples/create-react-app-with-typescript/README.md @@ -24,6 +24,10 @@ or: [![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/mui-org/material-ui/tree/master/examples/create-react-app-with-typescript) + + +[![Edit on StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/mui-org/material-ui/tree/master/examples/create-react-app-with-typescript) + ## The idea behind the example This example demonstrates how you can use [Create React App](https://github.com/facebookincubator/create-react-app) with [TypeScript](https://github.com/Microsoft/TypeScript). diff --git a/examples/create-react-app/README.md b/examples/create-react-app/README.md index bb72afcbec8a89..c25790da518be9 100644 --- a/examples/create-react-app/README.md +++ b/examples/create-react-app/README.md @@ -24,6 +24,10 @@ or: [![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/mui-org/material-ui/tree/master/examples/create-react-app) + + +[![Edit on StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/mui-org/material-ui/tree/master/examples/create-react-app) + ## The idea behind the example diff --git a/examples/gatsby/README.md b/examples/gatsby/README.md index 5c05fe4e2d4bba..91a6173418a6ba 100644 --- a/examples/gatsby/README.md +++ b/examples/gatsby/README.md @@ -18,12 +18,6 @@ npm install npm run develop ``` -or: - - - -[![Edit on CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/mui-org/material-ui/tree/master/examples/gatsby) - ## The idea behind the example The project uses [Gatsby](https://github.com/gatsbyjs/gatsby), which is a static site generator for React. diff --git a/examples/gatsby/plugins/gatsby-plugin-mui-emotion/gatsby-ssr.js b/examples/gatsby/plugins/gatsby-plugin-mui-emotion/gatsby-ssr.js index dc53a1d535d636..388bb20bb069aa 100644 --- a/examples/gatsby/plugins/gatsby-plugin-mui-emotion/gatsby-ssr.js +++ b/examples/gatsby/plugins/gatsby-plugin-mui-emotion/gatsby-ssr.js @@ -1,10 +1,24 @@ -/* eslint-disable import/prefer-default-export */ import * as React from 'react'; import { CacheProvider } from '@emotion/react'; import createEmotionServer from '@emotion/server/create-instance'; import { renderToString } from 'react-dom/server'; import getEmotionCache from './getEmotionCache'; +// Inject MUI styles first to match with the prepend: true configuration. +export const onPreRenderHTML = ({ getHeadComponents, replaceHeadComponents }) => { + const headComponents = getHeadComponents(); + headComponents.sort((x, y) => { + if (x.key === 'emotion-css-global' || x.key === 'emotion-css') { + return -1; + } + if (y.key === 'style') { + return 1; + } + return 0; + }); + replaceHeadComponents(headComponents); +}; + export const replaceRenderer = ({ bodyComponent, setHeadComponents, replaceBodyHTMLString }) => { const cache = getEmotionCache(); const { extractCriticalToChunks } = createEmotionServer(cache); @@ -17,7 +31,7 @@ export const replaceRenderer = ({ bodyComponent, setHeadComponents, replaceBodyH emotionStyles.styles.map((style) => (