fix(web): match the iOS status bar to the theme picked in the app

The theme-color metas used prefers-color-scheme media queries, so they
followed the OS theme and ignored the in-app choice. Use a single meta
that the pre-paint script and ThemeProvider update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-10-20 19:24:38 -03:00
parent 5abdb08204
commit 71793dbd3a
2 changed files with 12 additions and 2 deletions

View File

@@ -8,8 +8,9 @@
name="viewport"
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
/>
<meta name="theme-color" media="(prefers-color-scheme: light)" content="#f9f8f5" />
<meta name="theme-color" media="(prefers-color-scheme: dark)" content="#0f1411" />
<!-- Set from the resolved theme (script below and `theme-provider.tsx`), not with
`media` queries: those follow the OS and ignore the theme picked in the app. -->
<meta name="theme-color" content="#f9f8f5" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
@@ -28,6 +29,9 @@
stored === 'dark' || (stored !== 'light' && matchMedia('(prefers-color-scheme: dark)').matches)
document.documentElement.classList.toggle('dark', dark)
document.documentElement.style.colorScheme = dark ? 'dark' : 'light'
document
.querySelector('meta[name="theme-color"]')
.setAttribute('content', dark ? '#0f1411' : '#f9f8f5')
})()
</script>
</head>

View File

@@ -16,6 +16,9 @@ type ThemeContextValue = {
const STORAGE_KEY = 'superlist-theme'
const DARK_QUERY = '(prefers-color-scheme: dark)'
/** Browser chrome color (the iOS status bar) per theme. Keep in sync with `index.html`. */
const THEME_COLORS: Record<ResolvedTheme, string> = { light: '#f9f8f5', dark: '#0f1411' }
/**
* This theme handling is hand-rolled on purpose. Libraries such as `next-themes`
* avoid the pre-paint flash by rendering a `<script>` from React, but React 19
@@ -60,6 +63,9 @@ export function ThemeProvider({ children }: { children: ReactNode }) {
const root = document.documentElement
root.classList.toggle('dark', resolvedTheme === 'dark')
root.style.colorScheme = resolvedTheme
document
.querySelector('meta[name="theme-color"]')
?.setAttribute('content', THEME_COLORS[resolvedTheme])
}, [resolvedTheme])
const setTheme = useCallback((next: Theme) => {