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.
This commit is contained in:
2026-02-06 18:47:13 +01:00
parent 7c4754e506
commit e975d7aa25

View File

@@ -4,7 +4,8 @@ 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)
async function bootstrap() {
// ✅ Theme sofort setzen
try {
const key = localStorage.getItem("hpTheme:guest") || DEFAULT_THEME_KEY;
applyTheme(key);
@@ -12,17 +13,29 @@ try {
applyTheme(DEFAULT_THEME_KEY);
}
// ✅ Preload Unlock (nach Theme!)
// ✅ 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(<App />);
// ✅ Service Worker NUR EINMAL registrieren
const updateSW = registerSW({
// ✅ Service Worker KEIN Auto-Reload mehr
registerSW({
immediate: true,
onNeedRefresh() {
updateSW(true);
window.location.reload();
console.info("Neue Version verfügbar Reload manuell");
// optional: später Toast „Update verfügbar“
},
});
}
bootstrap();