Skip to content

feat: add Auto/Light/Dark color mode switcher to settings - #510

Merged
antfu merged 3 commits into
mainfrom
feat/color-mode-switcher
Aug 4, 2026
Merged

feat: add Auto/Light/Dark color mode switcher to settings#510
antfu merged 3 commits into
mainfrom
feat/color-mode-switcher

Conversation

@antfubot

@antfubot antfubot commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Description

Adds a color mode control (Auto / Light / Dark) to Settings → Appearance that themes both the Vite DevTools shell and its inner integration panels (iframes), persisted to localStorage.

How it works

  • The switcher writes to the vite-devtools-color-scheme localStorage key — the same key the Nuxt integration apps (Rolldown/Vite/Oxc) already read via @vitejs/devtools-ui/composables/dark. Because those iframes are served same-origin, the write fires a storage event that each iframe picks up, so one switch re-themes the shell and every inner integration at once.
  • The webcomponents dock shell previously followed the OS only (dark: 'media'), which can't be overridden. It now uses class-based dark (dark: 'class'), and each shell root is wrapped in a new ColorSchemeRoot (display: contents) that carries .dark/.light + color-scheme. This makes .dark … utilities resolve inside the shadow root and the light-DOM standalone page identically, and preserves the shared theme's specificity-boost contract (e.g. .dark .bg-base).
  • Auto defers to prefers-color-scheme; Light/Dark are explicit overrides.

Changes

  • state/color-mode.ts (new)colorSchemePreference (persisted), isDark, setColorSchemePreference.
  • dock/ColorSchemeRoot.vue (new) — the .dark/.light + color-scheme wrapper.
  • SettingsAppearance.vue — the Auto/Light/Dark segmented control.
  • DockEmbedded.vue / DockStandalone.vue — wrapped in ColorSchemeRoot.
  • standalone/App.vue — mirrors the mode onto <html> (visible page canvas).
  • uno.config.tsdark: 'media'dark: 'class'.
  • popup.ts — popup color-scheme now watches shared isDark.
  • icons/ViteDevTools.vue — logo color follows the preference.

Linked Issues

Additional context

lint, test, typecheck, and build all pass. Reviewers may want to focus on the shadow-DOM class-based dark approach (the ColorSchemeRoot wrapper) and the localStorage-key sharing that drives the iframes. Live browser click-through wasn't run (no Chromium available in the dev container).

This PR was created with the help of an agent.

Adds a color-mode control to Settings → Appearance that themes the
DevTools shell and its inner integration iframes together, persisted to
localStorage under the shared `vite-devtools-color-scheme` key (the same
key the Nuxt plugin apps already read), so one switch re-themes
everything via storage events.

The shell moves from OS-only `dark: 'media'` to class-based dark, with a
`ColorSchemeRoot` wrapper carrying `.dark`/`.light` so utilities resolve
inside the shadow DOM and the light-DOM standalone page alike.
@pkg-pr-new

pkg-pr-new Bot commented Aug 4, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@510

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@510

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@510

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@510

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@510

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@510

commit: 50023a3

@antfu
antfu merged commit 6c99273 into main Aug 4, 2026
10 checks passed
@antfu
antfu deleted the feat/color-mode-switcher branch August 4, 2026 00:50
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.

2 participants