From 760bd14aa7a85f825a1c11d75f4b30571d23f522 Mon Sep 17 00:00:00 2001 From: Julien Froidefond Date: Tue, 7 Oct 2025 18:15:57 +0200 Subject: [PATCH] fix: loader was slowing down the pages load time --- src/components/layout/ClientLayout.tsx | 2 - .../skeletons/OptimizedSkeletons.tsx | 97 +++++++++++++++++++ src/components/ui/loading-bar.tsx | 97 ------------------- 3 files changed, 97 insertions(+), 99 deletions(-) create mode 100644 src/components/skeletons/OptimizedSkeletons.tsx delete mode 100644 src/components/ui/loading-bar.tsx diff --git a/src/components/layout/ClientLayout.tsx b/src/components/layout/ClientLayout.tsx index f7aa78f..3beb684 100644 --- a/src/components/layout/ClientLayout.tsx +++ b/src/components/layout/ClientLayout.tsx @@ -9,7 +9,6 @@ import { Toaster } from "@/components/ui/toaster"; import { usePathname } from "next/navigation"; import { registerServiceWorker } from "@/lib/registerSW"; import { NetworkStatus } from "../ui/NetworkStatus"; -import { LoadingBar } from "@/components/ui/loading-bar"; import { DebugWrapper } from "@/components/debug/DebugWrapper"; import type { KomgaLibrary, KomgaSeries } from "@/types/komga"; @@ -70,7 +69,6 @@ export default function ClientLayout({ children, initialLibraries = [], initialF return (
- {!isPublicRoute &&
} {!isPublicRoute && ( + {children} +
+ ); +} + +export function HomePageSkeleton() { + return ( +
+ {/* Header */} +
+ + +
+ + {/* Hero Section */} + + + {/* Media Rows */} +
+ {Array.from({ length: 4 }).map((_, i) => ( +
+
+ + +
+
+ {Array.from({ length: 6 }).map((_, j) => ( + + ))} +
+
+ ))} +
+
+ ); +} + +export function SeriesPageSkeleton() { + return ( +
+ {/* Header */} +
+ +
+ + +
+
+ + {/* Books Grid */} +
+ {Array.from({ length: 12 }).map((_, i) => ( + + ))} +
+
+ ); +} + +export function LibraryPageSkeleton() { + return ( +
+ {/* Header */} +
+ +
+ + +
+
+ + {/* Series Grid */} +
+ {Array.from({ length: 18 }).map((_, i) => ( + + ))} +
+
+ ); +} diff --git a/src/components/ui/loading-bar.tsx b/src/components/ui/loading-bar.tsx deleted file mode 100644 index e3b438e..0000000 --- a/src/components/ui/loading-bar.tsx +++ /dev/null @@ -1,97 +0,0 @@ -"use client"; - -import { useEffect, useState, useRef } from "react"; -import { cn } from "@/lib/utils"; -import { Loader2 } from "lucide-react"; - -export function LoadingBar() { - const [isLoading, setIsLoading] = useState(false); - const [shouldRender, setShouldRender] = useState(false); - const pendingRequestsRef = useRef(0); - - useEffect(() => { - if (isLoading) { - setShouldRender(true); - } else { - const timer = setTimeout(() => { - setShouldRender(false); - }, 500); - return () => clearTimeout(timer); - } - }, [isLoading]); - - useEffect(() => { - const handleStart = () => { - setIsLoading(true); - }; - - const handleStop = () => { - setTimeout(() => { - if (pendingRequestsRef.current === 0) { - setIsLoading(false); - } - }, 300); - }; - - window.addEventListener("navigationStart", handleStart); - window.addEventListener("navigationComplete", handleStop); - - return () => { - window.removeEventListener("navigationStart", handleStart); - window.removeEventListener("navigationComplete", handleStop); - }; - }, []); - - useEffect(() => { - const originalFetch = window.fetch; - - window.fetch = async function (...args) { - const url = args[0].toString(); - const isStaticRequest = - /\.(css|js|png|jpg|jpeg|gif|webp|svg|ico|mp3|mp4|webm|ttf|woff|woff2)$/.test(url); - const isBookPageRequest = url.includes("/api/komga/images/books/") && url.includes("/pages"); - - if (!isStaticRequest && !isBookPageRequest) { - pendingRequestsRef.current++; - setIsLoading(true); - } - - try { - const response = await originalFetch.apply(this, args); - return response; - } finally { - if (!isStaticRequest && !isBookPageRequest) { - pendingRequestsRef.current = Math.max(0, pendingRequestsRef.current - 1); - - if (pendingRequestsRef.current === 0) { - setTimeout(() => { - setIsLoading(false); - }, 200); - } - } - } - }; - - return () => { - window.fetch = originalFetch; - }; - }, []); - - if (!shouldRender) return null; - - return ( -
-
- -

Chargement...

-
-
- ); -}