diff --git a/src/app/books/[bookId]/page.tsx b/src/app/books/[bookId]/page.tsx
index a427747..7511c0d 100644
--- a/src/app/books/[bookId]/page.tsx
+++ b/src/app/books/[bookId]/page.tsx
@@ -1,13 +1,36 @@
import { Suspense } from "react";
import { ClientBookPage } from "@/components/reader/ClientBookPage";
import { BookSkeleton } from "@/components/skeletons/BookSkeleton";
+import { BookService } from "@/lib/services/book.service";
+import { ERROR_CODES } from "@/constants/errorCodes";
+import { AppError } from "@/utils/errors";
+import { redirect } from "next/navigation";
export default async function BookPage({ params }: { params: Promise<{ bookId: string }> }) {
const { bookId } = await params;
- return (
- }>
-
-
- );
+ try {
+ // SSR: Fetch directly on server instead of client-side XHR
+ const data = await BookService.getBook(bookId);
+ const nextBook = await BookService.getNextBook(bookId, data.book.seriesId);
+
+ return (
+ }>
+
+
+ );
+ } catch (error) {
+ // If config is missing, redirect to settings
+ if (error instanceof AppError && error.code === ERROR_CODES.KOMGA.MISSING_CONFIG) {
+ redirect("/settings");
+ }
+
+ // Pass error to client component
+ const errorCode = error instanceof AppError ? error.code : ERROR_CODES.BOOK.NOT_FOUND;
+ return (
+ }>
+
+
+ );
+ }
}
diff --git a/src/components/reader/ClientBookPage.tsx b/src/components/reader/ClientBookPage.tsx
index 7e7f734..64bf3bc 100644
--- a/src/components/reader/ClientBookPage.tsx
+++ b/src/components/reader/ClientBookPage.tsx
@@ -10,9 +10,15 @@ import logger from "@/lib/logger";
interface ClientBookPageProps {
bookId: string;
+ initialData?: {
+ book: KomgaBook;
+ pages: number[];
+ nextBook: KomgaBook | null;
+ };
+ initialError?: string;
}
-export function ClientBookPage({ bookId }: ClientBookPageProps) {
+export function ClientBookPage({ bookId, initialData, initialError }: ClientBookPageProps) {
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [data, setData] = useState<{
@@ -21,6 +27,22 @@ export function ClientBookPage({ bookId }: ClientBookPageProps) {
nextBook: KomgaBook | null;
} | null>(null);
+ // Use SSR data if available
+ useEffect(() => {
+ if (initialData) {
+ setData(initialData);
+ setLoading(false);
+ return;
+ }
+ if (initialError) {
+ setError(initialError);
+ setLoading(false);
+ return;
+ }
+ fetchBookData();
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [bookId, initialData, initialError]);
+
const fetchBookData = async () => {
try {
setLoading(true);
@@ -43,11 +65,6 @@ export function ClientBookPage({ bookId }: ClientBookPageProps) {
}
};
- useEffect(() => {
- fetchBookData();
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [bookId]);
-
const handleRetry = () => {
fetchBookData();
};