Skip to content

feat(web): add dark mode toggle - #77

Merged
mankatcheung merged 3 commits into
mainfrom
feature/jef-30-dark-mode-toggle
Jul 23, 2026
Merged

mankatcheung merged 3 commits into
mainfrom
feature/jef-30-dark-mode-toggle

Conversation

@mankatcheung

@mankatcheung mankatcheung commented Jul 23, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Adds a ThemeProvider (light/dark/system) with localStorage persistence, keyed as theme
  • Enables Tailwind v4's class-based dark: variant (@custom-variant dark (&:where(.dark, .dark *));) — previously only the media-query variant was active, so there was no way to override the OS preference
  • Adds a three-way segmented control (Light / Dark / System) in Account settings → Appearance
  • Adds a quick-access sun/moon/monitor toggle icon in the sidebar (desktop) and mobile header, cycling light → dark → system
  • Applies the theme via an inline <script> in the document head (before hydration) to avoid a flash of the wrong theme on load, and suppresses the resulting (expected, harmless) hydration warning on <html>
  • Adds a global 0.15s transition for background/border/text color for a smooth switch

Closes JEF-30.

Test plan

  • pnpm typecheck and pnpm lint pass with no new errors
  • pnpm build succeeds
  • Manually verified end-to-end in a real browser (registered a user, logged in, exercised the toggle):
    • Segmented control switches Light/Dark/System and updates the whole app immediately
    • Sidebar icon cycles through all three states and stays in sync with the account page control
    • Theme persists in localStorage and survives a full page reload
    • No flash of the wrong theme on reload (verified the dark class is present at domcontentloaded, before hydration)
    • System option respects prefers-color-scheme
    • All pages already carried dark: classes from prior work — confirmed dashboard, account, and sidebar all render correctly in dark mode

Summary by CodeRabbit

  • New Features

    • Added light, dark and system theme options.
    • Added persistent theme selection across sessions.
    • Added theme controls to the account settings and authenticated navigation.
    • Added automatic system theme detection and synchronisation.
    • Added smooth transitions when changing themes.
  • Bug Fixes

    • Prevented an incorrect theme flash while the application loads.

Adds a ThemeProvider (light/dark/system) with localStorage persistence,
a segmented control in account settings, and a quick-access sidebar
toggle icon. Enables Tailwind v4's class-based dark variant and applies
the theme via an inline head script before hydration to avoid a flash
of the wrong theme on load.

Closes JEF-30.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mankatcheung, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 54 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a63ee308-6313-4f54-b258-7a09b59facc9

📥 Commits

Reviewing files that changed from the base of the PR and between aae5ba9 and 3f06025.

📒 Files selected for processing (3)
  • apps/web/src/__tests__/components/AccountPage.test.tsx
  • apps/web/src/__tests__/components/AuthenticatedLayout.test.tsx
  • apps/web/src/__tests__/setup.ts

Walkthrough

The web app adds persisted light, dark, and system theme selection. Theme state is initialised before hydration, provided through React context, exposed in account and authenticated-layout controls, and connected to dark-mode styling with colour transitions.

Changes

Application theme support

Layer / File(s) Summary
Theme state and document initialisation
apps/web/src/lib/theme.tsx, apps/web/src/routes/__root.tsx
Defines theme resolution, persistence, system preference handling, React context, and pre-hydration document initialisation.
Authenticated theme controls
apps/web/src/routes/_authenticated/account.tsx, apps/web/src/routes/_authenticated/route.tsx
Adds appearance settings and cycling theme toggles to authenticated layouts.
Dark variant and transitions
apps/web/src/styles.css
Configures the dark variant and colour transition rules.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RootDocument
  participant ThemeInitScript
  participant ThemeProvider
  participant ThemeControls
  participant documentElement
  RootDocument->>ThemeInitScript: run before hydration
  ThemeInitScript->>documentElement: apply stored or system theme
  RootDocument->>ThemeProvider: provide theme context
  ThemeControls->>ThemeProvider: select or cycle theme
  ThemeProvider->>documentElement: update dark class
Loading

Possibly related issues

  • #70 — This PR implements the described dark-mode provider, persistence, system preference support, document class toggling, and theme controls.

Poem

A bunny hops through light and shade,
With moon and sun in buttons laid.
The system hums, the dark class gleams,
Stored safely alongside dreams.
“Three cheers for themes!” the rabbit sings.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding dark mode support and a theme toggle in the web app.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/jef-30-dark-mode-toggle

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mankatcheung
mankatcheung marked this pull request as ready for review July 23, 2026 22:21
AccountPage and AuthenticatedLayout tests rendered without a
ThemeProvider, and useTheme() throws outside one. Also mocks
window.matchMedia globally for jsdom, which the provider relies on
to resolve the system theme.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/routes/_authenticated/account.tsx`:
- Around line 265-268: Update the shared account-page test render helper to
provide ThemeProvider context before rendering AccountPage, or mock useTheme
consistently in those tests. Ensure direct AccountPage renders no longer throw
while preserving the existing form test behavior.

In `@apps/web/src/styles.css`:
- Around line 19-25: Update the global transition rule for body and its
descendants to respect prefers-reduced-motion: reduce by adding an override that
disables or effectively shortens the color, background-color, and border-color
transitions, while preserving the existing transitions for users without the
preference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4fdf0631-8328-43e5-b6e9-51b5c7dd523e

📥 Commits

Reviewing files that changed from the base of the PR and between d393d6c and aae5ba9.

📒 Files selected for processing (5)
  • apps/web/src/lib/theme.tsx
  • apps/web/src/routes/__root.tsx
  • apps/web/src/routes/_authenticated/account.tsx
  • apps/web/src/routes/_authenticated/route.tsx
  • apps/web/src/styles.css

Comment on lines 265 to +268
export function AccountPage() {
const navigate = useNavigate();
const qc = useQueryClient();
const { theme, setTheme } = useTheme();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Restore the AccountPage test provider.

useTheme() now throws before the existing direct AccountPage renders, causing the reported 31 CI test failures. Wrap the shared account-page test render helper in ThemeProvider (or mock useTheme) so the existing form tests can run.

🧰 Tools
🪛 GitHub Actions: CI / 1_Test.txt

[error] 268-268: useTheme called without a ThemeProvider while rendering AccountPage (triggering: "useTheme must be used within a ThemeProvider").

🪛 GitHub Actions: CI / Test

[error] 268-268: useTheme must be used within a ThemeProvider (thrown while rendering AccountPage during tests)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/routes/_authenticated/account.tsx` around lines 265 - 268,
Update the shared account-page test render helper to provide ThemeProvider
context before rendering AccountPage, or mock useTheme consistently in those
tests. Ensure direct AccountPage renders no longer throw while preserving the
existing form test behavior.

Sources: Linters/SAST tools, Pipeline failures

Comment thread apps/web/src/styles.css
Comment on lines +19 to +25
body,
body * {
transition:
background-color 0.15s ease,
border-color 0.15s ease,
color 0.15s ease;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Respect reduced-motion preferences.

This forces colour transitions on every descendant, including for users who request reduced motion. Add a prefers-reduced-motion: reduce override that disables or effectively shortens these transitions.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/styles.css` around lines 19 - 25, Update the global transition
rule for body and its descendants to respect prefers-reduced-motion: reduce by
adding an override that disables or effectively shortens the color,
background-color, and border-color transitions, while preserving the existing
transitions for users without the preference.

@mankatcheung
mankatcheung merged commit fdc8efb into main Jul 23, 2026
5 checks passed
@mankatcheung
mankatcheung deleted the feature/jef-30-dark-mode-toggle branch July 23, 2026 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant