diff --git a/src/modules/reader/components/viewer/ReaderViewer.tsx b/src/modules/reader/components/viewer/ReaderViewer.tsx index 2eddc3ed..2d5a4cd3 100644 --- a/src/modules/reader/components/viewer/ReaderViewer.tsx +++ b/src/modules/reader/components/viewer/ReaderViewer.tsx @@ -191,7 +191,7 @@ const BaseReaderViewer = forwardRef( const isLtrReadingDirection = readingDirection === ReadingDirection.LTR; const initialChapterIndex = useMemo( () => chapters.findIndex((chapter) => chapter.id === initialChapter?.id), - [initialChapter?.id], + [chapters, initialChapter?.id], ); const chaptersToRender = useMemo( () => @@ -199,7 +199,7 @@ const BaseReaderViewer = forwardRef( Math.max(0, initialChapterIndex - visibleChapters.trailing), Math.min(chapters.length, initialChapterIndex + visibleChapters.leading + 1), ), - [chapters, initialChapterIndex, visibleChapters.trailing, visibleChapters.leading, chapters.length], + [chapters, initialChapterIndex, visibleChapters.trailing, visibleChapters.leading], ); const currentChapterIndex = useMemo( () => chaptersToRender.findIndex((chapter) => chapter.id === currentChapter?.id), diff --git a/src/modules/reader/hooks/useReaderSetChaptersState.ts b/src/modules/reader/hooks/useReaderSetChaptersState.ts index fd8cbcd0..78a3c257 100644 --- a/src/modules/reader/hooks/useReaderSetChaptersState.ts +++ b/src/modules/reader/hooks/useReaderSetChaptersState.ts @@ -46,6 +46,17 @@ export const useReaderSetChaptersState = ( skipDupe: shouldSkipDupChapters, skipDupeChapter: newChapterForDuplicatesHandling, }); + const newChapters = (() => { + if (!newMangaChapters || !newChapterForDuplicatesHandling) { + return []; + } + + if (shouldSkipDupChapters) { + return Chapters.removeDuplicates(newChapterForDuplicatesHandling, newMangaChapters); + } + + return newMangaChapters; + })(); const hasInitialChapterChanged = newInitialChapter != null && newInitialChapter.id !== initialChapter?.id; @@ -54,10 +65,7 @@ export const useReaderSetChaptersState = ( return { ...prevState, mangaChapters: newMangaChapters ?? [], - chapters: - newChapterForDuplicatesHandling && newMangaChapters - ? Chapters.removeDuplicates(newChapterForDuplicatesHandling, newMangaChapters) - : [], + chapters: newChapters, initialChapter: newInitialChapter, chapterForDuplicatesHandling: newChapterForDuplicatesHandling, currentChapter: newCurrentChapter,