feat: theme-aware favicons (light + dark variants for every format) - #8
Merged
Conversation
The previous favicons shipped a single light variant for every format.
On dark browser chrome, dark OS chrome, or dark iOS home screens, they
looked dim and off-brand.
This PR ships paired light/dark variants for every favicon format and
wires them up to follow both prefers-color-scheme AND the manual
[data-theme] toggle:
Files (all in public/, paired light + dark):
- favicon-{light,dark}.svg — scalable, for modern browsers
- favicon-{light,dark}-96x96.png — PNG fallback
- favicon-{light,dark}.ico — multi-res ICO for legacy
- apple-touch-icon-{light,dark}.png — iOS home screen (180px)
- web-app-manifest-{light,dark}-{192x192,512x512}.png — PWA
Dropped: favicon.svg, favicon-96x96.png, favicon.ico, apple-touch-icon.png
(the single-variant versions).
Mechanism:
- BaseLayout emits one link per slot with data-favicon="svg|png|ico|apple",
defaulting to the light variant.
- An inline pre-paint script resolves the theme (stored localStorage OR
matchMedia) and rewrites each link's href to the matching variant.
- matchMedia listener re-applies on system theme change.
- ThemeToggle calls window.__applyClaricleFavicons(next) on click so
manual toggles update the favicon without a page reload.
Manifest also fixed up: name/short_name corrected from the RealFaviconGenerator
placeholder, light icons registered as purpose:"any" + dark as purpose:"maskable"
(PWA spec doesn't support theme-aware icons, so both are listed).
Per the canonical asset hierarchy, originals for these live in
claricle/branding and will be synced in a follow-up.
Tested:
- 99 vitest specs pass (added: paired-variant existence + BaseLayout
applies favicons based on resolved theme).
- Manual: system light -> light favicons everywhere, system dark -> dark,
manual light on dark-pref system -> light everywhere, manual dark on
light-pref system -> dark everywhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ships paired light + dark favicons for every format and wires them up to follow both
prefers-color-schemeAND the manual[data-theme]toggle.Files (all in
public/, paired)favicon-{light,dark}.svg— scalable, modern browsersfavicon-{light,dark}-96x96.png— PNG fallbackfavicon-{light,dark}.ico— multi-res ICO, legacy contextsapple-touch-icon-{light,dark}.png— iOS home screen (180px)web-app-manifest-{light,dark}-{192x192,512x512}.png— PWA manifest iconsDropped the old single-variant
favicon.svg,favicon-96x96.png,favicon.ico,apple-touch-icon.png.Mechanism (no
<link media>— JS-driven so the manual toggle works)BaseLayoutemits one<link>per slot withdata-favicon="svg|png|ico|apple", defaulting to the light variant.matchMedia) and rewrites each link'shrefto the matching variant.matchMedialistener re-applies on system theme change.ThemeTogglecallswindow.__applyClaricleFavicons(next)on click so manual toggles update favicons without a page reload.Reference: favicon.im blog — for sites with custom theme controls, the HTML-only
<link media>approach is insufficient because it can't see the[data-theme]attribute. JS is required to override.Manifest
site.webmanifestcorrected:MyWebSite→Claricle. Light icons registered aspurpose: "any", dark aspurpose: "maskable"(PWA spec doesn't support theme-aware icons — both are listed, platform picks one).Branding repo
Originals for these will be synced to
claricle/brandingin a follow-up PR (per the canonical asset hierarchy).Test plan
/favicon-light.svg,/favicon-dark.svg, etc.