⬆️Migration v3 -> v4

Upgrade MUI

If you are using MUI you must upgrade @mui/material to v5.10.7 or newer.

Breaking changes

SSR setup

// src/pages/_app.tsx

-import type { EmotionCache } from "@emotion/cache";
-import createCache from "@emotion/cache";
-import { CacheProvider } from '@emotion/react';
+import { createEmotionSsrAdvancedApproach } from "tss-react/nextJs";

-let muiCache: EmotionCache | undefined = undefined;
-export const createMuiCache = () => muiCache = createCache({ "key": "mui", "prepend": true });

+const { EmotionCacheProvider, withEmotionCache } = createEmotionSsrAdvancedApproach({ "key": "css" });
+export { withEmotionCache };

 function App({ Component, pageProps }: AppProps) {

   ...

-			<CacheProvider value={muiCache ?? createMuiCache()}>
+			<EmotionCacheProvider>
				<MuiThemeProvider theme={theme}>
					<CssBaseline />
					<Component {...pageProps} />
				</MuiThemeProvider>
-			</CacheProvider>
+			</EmotionCacheProvider>

 );

useCssAndCx removed

useMergedClasses removed

Removing noise

Explicitly providing an emotion cache is still supported but no longer required.

Having issues?

🆘Fix broken styles after upgrading to MUI v5 with TSS

Last updated

Was this helpful?