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

MUI + NextJS + Redux - Dark Theme switch not working on SSR #44949

Open
karthikdivi opened this issue Jan 6, 2025 · 2 comments
Open

MUI + NextJS + Redux - Dark Theme switch not working on SSR #44949

karthikdivi opened this issue Jan 6, 2025 · 2 comments
Assignees
Labels
nextjs status: waiting for maintainer These issues haven't been looked at yet by a maintainer

Comments

@karthikdivi
Copy link

karthikdivi commented Jan 6, 2025

Steps to reproduce

Steps:

  1. Open this link to live example: (required)
  2. Repo: https://github.com/karthikdivi/thefinalstack/tree/main
  3. Run the following commands to start npm install --legacy-peer-deps and npm run dev

Current behavior

Dark mode not getting applied.

Expected behavior

On refreshing the page the dark mode should apply.

Context

When I switch the theme to Dark mode, it updates the Redux state and also preserved to LocalStorage. When I do a hard refresh in the browser, reading the theme preference from Redux and applying it. But the Dark theme is not showing.

Screen.Recording.2025-01-06.at.1.53.20.PM.mov

Your environment

npx @mui/envinfo
  Don't forget to mention which browser you used.
    System:
    OS: macOS 14.5
  Binaries:
    Node: 18.20.5 - ~/.nvm/versions/node/v18.20.5/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v18.20.5/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 131.0.6778.205
    Edge: Not Found
    Safari: 17.5
  npmPackages:
    @emotion/react: latest => 11.14.0 
    @emotion/styled: latest => 11.14.0 
    @mui/core-downloads-tracker:  6.3.1 
    @mui/icons-material: latest => 6.3.1 
    @mui/material: latest => 6.3.1 
    @mui/material-nextjs: latest => 6.3.1 
    @mui/private-theming:  6.3.1 
    @mui/styled-engine:  6.3.1 
    @mui/system:  6.3.1 
    @mui/types:  7.2.21 
    @mui/utils:  6.3.1 
    @types/react:  19.0.2 
    react: ^19.0.0 => 19.0.0 
    react-dom: ^19.0.0 => 19.0.0 
    typescript:  5.7.2 

Search keywords: nextjs dark mode

@karthikdivi karthikdivi added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jan 6, 2025
@zannager zannager added the nextjs label Jan 6, 2025
@siriwatknp
Copy link
Member

Is it required to use Redux? If not, I recommend following:

@siriwatknp siriwatknp added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jan 6, 2025
@karthikdivi
Copy link
Author

Is it required to use Redux? If not, I recommend following:

@siriwatknp I have updated the code with InitColorSchemeScript and it's already using the cssVariables. Still the issue persists.
Also do you have any reference implementation project with Dark mode toggle?

@github-actions github-actions bot added status: waiting for maintainer These issues haven't been looked at yet by a maintainer and removed status: waiting for author Issue with insufficient information labels Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
nextjs status: waiting for maintainer These issues haven't been looked at yet by a maintainer
Projects
None yet
Development

No branches or pull requests

3 participants