-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[system] createTheme() shouldn't have "use client" #42750
Comments
|
@mj12albert I think that this is the opposite problem. There should be no In today's import path, there are a good number of them:
then
then
|
Landed here after reproducing steps. |
As a workaround, it is possible to import from import { Experimental_CssVarsProvider } from "@mui/material";
import { AppRouterCacheProvider } from "@mui/material-nextjs/v14-appRouter";
import getInitColorSchemeScript from "@mui/system/cssVars/getInitColorSchemeScript";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link
rel="preconnect"
href="https://fonts.gstatic.com"
crossOrigin="anonymous"
/>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap"
/>
</head>
<body>
<AppRouterCacheProvider>
<Experimental_CssVarsProvider defaultMode="system">
{getInitColorSchemeScript({
// These properties are normally set when importing from @mui/material,
// but we have to set manually because we are importing from @mui/system.
attribute: "data-mui-color-scheme",
modeStorageKey: "mui-mode",
colorSchemeStorageKey: "mui-color-scheme",
// All options that you pass to CssVarsProvider you should also pass here.
defaultMode: "system",
})}
{children}
</Experimental_CssVarsProvider>
</AppRouterCacheProvider>
</body>
</html>
);
} It would be nice if this could be integrated in the |
Same bug with I first saw a developer complain on Twitter, more recently on #40199 (comment). |
Following up from #40945 (the issue closed right above) - the recommended steps there did not work (still experiencing flickering). Will be following this issue for updates. |
I'm on this. This should help with zero-runtime integration as well. |
I took a few steps to fix this in #40663 but didn't go all in. Wanted to test the water. |
I got this error after removing
I wonder if it would be a better DX to add |
@siriwatknp Arf, tricky. It goes back to my point in: emotion-js/emotion#2978 (comment). The right solution might be to have two default themes/two theme creators: one in the client-side bundle and one in the server-side bundle. I mean, it would be the exact same logic, but one would be flagged as use client, the other wouldn't, so two different entry points, one implementation. How I understand things working: |
@bartlangelaan's workaround didn't work for me. Seems like it's not exported anymore. I've resorted to adding |
@oliviertassinari I'm removing |
Thanks and it works for me! |
The bug is still relevant |
@siriwatknp I would still expect the opposite. We need to be able to use the theme in server components, but also in client components. So I would expect that a theme is created twice. |
I removed |
So this probably means the current stable (v5) and the upcoming version (v6) of MUI don't support a custom theme in a server component? It seems I can follow this guide here to create the theme in a client component instead: https://mui.com/material-ui/integrations/nextjs/ |
For the default Material UI v6, yes (because it still relies on Emotion). However, the theme will be removed at build time if you replace Emotion with Pigment CSS. |
FYI: Just noticed the following in #43264 While running
Looks like Next.js RSC can't have both Removing |
@Janpot It might be vercel/next.js#64518 (comment), it was getting fixed in #41956, we could resume this. |
Hi, I am trying to use Mui V6 with Next 15, and after I remove the import { CssBaseline, Box, Toolbar } from "@mui/material";
import { ThemeProvider } from "@mui/material/styles";
import { AppRouterCacheProvider } from "@mui/material-nextjs/v13-appRouter";
import type { Metadata } from "next";
import CustomAppBar from "@/components/AppBar";
import { CommonStoreProvider } from "@/providers/common-store-provider";
import theme from "@/theme";
import { NextIntlClientProvider } from "next-intl";
import { getTranslations } from "next-intl/server";
import { getMessages } from "next-intl/server";
import { notFound } from "next/navigation";
import { routing } from "@/i18n/routing";
import { Suspense } from "react";
import Loading from "@/app/[locale]/loading";
export const metadata: Metadata = {
title: "nextjs-mui-zustand-template",
description: "Next.js + MUI + Zustand template",
};
export default async function RootLayout(props: {
children: React.ReactNode;
params: { locale: string };
}) {
const params = await props.params;
const { locale } = params;
const { children } = props;
if (!routing.locales.includes(locale as any)) {
notFound();
}
const messages = await getMessages();
const t = await getTranslations("Common");
return (
<html lang="en">
<body>
<CommonStoreProvider>
<AppRouterCacheProvider options={{ key: "css" }}>
<NextIntlClientProvider messages={messages}>
<ThemeProvider theme={theme} defaultMode="system">
<CssBaseline />
<Box
sx={{
height: "100vh",
width: "100vw",
overflow: "hidden",
display: "flex",
}}
>
<Box
sx={{
display: "flex",
flex: "0 0 100vw",
height: "100vh",
flexWrap: "npwrap",
alignContent: "flex-start",
justifyContent: "space-between",
}}
>
<CustomAppBar title={t("appBarTitle")}></CustomAppBar>
<Box
sx={{
flexGrow: 1,
width: "100%",
height: "100%",
overflowY: "auto",
}}
>
<Toolbar></Toolbar>
<Suspense fallback={<Loading></Loading>}>
{children}
</Suspense>
</Box>
</Box>
</Box>
</ThemeProvider>
</NextIntlClientProvider>
</AppRouterCacheProvider>
</CommonStoreProvider>
</body>
</html>
);
} |
Steps to reproduce 🕹
Link to live example:
Steps:
Current behavior 😯
Expected behavior 🤔
It works
Context 🔦
Your environment 🌎
npx @mui/envinfo
Search keywords:
Search keywords:
The text was updated successfully, but these errors were encountered: