Skip to content

Commit f7dff99

Browse files
authored
fix: invalidate series cache when book status changes (#409)
## Summary Fixes a cache invalidation bug where changing a book's status on `/books/:id` doesn't refresh the cache on the `/series/:name` page, causing stale status badges and ratings to be displayed. ## Root Cause The cache invalidation bug existed at two levels: 1. **Client-Side (React Query)**: `invalidateBookQueries()` in `useBookStatus.ts` was not invalidating series queries 2. **Server-Side (Next.js)**: `SessionService` and `ProgressService` were not calling `revalidatePath('/series')` ## Changes **3 files modified, 3 lines added:** - `hooks/useBookStatus.ts:57` - Added series query invalidation using `queryKeys.series.all()` - `lib/services/session.service.ts:1365` - Added `revalidatePath('/series')` - `lib/services/progress.service.ts:524` - Added `revalidatePath('/series')` ## Implementation Details The fix uses "nuclear" invalidation (invalidate all series queries) for simplicity and reliability, consistent with the existing shelf invalidation pattern when specific targeting is complex. - `queryKeys.series.all()` returns `['series']`, which matches both series list and all series detail pages - `revalidatePath('/series')` revalidates both `/series` (list) and `/series/:name` (detail) pages ## Testing - ✅ All 4,013 tests pass (188 test files) - ✅ No regressions detected - ✅ Changes follow existing patterns ## Manual Testing To verify the fix: 1. Open a series detail page (e.g., `/series/Harry%20Potter`) 2. Note a book's status badge 3. Change that book's status on `/books/:id` 4. Return to the series page - status should now update immediately
1 parent 7b3cf28 commit f7dff99

3 files changed

Lines changed: 5 additions & 0 deletions

File tree

hooks/useBookStatus.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ export function invalidateBookQueries(queryClient: QueryClient, bookId: string):
5454
queryClient.invalidateQueries({ queryKey: queryKeys.dashboard.all() });
5555
queryClient.invalidateQueries({ queryKey: queryKeys.library.books() });
5656
queryClient.invalidateQueries({ queryKey: queryKeys.readNext.base() });
57+
58+
// Invalidate series pages (if book belongs to a series)
59+
queryClient.invalidateQueries({ queryKey: queryKeys.series.all() });
5760

5861
// Invalidate shelves containing this book
5962
// Try to get shelves from cache; if available, invalidate only those shelves (surgical)

lib/services/progress.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ export class ProgressService {
521521
revalidatePath("/stats"); // Stats page
522522
revalidatePath("/journal"); // Journal page
523523
revalidatePath(`/books/${bookId}`); // Book detail page
524+
revalidatePath("/series"); // Series pages (list and detail)
524525
} catch (error) {
525526
getLogger().error({ err: error }, "[ProgressService] Failed to invalidate cache");
526527
// Don't fail the request if cache invalidation fails

lib/services/session.service.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,7 @@ export class SessionService {
13621362
revalidatePath("/stats"); // Stats page
13631363
revalidatePath("/journal"); // Journal page
13641364
revalidatePath(`/books/${bookId}`); // Book detail page
1365+
revalidatePath("/series"); // Series pages (list and detail)
13651366
} catch (error) {
13661367
getLogger().error({ err: error }, "[SessionService] Failed to invalidate cache");
13671368
// Don't fail the request if cache invalidation fails

0 commit comments

Comments
 (0)