Skip to content

Commit c487dba

Browse files
committed
fix(theme): default to light theme for new users
New visitors now always start with the light theme instead of following the OS setting. Users can still switch to "System" in Settings → Appearance to follow their OS preference. Changes: - themeStore default preference: "system" → "light" - Anti-FOUC script fallback: "system" → "light" - Theme doc: marked §7.4 (root variables) and §7.5 (PWA theme-color) as fixed — both were already resolved in code but the doc still listed them as open issues
1 parent 03a5820 commit c487dba

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

Notes/Theme_Light_Dark.md

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ themeStore.ts (single source of truth)
9090
| 🌙 Dark | `"dark"` | `docsplus-dark` | Always dark |
9191
| 🎯 Dark HC | `"dark-hc"` | `docsplus-dark-hc` | High contrast dark for projectors |
9292

93+
**Default: `"light"`** — new users see the light theme on first visit. The "System" option is available in Settings → Appearance for users who prefer to follow their OS setting.
94+
9395
**Anti-FOUC inline script** in `_document.tsx` runs before React hydration:
9496
```js
9597
// Reads persisted Zustand state from localStorage and applies data-theme immediately
96-
var p = (state.preference) || 'system';
98+
var p = (state.preference) || 'light';
9799
var t = p==='dark-hc' ? 'docsplus-dark-hc'
98100
: p==='dark' ? 'docsplus-dark'
99101
: p==='light' ? 'docsplus'
@@ -435,7 +437,7 @@ Since the theme toggle is instant, `prefers-reduced-motion` has no bearing on it
435437
| 🌙 Dark | `"dark"` | `docsplus-dark` | Always dark, ignores OS setting |
436438
| 🎯 Dark HC | `"dark-hc"` | `docsplus-dark-hc` | High contrast dark for projectors/classrooms |
437439

438-
**Default: `"system"`**respects the user's OS-level accessibility and comfort settings out of the box.
440+
**Default: `"light"`**new users always start with the light theme. Users can switch to "System" in Settings → Appearance to follow their OS preference.
439441

440442
**Implementation (complete):**
441443

@@ -476,28 +478,35 @@ Components using `bg-white`, `text-gray-*`, `bg-[#hex]` instead of semantic toke
476478
<div className="bg-base-100 text-base-content/60 border-base-300">
477479
```
478480

479-
### 7.4 ⚠️ `:root` Variables Not Theme-Aware
481+
### 7.4 ✅ `:root` Variables Now Theme-Aware (Fixed 2026-02-16)
482+
483+
Previously, `:root` hardcoded `--color-docsy: #2778ff` and `--caret-color: #2778ff`, which broke the caret and brand color in dark mode.
480484

485+
**What was fixed:**
481486
```scss
482487
:root {
483-
--color-docsy: #2778ff; /* Always brand blue, even in dark mode */
484-
--caret-color: #2778ff; /* Blue caret on dark blue canvas = poor visibility */
488+
--color-docsy: var(--color-primary);
489+
--caret-color: var(--color-primary);
490+
--caret-color-inverse: var(--color-primary-content);
485491
}
486492
```
487493

488-
**Fix:** Replace with `caret-color: var(--color-primary)` in `.ProseMirror`, or move values into theme blocks.
494+
Both resolve to the active theme's primary color, so the caret and brand color adapt automatically in all three themes.
489495

490-
### 7.5 ⚠️ PWA `theme-color` Is Static
496+
### 7.5 ✅ PWA `theme-color` Is Now Dynamic (Fixed 2026-02-16)
497+
498+
Previously, a single static `theme-color` meta tag was used. Now `_document.tsx` ships two tags with `prefers-color-scheme` media queries:
491499

492500
```tsx
493-
const THEME_COLOR = '#2778ff' // Always brand blue, regardless of theme
494-
```
501+
const THEME_COLOR_LIGHT = '#fafbfc' // base-100 light
502+
const THEME_COLOR_DARK = '#0b1220' // base-100 dark
495503

496-
**Fix:** Add a second meta tag:
497-
```html
498-
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#0b1220" />
504+
<meta name="theme-color" content={THEME_COLOR_LIGHT} media="(prefers-color-scheme: light)" />
505+
<meta name="theme-color" content={THEME_COLOR_DARK} media="(prefers-color-scheme: dark)" />
499506
```
500507

508+
The browser chrome, status bar, and task switcher now match the active OS color scheme.
509+
501510
### 7.6 ✅ Overlay Component Dark Mode Compliance (Fixed 2026-02-16)
502511

503512
Multiple overlay/floating components were invisible or poorly visible in dark mode because they lacked borders, used insufficient shadows, or used `base-100` (which matches the dark page background).

packages/webapp/src/pages/_document.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export default function Document() {
100100
This is the same approach used by next-themes and GitHub. */}
101101
<script
102102
dangerouslySetInnerHTML={{
103-
__html: `(function(){try{var s=JSON.parse(localStorage.getItem('docsplus-theme')||'{}');var p=(s.state&&s.state.preference)||'system';var t=p==='dark-hc'?'docsplus-dark-hc':p==='dark'?'docsplus-dark':p==='light'?'docsplus':window.matchMedia('(prefers-color-scheme:dark)').matches?'docsplus-dark':'docsplus';document.documentElement.setAttribute('data-theme',t)}catch(e){}})()`
103+
__html: `(function(){try{var s=JSON.parse(localStorage.getItem('docsplus-theme')||'{}');var p=(s.state&&s.state.preference)||'light';var t=p==='dark-hc'?'docsplus-dark-hc':p==='dark'?'docsplus-dark':p==='light'?'docsplus':window.matchMedia('(prefers-color-scheme:dark)').matches?'docsplus-dark':'docsplus';document.documentElement.setAttribute('data-theme',t)}catch(e){}})()`
104104
}}
105105
/>
106106
<Main />

packages/webapp/src/stores/themeStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ type ThemeStorePersist = (
5959
export const useThemeStore = create<ThemeStore>(
6060
(persist as ThemeStorePersist)(
6161
(set) => ({
62-
preference: 'system',
62+
preference: 'light',
6363
resolvedTheme: 'docsplus',
6464
hydrated: false,
6565

0 commit comments

Comments
 (0)