You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make it so automatic theme switcher prefers system theme preference over 'last theme chosen' as option #7199
Open tab => "dark" found in local storage, system theme neglected
This doesn't make sense with disableSwitch since it's rather not the user's choice.
I don't think we need to add another option, but with disableSwitch: true and respectPrefersColorScheme: true we absolutely should always respect system settings instead of persisting the last choice
I don't really understand how to reproduce your screencast 🤪
Looks like there are a few weird things we do:
on system color mode change, we persist the new system color, eventually overriding the manually selected color from user => problem for users that have "auto system color mode" => color is "erased/replaced" every day)
on disableSwitch, we never clean up the persisted color mode to ensure system color can kick in again
The problem is, we believe a system-color-mode-triggered theme change is a user change and we persist it in local storage, so when the user opens up the tab again under a different color mode, we don't update the theme according to the system theme but uses the persisted one instead.
on system color mode change, we persist the new system color, eventually overriding the manually selected color from user => problem for users that have "auto system color mode" => color is "erased/replaced" every day)
That is the whole point of the "OS default" color mode. It's expected that whenever OS color changes (like according to time), the site changes as well.
on disableSwitch, we never clean up the persisted color mode to ensure system color can kick in again
The problem is, we believe a system-color-mode-triggered theme change is a user change and we persist it in local storage, so when the user opens up the tab again under a different color mode, we don't update the theme according to the system theme but uses the persisted one instead.
Yes that's why I think we should call something like setColorMode(color, persist = false) in this case (when the mediaquery onChange is triggered)
That is the whole point of the "OS default" color mode. It's expected that whenever OS color changes (like according to time), the site changes as well.
If the user explicitly toggle the color mode, the color mode should remain the same IMHO.
If you want to reset to "follow OS color mode", we'd need a 3rd option to handle that, not simply ignoring the persisted value
We should consider the case where a site previously had a switch enabled (and thus a persisted value) and then later the switch is removed => we'd better clean localstorage in this case
We should consider the case where a site previously had a switch enabled (and thus a persisted value) and then later the switch is removed => we'd better clean localstorage in this case
Yes, I understand this better.
About "OS default", disableSwitch and respectPrefersColorScheme combined is pretty much already a simulation of "OS default". We should always follow the OS theme in this case.
About "OS default", disableSwitch and respectPrefersColorScheme combined is pretty much already a simulation of "OS default". We should always follow the OS theme in this case.
Yes agree on that. And it should follow OS theme even if there used to be a switch before ;)
But for sites that do want a switch, we currently don't provide any option for a single user to reset their choice to system os => that is not ideal and we may need top adapt design to provide a third option
Things to consider:
User is using "auto OS theme" but really wants to use the Docusaurus site in dark mode only => OS theme changes should simply be ignored and not persisted
User is using "auto OS theme" and previously selected an explicit theme value but wants to move back to "auto OS theme" and have different theme according to current daylight => user can't do that
Unfortunately with the current UX, one of these 2 scenarios is not possible
Activity
Josh-Cena commentedon Apr 18, 2022
The way to understand this is:
This doesn't make sense with
disableSwitchsince it's rather not the user's choice.I don't think we need to add another option, but with
disableSwitch: trueandrespectPrefersColorScheme: truewe absolutely should always respect system settings instead of persisting the last choiceslorber commentedon Apr 20, 2022
I don't really understand how to reproduce your screencast 🤪
Looks like there are a few weird things we do:
Josh-Cena commentedon Apr 20, 2022
The problem is, we believe a system-color-mode-triggered theme change is a user change and we persist it in local storage, so when the user opens up the tab again under a different color mode, we don't update the theme according to the system theme but uses the persisted one instead.
That is the whole point of the "OS default" color mode. It's expected that whenever OS color changes (like according to time), the site changes as well.
Yep, that's what I'm fixing in #7200
slorber commentedon Apr 20, 2022
Yes that's why I think we should call something like
setColorMode(color, persist = false)in this case (when the mediaquery onChange is triggered)If the user explicitly toggle the color mode, the color mode should remain the same IMHO.
If you want to reset to "follow OS color mode", we'd need a 3rd option to handle that, not simply ignoring the persisted value
Like someone mentioned in the MDN doc:
https://developer.mozilla.org/
Not exactly: you only "not persist" it
We should consider the case where a site previously had a switch enabled (and thus a persisted value) and then later the switch is removed => we'd better clean localstorage in this case
Josh-Cena commentedon Apr 20, 2022
Yes, I understand this better.
About "OS default",
disableSwitchandrespectPrefersColorSchemecombined is pretty much already a simulation of "OS default". We should always follow the OS theme in this case.slorber commentedon Apr 20, 2022
Yes agree on that. And it should follow OS theme even if there used to be a switch before ;)
But for sites that do want a switch, we currently don't provide any option for a single user to reset their choice to system os => that is not ideal and we may need top adapt design to provide a third option
Things to consider:
Unfortunately with the current UX, one of these 2 scenarios is not possible
Josh-Cena commentedon Apr 20, 2022
I understand that, but not totally relevant to the current issue, right? Would be a useful enhancement instead.
slorber commentedon Apr 20, 2022
Adding a 3rd "auto OS" option is not part of this issue as it changes the UX
the rest remains quite related to me and can be considered a bugfix