fix: make next-book lookup non-blocking when opening reader
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import { BookService } from "@/lib/services/book.service";
|
import { BookService } from "@/lib/services/book.service";
|
||||||
import { AppError } from "@/utils/errors";
|
import { AppError } from "@/utils/errors";
|
||||||
import type { KomgaBook } from "@/types/komga";
|
import type { KomgaBook } from "@/types/komga";
|
||||||
|
import logger from "@/lib/logger";
|
||||||
|
|
||||||
interface BookDataResult {
|
interface BookDataResult {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
@@ -17,7 +18,12 @@ interface BookDataResult {
|
|||||||
export async function getBookData(bookId: string): Promise<BookDataResult> {
|
export async function getBookData(bookId: string): Promise<BookDataResult> {
|
||||||
try {
|
try {
|
||||||
const data = await BookService.getBook(bookId);
|
const data = await BookService.getBook(bookId);
|
||||||
const nextBook = await BookService.getNextBook(bookId, data.book.seriesId);
|
let nextBook = null;
|
||||||
|
try {
|
||||||
|
nextBook = await BookService.getNextBook(bookId, data.book.seriesId);
|
||||||
|
} catch (error) {
|
||||||
|
logger.warn({ err: error, bookId }, "Failed to fetch next book in server action");
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { BookService } from "@/lib/services/book.service";
|
|||||||
import { ERROR_CODES } from "@/constants/errorCodes";
|
import { ERROR_CODES } from "@/constants/errorCodes";
|
||||||
import { AppError } from "@/utils/errors";
|
import { AppError } from "@/utils/errors";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
|
import logger from "@/lib/logger";
|
||||||
|
|
||||||
export default async function BookPage({ params }: { params: Promise<{ bookId: string }> }) {
|
export default async function BookPage({ params }: { params: Promise<{ bookId: string }> }) {
|
||||||
const { bookId } = await params;
|
const { bookId } = await params;
|
||||||
@@ -12,7 +13,12 @@ export default async function BookPage({ params }: { params: Promise<{ bookId: s
|
|||||||
try {
|
try {
|
||||||
// SSR: Fetch directly on server instead of client-side XHR
|
// SSR: Fetch directly on server instead of client-side XHR
|
||||||
const data = await BookService.getBook(bookId);
|
const data = await BookService.getBook(bookId);
|
||||||
const nextBook = await BookService.getNextBook(bookId, data.book.seriesId);
|
let nextBook = null;
|
||||||
|
try {
|
||||||
|
nextBook = await BookService.getNextBook(bookId, data.book.seriesId);
|
||||||
|
} catch (error) {
|
||||||
|
logger.warn({ err: error, bookId }, "Failed to fetch next book, continuing without it");
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Suspense fallback={<BookSkeleton />}>
|
<Suspense fallback={<BookSkeleton />}>
|
||||||
|
|||||||
Reference in New Issue
Block a user