Skip to content

Theme toggle destroys the follow-system state and cannot restore it #9

Description

@ClaydeCode

Symptom

Once the theme toggle is used, "follow the system theme" becomes unreachable for the rest of that browser's life. There is no way back.

Mechanism

js/theme-init.js treats three states: dark, light, and key-absent, where absent means follow prefers-color-scheme.

const t = localStorage.getItem('sundial.theme');
if (t === 'dark' || (t === null && matchMedia('(prefers-color-scheme: dark)').matches)) { ... }

js/components/dock.js:108 only ever writes two of them, and never removes the key:

localStorage.setItem('sundial.theme', dark ? 'light' : 'dark');

So the third state exists, is handled correctly on boot, and is destroyed by the first toggle.

Fix shape

Either cycle the toggle dark → light → system, or clear the key when the chosen value already matches the current system value. theme-init.js needs no change; it already handles the absent key.

Worth deciding which, since the two differ for a user whose system theme changes later in the day: cycling gives an explicit "system" position, clearing is invisible and could be mistaken for the setting not sticking.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions