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:
@@ -4,25 +4,38 @@ import App from "./App.jsx";
|
|||||||
import { applyTheme, DEFAULT_THEME_KEY } from "./styles/themes";
|
import { applyTheme, DEFAULT_THEME_KEY } from "./styles/themes";
|
||||||
import { registerSW } from "virtual:pwa-register";
|
import { registerSW } from "virtual:pwa-register";
|
||||||
|
|
||||||
// ✅ Theme VOR React setzen (kein Theme-Flash)
|
async function bootstrap() {
|
||||||
try {
|
// ✅ Theme sofort setzen
|
||||||
|
try {
|
||||||
const key = localStorage.getItem("hpTheme:guest") || DEFAULT_THEME_KEY;
|
const key = localStorage.getItem("hpTheme:guest") || DEFAULT_THEME_KEY;
|
||||||
applyTheme(key);
|
applyTheme(key);
|
||||||
} catch {
|
} catch {
|
||||||
applyTheme(DEFAULT_THEME_KEY);
|
applyTheme(DEFAULT_THEME_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ Preload Unlock (nach Theme!)
|
// ✅ Warten bis ALLE Fonts geladen sind
|
||||||
document.body.classList.remove("preload");
|
try {
|
||||||
document.body.classList.add("ready");
|
if (document.fonts && document.fonts.ready) {
|
||||||
|
await document.fonts.ready;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
|
// ✅ Erst JETZT sichtbar machen
|
||||||
|
document.body.classList.remove("preload");
|
||||||
|
document.body.classList.add("ready");
|
||||||
|
|
||||||
// ✅ Service Worker NUR EINMAL registrieren
|
ReactDOM.createRoot(document.getElementById("root")).render(<App />);
|
||||||
const updateSW = registerSW({
|
|
||||||
|
// ✅ Service Worker – KEIN Auto-Reload mehr
|
||||||
|
registerSW({
|
||||||
immediate: true,
|
immediate: true,
|
||||||
onNeedRefresh() {
|
onNeedRefresh() {
|
||||||
updateSW(true);
|
console.info("Neue Version verfügbar – Reload manuell");
|
||||||
window.location.reload();
|
// optional: später Toast „Update verfügbar“
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bootstrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user