From 6b41c11f30ca7c87b69c65f27e07943b72c51dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 8 Oct 2026 21:39:56 +0200 Subject: [PATCH] fix(pwa): set the status-bar colour with the theme before first paint The theme-color tags were rewritten to the app's theme only after hydration, so with a light system and the app in dark mode the status bar stayed light on a cold start. The existing boot script now sets them along with the theme class, and once more after parsing in case the tags stream in after it. --- src/app/layout.tsx | 9 ++-- src/lib/pwa/__tests__/theme-color.test.ts | 53 ++++++++++++++++++++++- src/lib/pwa/theme-color.ts | 11 +++++ 3 files changed, 67 insertions(+), 6 deletions(-) diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 8ce442359..57e112094 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -9,7 +9,7 @@ import { MonitoringBootstrap } from "@/components/monitoring/bootstrap"; import { WebVitalsReporter } from "@/components/monitoring/web-vitals-reporter"; import { resolveInitialLocale } from "@/lib/i18n/resolve-initial-locale"; import { isKeyMismatch } from "@/lib/boot/key-mismatch-state"; -import { THEME_COLOR } from "@/lib/pwa/theme-color"; +import { THEME_BOOT_SCRIPT, THEME_COLOR } from "@/lib/pwa/theme-color"; import { KeyMismatchPage } from "./key-mismatch-page"; const inter = Inter({ @@ -80,9 +80,6 @@ export const viewport: Viewport = { ], }; -// Inline script to apply theme before first paint (prevents FOUC) -const themeScript = `(function(){try{var t=localStorage.getItem("healthlog-theme");var c=(t==="light"||t==="dark")?t:(t==="system"?(window.matchMedia("(prefers-color-scheme:dark)").matches?"dark":"light"):"dark");document.documentElement.classList.add(c)}catch(e){document.documentElement.classList.add("dark")}})()`; - export default async function RootLayout({ children, }: Readonly<{ @@ -101,7 +98,9 @@ export default async function RootLayout({