Skip to content

Make it so automatic theme switcher prefers system theme preference over 'last theme chosen' as option #7199

Closed

Description

@nikivdev

Have you read the Contributing Guidelines on issues?

Description

My Docu site located here https://wiki.nikiv.dev has no theme switch button. I want to rely only on system theme switcher, however that fails as shown in this screencast:

https://www.loom.com/share/3c06fb6b8f41418daffaf14fc4cb637b

This Discord thread has more context on the issue: https://discord.com/channels/398180168688074762/867060369087922187/965585587505618997

Also tagging @Josh-Cena :)

Has this been requested on Canny?

No response

Motivation

I want to be able to rely only on system theme setting to switch theme reliably.

API design

No response

Have you tried building it?

No response

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.

Activity

  1. added
    feature
    status: needs triage
    on Apr 18, 2022
  2. added
    domain: theme
    and removed
    status: needs triage
    on Apr 18, 2022
  3. Josh-Cena commented on Apr 18, 2022

    @Josh-Cena
    Collaborator

    The way to understand this is:

    1. Site in dark theme; system in dark theme
    2. Close tab => "dark" persisted in local storage
    3. Change system to light theme
    4. 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

  4. slorber commented on Apr 20, 2022

    @slorber
    Collaborator

    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
  5. Josh-Cena commented on Apr 20, 2022

    @Josh-Cena
    Collaborator

    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

    Yep, that's what I'm fixing in #7200

  6. slorber commented on Apr 20, 2022

    @slorber
    Collaborator

    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

    Like someone mentioned in the MDN doc:

    CleanShot 2022-04-20 at 15 31 52@2x

    https://developer.mozilla.org/

    on disableSwitch, we never clean up the persisted color mode to ensure system color can kick in again

    Yep, that's what I'm fixing in #7200

    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

  7. Josh-Cena commented on Apr 20, 2022

    @Josh-Cena
    Collaborator

    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.

  8. slorber commented on Apr 20, 2022

    @slorber
    Collaborator

    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

  9. Josh-Cena commented on Apr 20, 2022

    @Josh-Cena
    Collaborator

    I understand that, but not totally relevant to the current issue, right? Would be a useful enhancement instead.

  10. slorber commented on Apr 20, 2022

    @slorber
    Collaborator

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    domain: themefeature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions