---
name: fix-dark-leaks
description: Find and seal every dark-mode leak in your web app: blinding white native date pickers, selects, and scrollbars (missing color-scheme: dark), white flash on reload (FOUC), hardcoded bg-white/text-black/#hex inside modals and empty states, low-contrast unpaired status colors, disappearing borders, and black SVGs on dark surfaces. Works on any React, Next.js, Vue, Svelte, Astro, or plain CSS/Tailwind app.
license: MIT
metadata:
  author: Hairline UI
  url: https://hairlineui.com/skills/fix-dark-leaks
  version: "1.0.0"
---

# /fix-dark-leaks

Find and seal every light-mode leak in your app's dark theme: blinding white OS date pickers, selects, and scrollbars, white reload flashes, hardcoded white cards or tooltips, unreadable status colors, invisible borders, and black SVGs that disappear into dark backgrounds.

This skill is **zero-redesign and zero-lock-in**. It keeps your existing color system, brand palette, and layout intact, fixing every leak with native CSS and your project's own dark tokens.

## Guardrails (never break these)

- **Keep light mode intact.** Never replace a light-mode class with a dark-only value (`bg-white` → `bg-zinc-950` breaks light mode!). Always replace with a semantic token (`bg-background`, `bg-card`, `bg-popover`, `text-foreground`) or add a `dark:` pair (`bg-white dark:bg-zinc-900`).
- **Do not break intentional high-contrast surfaces** such as QR codes, print previews, white logos on brand badges, or primary buttons whose contrast is intentional.
- **Respect the project's dark-mode mechanism:** detect whether the app uses a `.dark` class, `[data-theme="dark"]`, or `@media (prefers-color-scheme: dark)` before writing a single rule.
- **Never add external dependencies or UI libraries.** Every fix is pure CSS, HTML, and your existing tokens.
- **Never report a fix you did not verify in Chromium.**

---

## Step 1 — Measure the baseline (browser + source scan)

### 1A. Run the Chromium dark-leaks verifier (recommended)

With your local dev server running, fetch and run the verifier across your key routes in dark mode:

```bash
curl -sL https://hairlineui.com/skills/fix-dark-leaks-check.mjs -o /tmp/fix-dark-leaks-check.mjs
node /tmp/fix-dark-leaks-check.mjs http://localhost:3000 --routes /,/settings,/login
```

*(If your app requires clicking a toggle instead of following `prefers-color-scheme: dark`, pass `--toggle "button[aria-label*='theme' i]"` or `--dark-class .dark`.)*

Save the baseline numbers: reload FOUC flash, missing `color-scheme: dark` controls, bright surface leaks, WCAG contrast failures, and dark-on-dark invisible icons/borders.

### 1B. Static source scan

Run these from the project root and record the hit counts:

```bash
G='-g *.{tsx,jsx,ts,js,vue,svelte,astro,html} -g !node_modules -g !.next -g !dist'

# 1. Check whether color-scheme: dark is declared anywhere in CSS
rg -n 'color-scheme\s*:\s*dark' -g '*.css' -g '!node_modules' -g '!.next' -g '!dist' .

# 2. Hardcoded light backgrounds without a dark: counterpart on the same line
rg -n '\b(bg-white|bg-slate-50|bg-gray-50|bg-zinc-50|bg-neutral-50|bg-stone-50)\b' $G . | rg -v '\bdark:bg-'

# 3. Hardcoded dark text without a dark: counterpart on the same line
rg -n '\b(text-black|text-slate-900|text-gray-900|text-zinc-900|text-neutral-900|text-gray-800|text-slate-800)\b' $G . | rg -v '\bdark:text-'

# 4. Hardcoded light borders without a dark: counterpart
rg -n '\b(border-gray-200|border-slate-200|border-zinc-200|border-neutral-200|border-gray-300)\b' $G . | rg -v '\bdark:border-'

# 5. Unpaired saturated status text/backgrounds that fail contrast on dark surfaces
rg -n '\btext-(red|rose|emerald|green|amber|blue|indigo)-(600|700|800)\b' $G . | rg -v '\bdark:text-'
rg -n '\bbg-(red|rose|emerald|green|amber|blue|indigo)-(50|100)\b' $G . | rg -v '\bdark:bg-'

# 6. Raw hex fills/strokes in SVGs and inline styles (#000 / #fff / #111 / #333)
rg -n '(fill|stroke|color|background)\s*[:=]\s*["\x27]?#(000(000)?|fff(fff)?|111(111)?|222(222)?|333(333)?)\b' $G .
```

---

## Step 2 — Seal every dark-mode leak

### 2.1 Native controls, date pickers, `<select>`, autofill, and scrollbars

Without `color-scheme: dark`, the browser paints OS-level UI in bright white even when your entire page is dark: `<input type="date">`, `<input type="time">`, `<select>` option menus, scrollbars, checkboxes, and browser autofill highlights.

- **Fix:** Set `color-scheme: dark` on the dark root selector in your global CSS:
  ```css
  /* Class-based dark mode (.dark or [data-theme="dark"]) */
  :root {
    color-scheme: light;
  }
  .dark,
  [data-theme="dark"] {
    color-scheme: dark;
  }

  /* If the app follows OS preference automatically */
  @media (prefers-color-scheme: dark) {
    :root:not(.light) {
      color-scheme: dark;
    }
  }
  ```
- **Browser autofill yellow/white box fix:** If inputs turn blinding white/blue on Chrome autofill in dark mode, style `input:-webkit-autofill` using a subtle inset shadow matching your input token:
  ```css
  .dark input:-webkit-autofill,
  .dark textarea:-webkit-autofill,
  .dark select:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px var(--background, #18181b) inset;
    -webkit-text-fill-color: var(--foreground, #fafafa);
    caret-color: var(--foreground, #fafafa);
  }
  ```

### 2.2 White flash on reload (pre-hydration FOUC)

If your theme is stored in `localStorage` and applied inside a `useEffect`, the browser paints a full white frame before JavaScript hydrates.

- **Fix:** Add a tiny synchronous inline script in `<head>` (in `app/layout.tsx` or `index.html`) that sets the dark class **and** `color-scheme` before first paint, and put `suppressHydrationWarning` on `<html>`:
  ```html
  <script>
    (function () {
      try {
        var t = localStorage.getItem('theme');
        var dark = t === 'dark' || ((!t || t === 'system') && matchMedia('(prefers-color-scheme: dark)').matches);
        document.documentElement.classList.toggle('dark', dark);
        document.documentElement.style.colorScheme = dark ? 'dark' : 'light';
      } catch (e) {}
    })();
  </script>
  ```
  *(Match the exact `localStorage` key and class/attribute your app already uses — never invent a second key.)*

### 2.3 Hardcoded light surfaces, text, and borders

Replace hardcoded utilities with the project's own semantic tokens first (if using shadcn/Tailwind CSS variables), or explicit `dark:` pairs if using raw Tailwind palette classes:

| Leak | Semantic token fix (preferred) | Explicit Tailwind pair (if no tokens) |
| --- | --- | --- |
| `bg-white` | `bg-background` or `bg-card` or `bg-popover` | `bg-white dark:bg-zinc-900` |
| `bg-gray-50` / `bg-slate-50` | `bg-muted` | `bg-gray-50 dark:bg-zinc-900/60` |
| `text-black` / `text-gray-900` | `text-foreground` | `text-gray-900 dark:text-zinc-100` |
| `text-gray-500` / `text-gray-600` | `text-muted-foreground` | `text-gray-600 dark:text-zinc-400` |
| `border-gray-200` / `border-gray-300` | `border-border` | `border-gray-200 dark:border-white/10` |

Check **modals, popovers, dropdown menus, tooltips, command palettes, empty states, toasts, and skeleton loaders** specifically — these are where `bg-white` hides most often because they aren't visible on initial render.

### 2.4 Unpaired status colors & contrast failures

Colors that pass WCAG AA on white (`text-red-600`, `text-emerald-600`, `text-amber-700`, `text-blue-600`) drop below `4.5:1` on dark `#18181b` / `#191919` cards, and `bg-red-50` / `bg-amber-50` badges glow like headlights in dark mode.

- **Fix status text** with lighter `dark:` steps (`>= 4.5:1` contrast):
  - `text-red-600 dark:text-red-400`
  - `text-emerald-600 dark:text-emerald-400`
  - `text-amber-700 dark:text-amber-400`
  - `text-blue-600 dark:text-blue-400`
- **Fix tinted status banners/badges:**
  - `bg-red-50 text-red-700 dark:bg-red-500/15 dark:text-red-300`
  - `bg-emerald-50 text-emerald-700 dark:bg-emerald-500/15 dark:text-emerald-300`
  - `bg-amber-50 text-amber-800 dark:bg-amber-500/15 dark:text-amber-300`
- **Check Tailwind v4 custom dark variant:** If the app uses Tailwind v4 with class-based dark mode (`.dark`), verify globals.css declares:
  ```css
  @custom-variant dark (&:where(.dark, .dark *));
  ```
  Without this line in Tailwind v4, every `dark:` class ignores `.dark` and only responds to OS preference!

### 2.5 Disappearing borders, inputs, shadows, and black SVGs

- **Black SVGs & brand marks:** Replace hardcoded `fill="#000"`, `fill="black"`, `stroke="#111"` on monochrome icons and wordmarks with `currentColor`. For raster dark logos (`<img>`), swap source or apply `dark:invert` only on monochrome black-only marks (never on multicolored logos or photos).
- **Invisible unchecked checkboxes, inputs, and cards on dark backgrounds:** Ensure dark borders have at least `rgba(255, 255, 255, 0.10)`–`0.14` (and `0.18`–`0.24` on unchecked inputs/checkboxes so control boundaries remain visible).
- **Vanishing shadows on floating popovers/menus:** Outer drop shadows disappear on `#18181b` surfaces. Pair floating dark surfaces with a subtle 1px edge (`dark:border-white/10` or `dark:ring-1 dark:ring-white/10`) and a slightly lifted background tone.

---

## Step 3 — Verify in both themes

1. Run your project's typecheck and build.
2. Re-run the dark-leaks verifier across the same routes:
   ```bash
   node /tmp/fix-dark-leaks-check.mjs http://localhost:3000 --routes /,/settings,/login
   ```
3. Visually check **both dark mode and light mode** (including opening modals, dropdowns, date fields, and error states) to confirm zero dark leaks and zero light-mode regressions.

---

## Step 4 — Report (keep it tight)

```text
/fix-dark-leaks — verified in dark and light mode

  White reload flash (FOUC):        yes → no
  Native controls missing dark:       5 → 0  (color-scheme: dark)
  Bright surface leaks:               7 → 0
  WCAG contrast failures (<4.5:1):   11 → 0
  Dark-on-dark SVGs / icons:          3 → 0

Files changed:
- src/app/globals.css — added color-scheme: dark + autofill override + @custom-variant dark
- src/app/layout.tsx — inline pre-paint theme script (eliminated 180ms white flash)
- src/components/BillingModal.tsx — replaced bg-white/text-gray-900 with semantic tokens
- src/components/StatusBadge.tsx — paired status text with dark:*-400 (>= 6.2:1 contrast)

Not checked:
- Embedded third-party Stripe iframe
```
