Skip to content

fix: stale dark class theme bootstrap#2006

Open
elibosley wants to merge 1 commit into
mainfrom
codex/fix-stale-dark-theme-bootstrap
Open

fix: stale dark class theme bootstrap#2006
elibosley wants to merge 1 commit into
mainfrom
codex/fix-stale-dark-theme-bootstrap

Conversation

@elibosley
Copy link
Copy Markdown
Member

@elibosley elibosley commented May 13, 2026

Summary

  • Reconcile root/body .dark classes from the computed dark-mode state when --theme-name is unavailable.
  • Add regression coverage for the fallback path where --theme-dark-mode: 0 is present but stale dark classes remain.

Root Cause

The previous fallback bootstrap path only added dark when dark mode was detected. If --theme-name was missing and the DOM already had stale dark classes, --theme-dark-mode: 0 was not enough to actively remove them.

Impact

Light Unraid themes can no longer keep Tailwind dark styles active just because a stale dark class survived on <html>, <body>, or .unapi containers.

Verification

  • pnpm exec eslint src/store/theme.ts __test__/store/theme.test.ts

Note: pnpm exec vitest run __test__/store/theme.test.ts is currently blocked before test collection by the existing Vue devtools / localStorage test-environment failure: localStorage.getItem is not a function.

Summary by CodeRabbit

  • Tests

    • Added test case verifying dark mode CSS variable handling and cleanup of stale dark mode classes.
  • Refactor

    • Improved dark mode initialization logic for cleaner implementation.

Review Change Stack

Purpose of the change:
- Make the web theme bootstrap remove stale dark classes when the server only provides --theme-dark-mode: 0.

How behavior was before:
- When --theme-name was unavailable, bootstrap only added dark if dark mode was detected.
- A stale html/body dark class could remain even while --theme-dark-mode was 0.

Why that was a problem:
- Light Unraid themes could still render Tailwind dark styles after a stale class survived on the page root.

What the new change accomplishes:
- Treats the computed dark-mode state as authoritative in the fallback path and reconciles both add and remove cases.
- Adds regression coverage for a light CSS variable with stale dark classes.

How it works:
- Reuses applyDarkClass(isDarkModeActive(), darkMode) when --theme-name is missing so the existing sync path updates html, body, .unapi, and the store state together.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 13, 2026

Walkthrough

This PR refactors dark-mode initialization in the theme store by removing an internal helper function and directly calling applyDarkClass() during store setup. A test case is added to verify that stale dark-mode classes are properly cleaned from the DOM when the CSS variable is set to '0'.

Changes

Dark Mode Initialization

Layer / File(s) Summary
Simplify dark mode initialization and add test coverage
web/src/store/theme.ts, web/__test__/store/theme.test.ts
The bootstrapDarkClass helper is removed; initialization now directly calls applyDarkClass(isDarkModeActive(), darkMode) when no DOM theme name is present. A new test verifies that pre-existing 'dark' classes are removed from both document.documentElement and document.body when --theme-dark-mode is '0', and that store.darkMode becomes false.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A helper gone, the dark mode flows clear,
Direct and true without a care,
Stale classes swept from the DOM's keep,
Tests verify the promise deep!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Title check ✅ Passed The title directly addresses the main change: fixing stale dark class removal during theme bootstrap. It concisely captures the core problem and solution.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-stale-dark-theme-bootstrap

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.58%. Comparing base (a2d4843) to head (d5cf623).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2006      +/-   ##
==========================================
- Coverage   52.59%   52.58%   -0.01%     
==========================================
  Files        1033     1033              
  Lines       71682    71676       -6     
  Branches     8181     8176       -5     
==========================================
- Hits        37698    37688      -10     
- Misses      33858    33862       +4     
  Partials      126      126              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions
Copy link
Copy Markdown
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR2006/dynamix.unraid.net.plg

@elibosley elibosley changed the title [codex] Fix stale dark class theme bootstrap fix: stale dark class theme bootstrap May 13, 2026
@elibosley elibosley marked this pull request as ready for review May 13, 2026 21:04
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