Skip to content

Commit

Permalink
Do not check for state change before set state call
Browse files Browse the repository at this point in the history
Due to not including the states in the dependency array (to improve render performance), they do not include updated data and might cause an incorrect early exit.

E.g. in case a load error happened for a page whose loaded flag was already set to true, the pages load state never got updated again
  • Loading branch information
schroda committed Dec 30, 2024
1 parent 95f95e7 commit f8d3be3
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions src/modules/reader/utils/Reader.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,14 @@ export const createUpdateReaderPageLoadState =
const img = new Image();
img.onload = () => {
const isSpreadPageFlag = isSpreadPage(img);
const pageSpreadState = pagesToSpreadState[index];
if (!isSpreadPageFlag || pageSpreadState.isSpread === isSpreadPageFlag) {
if (!isSpreadPageFlag) {
return;
}

setPagesToSpreadState((prevState) => {
const isOfOutdatedSpreadState = prevState[index] === undefined || prevState[index].url !== url;
const pageSpreadState = prevState[index];

const isOfOutdatedSpreadState = pageSpreadState === undefined || pageSpreadState.url !== url;
if (isOfOutdatedSpreadState) {
return prevState;
}
Expand All @@ -169,10 +170,6 @@ export const createUpdateReaderPageLoadState =
img.src = url;
}

if (pageLoadStates[index].loaded) {
return;
}

setPageLoadStates((statePageLoadStates) => {
const pageLoadState = statePageLoadStates[index];

Expand Down

0 comments on commit f8d3be3

Please sign in to comment.