From 67e554ede6ec3691245ab236bc044466d18f47f6 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Thu, 8 Jun 2023 13:43:58 +0200 Subject: [PATCH] Prevent updating "lastPageRead" of chapter to the initial chapters "lastPageRead" (#357) This could cause racing conditions with the chapter load which lead to the lastPageRead to be reset to 0 --- src/screens/Reader.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/screens/Reader.tsx b/src/screens/Reader.tsx index bfab1038..acc695cb 100644 --- a/src/screens/Reader.tsx +++ b/src/screens/Reader.tsx @@ -108,6 +108,7 @@ export default function Reader() { mangaId, chapterIndex, ); + const [wasLastPageReadSet, setWasLastPageReadSet] = useState(false); const [curPage, setCurPage] = useState(0); const [pageToScrollTo, setPageToScrollTo] = useState(undefined); const { setOverride, setTitle } = useContext(NavbarContext); @@ -154,6 +155,7 @@ export default function Reader() { return; } + setWasLastPageReadSet(true); if (chapter.lastPageRead === chapter.pageCount - 1) { // last page, also probably read = true, we will load the first page. setCurPage(0); @@ -198,6 +200,10 @@ export default function Reader() { }, [manga, chapter, settings, curPage, chapterIndex, retrievingNextChapter]); useEffect(() => { + if (!wasLastPageReadSet) { + return; + } + if (curPage !== -1) { requestManager.updateChapter(manga.id, chapter.index, { lastPageRead: curPage }); }