fix: server-side render InitialLoader via cookies to prevent FOUC and add video preload

Former-commit-id: 2af58c1fa51fbe807132e879995ffe75ec59b7b6
This commit is contained in:
2026-05-07 19:28:10 +02:00
parent b515e45c0d
commit e324e2c508
2 changed files with 17 additions and 16 deletions

View File

@@ -7,20 +7,12 @@ const PRELOAD_VIDEOS = [
'/assets/videos/web/hero-bohrung.mp4'
];
export function InitialLoader() {
const [isLoading, setIsLoading] = useState(true);
const [isClient, setIsClient] = useState(false);
export function InitialLoader({ shouldShowLoader = true }: { shouldShowLoader?: boolean }) {
const [isLoading, setIsLoading] = useState(shouldShowLoader);
useEffect(() => {
setIsClient(true);
if (!shouldShowLoader) return;
// Prüfen, ob wir in dieser Session schon geladen haben
const hasLoaded = sessionStorage.getItem('etib_initial_load');
if (hasLoaded) {
setIsLoading(false);
return;
}
// Fallback Timeout (4 Sekunden), falls Videos hängen
const timeout = setTimeout(() => {
finishLoading();
@@ -48,15 +40,16 @@ export function InitialLoader() {
// Cleanup
return () => clearTimeout(timeout);
}, []);
}, [shouldShowLoader]);
const finishLoading = () => {
sessionStorage.setItem('etib_initial_load', 'true');
// Set a session cookie so the server knows not to render the loader again
document.cookie = "etib_initial_load=true; path=/; samesite=lax";
setIsLoading(false);
};
// Wir rendern serverseitig nichts blockierendes (Hydration Mismatch verhindern)
if (!isClient) return null;
// Wenn wir serverseitig rendern und es nicht zeigen sollen, return null
if (!shouldShowLoader) return null;
return (
<AnimatePresence>