Skip to content

Commit 7d86671

Browse files
Fix stale cache issues from parser updates
- Validate cached data has usable images before using - Add clearComicChapterCache action to clear chapter images - Clear chapter cache on refresh to fetch fresh images
1 parent 8e13796 commit 7d86671

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

src/Redux/Actions/GlobalActions.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,13 @@ export const fetchComicBook =
175175
// Check for existing data
176176
const existingData = getState().data.dataByUrl[originalComicBook];
177177

178-
if (existingData) {
178+
// Validate cached data has usable images (fixes stale cache from parser updates)
179+
const hasValidImages =
180+
existingData &&
181+
Array.isArray(existingData.images) &&
182+
existingData.images.length > 0;
183+
184+
if (hasValidImages) {
179185
if (isfetchComicDetails && existingData.detailsLink) {
180186
dispatch(fetchComicDetails(existingData?.detailsLink));
181187
}

src/Redux/Reducers/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,20 @@ const Reducers = createSlice({
261261
clearHistory: state => {
262262
state.history = {};
263263
},
264+
clearComicChapterCache: (state, action) => {
265+
const comicDetailLink = action.payload;
266+
const comicDetail = state.dataByUrl[comicDetailLink];
267+
268+
// Clear cached chapter images for this comic
269+
if (comicDetail?.chapters) {
270+
comicDetail.chapters.forEach(chapter => {
271+
if (chapter?.link && state.dataByUrl[chapter.link]) {
272+
// Only clear the images array, keep other data if any
273+
delete state.dataByUrl[chapter.link];
274+
}
275+
});
276+
}
277+
},
264278
DownTime: (state, action) => {
265279
state.loading = false;
266280
state.error = action.payload
@@ -623,6 +637,7 @@ export const {
623637
updateDownloadedComicBook,
624638
clearHistory,
625639
clearSearch,
640+
clearComicChapterCache,
626641
setScrollPreference,
627642
setComicBackgroundColor,
628643
rewardAdsShown,

src/Screens/Comic/Details/ComicDetails.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '../../../Redux/Actions/GlobalActions';
2323
import Loading from '../../../Components/UIComp/Loading';
2424
import Error from '../../../Components/UIComp/Error';
25-
import {updateData} from '../../../Redux/Reducers';
25+
import {updateData, clearComicChapterCache} from '../../../Redux/Reducers';
2626
import ChaptersView from '../../../Components/UIComp/ChaptersView';
2727
import DescriptionView from '../../../Components/UIComp/DescriptionView';
2828
import {
@@ -164,13 +164,9 @@ export function ComicDetails({navigation, route}) {
164164
</TouchableOpacity>
165165
<TouchableOpacity
166166
onPress={() => {
167+
// Clear cached chapter images for this comic (keeps reading progress)
168+
dispatch(clearComicChapterCache(search ? PageUrl : PageLink));
167169
dispatch(fetchComicDetails(search ? PageUrl : PageLink, true));
168-
// dispatch(
169-
// updateData({
170-
// url: search ? PageUrl : PageLink,
171-
// data: { Bookmark: !ComicDetail?.Bookmark },
172-
// }),
173-
// );
174170
}}>
175171
<Ionicons
176172
name="refresh-outline"

0 commit comments

Comments
 (0)