From e975d7aa252874232ff5a931f31afe4864d59d13 Mon Sep 17 00:00:00 2001 From: nessi Date: Fri, 6 Feb 2026 18:47:13 +0100 Subject: [PATCH] Set up immediate theme application and manual SW updates Moved theme application logic to occur immediately on app initialization to prevent UI flash. Added a check to wait for all fonts to load before making the app visible and adjusted Service Worker behavior to require manual updates instead of auto-reloading. --- frontend/src/main.jsx | 53 +++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/frontend/src/main.jsx b/frontend/src/main.jsx index 7c3d36e..0a6689c 100644 --- a/frontend/src/main.jsx +++ b/frontend/src/main.jsx @@ -4,25 +4,38 @@ import App from "./App.jsx"; import { applyTheme, DEFAULT_THEME_KEY } from "./styles/themes"; import { registerSW } from "virtual:pwa-register"; -// ✅ Theme VOR React setzen (kein Theme-Flash) -try { - const key = localStorage.getItem("hpTheme:guest") || DEFAULT_THEME_KEY; - applyTheme(key); -} catch { - applyTheme(DEFAULT_THEME_KEY); +async function bootstrap() { + // ✅ Theme sofort setzen + try { + const key = localStorage.getItem("hpTheme:guest") || DEFAULT_THEME_KEY; + applyTheme(key); + } catch { + applyTheme(DEFAULT_THEME_KEY); + } + + // ✅ Warten bis ALLE Fonts geladen sind + try { + if (document.fonts && document.fonts.ready) { + await document.fonts.ready; + } + } catch { + // ignore + } + + // ✅ Erst JETZT sichtbar machen + document.body.classList.remove("preload"); + document.body.classList.add("ready"); + + ReactDOM.createRoot(document.getElementById("root")).render(); + + // ✅ Service Worker – KEIN Auto-Reload mehr + registerSW({ + immediate: true, + onNeedRefresh() { + console.info("Neue Version verfügbar – Reload manuell"); + // optional: später Toast „Update verfügbar“ + }, + }); } -// ✅ Preload Unlock (nach Theme!) -document.body.classList.remove("preload"); -document.body.classList.add("ready"); - -ReactDOM.createRoot(document.getElementById("root")).render(); - -// ✅ Service Worker NUR EINMAL registrieren -const updateSW = registerSW({ - immediate: true, - onNeedRefresh() { - updateSW(true); - window.location.reload(); - }, -}); +bootstrap();