From 8414159550dfae2d9bec110586d28e29fcc6b135 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Thu, 8 Jun 2023 12:42:21 +0200 Subject: [PATCH] Prevent updating "lastPageRead" to the initial chapters "lastPageRead" 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 bfab10385c..acc695cbfe 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 }); }