-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
Add abillity to prevent CssVarsProvider
from using local storage
#35837
Comments
Has anyone found a solution for this for usage in Joy? I need to change the color scheme programmatically for certain templates, and it would seem I would need to interact with the local storage and CSSVarsProvider in order to do this, in a complex way? |
I'm not sure if this belongs as a comment on this ticket or if it should be its own ticket, but using localstorage like this creates some developer headaches when developing apps with different themes. Say I have an app This seems to require manually going in and clearing localstorage, so having an ability to disable that feature would be useful! At minimum, I would suggest adding a note to the documentation instructing developers to clear localstorage if switching between sites with different themes. |
The same issue, I don't want MUI to save the modes into localStorage. Instead we have our own theme manager. |
Maybe the |
I hate to jump on this with a me-too comment, but since there's been no obvious movement here I'd like to add my use case to the list. We provide an internal library that use @mui, we expose our own provider that configures themes etc. and as part of that we manage themes in our own code. This include setting the preferred theme. Having @mui explicitly try and do all of this for us just adds a list of features to work around, and honestly I've spent more times dealing with this than I have getting everything else related to css-variables working nicely. I don't want this library to automatically persist state. I don't particularly want this library to sync themes across multiple tabs (by reading that variable), at least make this opt-in. Can we please have an option to disable this behavior, it's such an intrusive change in behavior when compared to the previous interface. |
This makes sense to me. cc @siriwatknp can you look into this please? |
Yes, I'm looking into it. |
Summary 💡
The current implementation of
CssVarsProvider
requires the use of local storage to store the theme settings. My suggestion is to make the use of local storage optional. One idea is to add amode
property toCssVarsProvider
, in addition to the existingdefaultMode
property. With this new property, the theme would be controlled solely by the property and would not be affected by local storage. Another suggestion is to delay writing to local storage until the theme is explicitly changed using the setter of theuseColorScheme
hook. That way, if the setter is not used, nothing would be written to local storage.Examples 🌈
No response
Motivation 🔦
The current version of
CssVarsProvider
requires the use of local storage, even though it is unnecessary in certain situations. For example, if the theme is only controlled by the system theme, or if there is only one theme, there is no need to use local storage. Local storage adds unnecessary complexity due to statefulness. For example, it adds the need to check how divergent states in local storage and in code interact.The text was updated successfully, but these errors were encountered: