Do not check for state change before set state call
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -169,10 +170,6 @@ export const createUpdateReaderPageLoadState =
|
||||
img.src = url;
|
||||
}
|
||||
|
||||
if (pageLoadStates[index].loaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
setPageLoadStates((statePageLoadStates) => {
|
||||
const pageLoadState = statePageLoadStates[index];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user