Skip to content

Frontend: Add dark mode persistence and system preference detection #470

Description

@joelpeace48-cell

Summary

The dark/light theme toggle exists but does not persist across sessions. Every page load resets to the default theme. Additionally, the system prefers-color-scheme setting is not respected on first load — users who prefer dark mode in their OS get a blinding white screen.

Problem

In frontend/src/theme.js, the theme is stored in component state only — it resets on reload.

Acceptance Criteria

  • On first load: check localStorage.getItem('trivela:theme'); if absent, check window.matchMedia('(prefers-color-scheme: dark)').matches and use the OS preference
  • On theme toggle: save to localStorage so next load respects the choice
  • Listen for OS theme changes (matchMedia.addEventListener('change', ...)) and auto-update if user has not manually set a preference
  • Apply theme class to <html> element (not <body>) to prevent FOUC (Flash of Unstyled Content) — move theme initialization to index.html <script> in <head>
  • Unit tests: OS dark preference sets dark mode, manual override persists, toggle saves to localStorage

References

  • frontend/src/theme.js
  • frontend/index.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions