Skip to content
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

Dark mode flicker on Vite.js #44250

Open
mtr1990 opened this issue Oct 29, 2024 · 5 comments
Open

Dark mode flicker on Vite.js #44250

mtr1990 opened this issue Oct 29, 2024 · 5 comments
Assignees
Labels
customization: css Design CSS customizability customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature package: system Specific to @mui/system support: question Community support but can be turned into an improvement

Comments

@mtr1990
Copy link

mtr1990 commented Oct 29, 2024

Steps to reproduce

Dark mode flicker Vite.js version :
https://stackblitz.com/edit/github-5gkalw?file=src%2Fmain.tsx,src%2Ftheme.tsx,src%2FApp.tsx,node_modules%2F%40mui%2Fmaterial%2FCssBaseline%2FCssBaseline.d.ts

For comparison I recreated the Next.js version
https://stackblitz.com/edit/github-rfxsj1?file=src%2Fapp%2Fpage.tsx,src%2Fapp%2Flayout.tsx,src%2Ftheme.ts,src%2Fcomponents%2FApp.tsx

Result

flicker.mp4

Current behavior

Dark mode flicker on Vite.js version with MUI v6.

in MUI v5 when used with CssVarsProvider and extendTheme don't have this problem.

Expected behavior

No flicker when refresh page

Context

No response

Your environment

No response

Search keywords: Dark mode flicker

@mtr1990 mtr1990 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 29, 2024
@zannager zannager added package: system Specific to @mui/system customization: theme Centered around the theming features customization: css Design CSS customizability labels Oct 29, 2024
@siriwatknp siriwatknp added docs Improvements or additions to the documentation enhancement This is not a bug, nor a new feature and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 31, 2024
@siriwatknp
Copy link
Member

The vite setup you provided is client side only. It won't be possible to prevent flickering because Material UI needs to render before generating the CSS variables.

On the other hand, the Next.js works because of SSR setup + InitColorSchemeScript component

Note: InitColorSchemeScript cannot be used in Vite because you cannot import it in index.html.

@siriwatknp siriwatknp added support: question Community support but can be turned into an improvement and removed docs Improvements or additions to the documentation labels Oct 31, 2024
@siriwatknp
Copy link
Member

The possible way is to use Pigment CSS to extract CSS variables at build time.

@mtr1990
Copy link
Author

mtr1990 commented Oct 31, 2024

@siriwatknp Thanks for clarifying.

Pigment CSS is currently only a experimental version. Is this a good time to migrate to Pigment CSS? Because my application has quite a few components. I tried integrating before but had a lot of errors. Maybe I will try again.

Currently I only see examples for Vite.js and Next.js

Can you please tell me where I can get an example of Pigment CSS + CRA (react-script)?

@siriwatknp
Copy link
Member

Can you please tell me where I can get an example of Pigment CSS + CRA (react-script)?

I don't think we will add an example for CRA, it's outdated. Is there any reason that you cannot use Vite?

@mtr1990
Copy link
Author

mtr1990 commented Oct 31, 2024

Can you please tell me where I can get an example of Pigment CSS + CRA (react-script)?

I don't think we will add an example for CRA, it's outdated. Is there any reason that you cannot use Vite?

Personally, I still like to use Vite.js because of its performance.

However, some of my customers still want to use CRA in their projects. So that's why I mentioned this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: css Design CSS customizability customization: theme Centered around the theming features enhancement This is not a bug, nor a new feature package: system Specific to @mui/system support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

3 participants