From 86d4796d88fb7473d82eb0bbb82c47274a3350db Mon Sep 17 00:00:00 2001 From: Jose Selesan Date: Tue, 20 Oct 2026 20:10:03 -0300 Subject: [PATCH] fix(web): reload the installed iOS app when the theme changes An iOS home-screen app only reads theme-color on page load, so updating the meta in place left the status bar with the previous theme's color. Reload when the resolved theme changes; the pre-paint script applies the stored theme before the first paint. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/theme-provider.tsx | 33 ++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/theme-provider.tsx b/apps/web/src/components/theme-provider.tsx index 3ede646..0c65b36 100644 --- a/apps/web/src/components/theme-provider.tsx +++ b/apps/web/src/components/theme-provider.tsx @@ -47,6 +47,15 @@ function systemTheme(): ResolvedTheme { return window.matchMedia(DARK_QUERY).matches ? 'dark' : 'light' } +function resolveTheme(theme: Theme): ResolvedTheme { + return theme === 'system' ? systemTheme() : theme +} + +/** iOS home-screen app (`navigator.standalone` only exists in iOS Safari). */ +function isIosStandalone() { + return 'standalone' in navigator && navigator.standalone === true +} + export function ThemeProvider({ children }: { children: ReactNode }) { const [theme, setThemeState] = useState(readStoredTheme) const [systemDark, setSystemDark] = useState(() => systemTheme() === 'dark') @@ -68,14 +77,22 @@ export function ThemeProvider({ children }: { children: ReactNode }) { ?.setAttribute('content', THEME_COLORS[resolvedTheme]) }, [resolvedTheme]) - const setTheme = useCallback((next: Theme) => { - setThemeState(next) - try { - window.localStorage.setItem(STORAGE_KEY, next) - } catch { - // Ignore storage failures: the theme still applies for this session. - } - }, []) + const setTheme = useCallback( + (next: Theme) => { + setThemeState(next) + try { + window.localStorage.setItem(STORAGE_KEY, next) + } catch { + // Ignore storage failures: the theme still applies for this session. + } + + // An installed iOS app only reads `theme-color` when the page loads, so + // the status bar keeps the old color until a reload. The stored theme is + // applied again before the first paint by the script in `index.html`. + if (isIosStandalone() && resolveTheme(next) !== resolvedTheme) window.location.reload() + }, + [resolvedTheme], + ) const value = useMemo( () => ({ theme, resolvedTheme, setTheme }),