[material-ui][nextjs] useLocalStorage for theme name causes theme styles to get out of sync #41847
Labels
customization: theme
Centered around the theming features
nextjs
package: material-ui
Specific to @mui/material
Steps to reproduce
Link to live example: https://stackblitz.com/~/github.com/RickyRoller/mui-local-storage-bug
Steps:
Step 1
Step 2
It seems like the theme styles are getting out of sync with the styles from NextJS's pre-render of the app.
Looking at the DOM, there are pre-render styles that are always dominating the actual style tags in the app.
Steps to fix:
useState
in-between the local storage and the theme.Current behavior
If you save the non-default theme in local storage, the theme styles will break upon reloading the app.
Expected behavior
Theme styles should always be in sync with the theme value passed to the component.
Context
I want to store the theme name in local storage so that the user's last selected preference is loaded by default
Your environment
npx @mui/envinfo
Search keywords: useLocalStorage, NextJS
The text was updated successfully, but these errors were encountered: