Skip to content

fix: CachedImage Animated.Value, SWR cache invalidation, background task timeout (#620 #621 #622)#709

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
BashMan11:fix/issues-620-621-622
Jun 27, 2026
Merged

fix: CachedImage Animated.Value, SWR cache invalidation, background task timeout (#620 #621 #622)#709
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
BashMan11:fix/issues-620-621-622

Conversation

@BashMan11

Copy link
Copy Markdown
Contributor

Summary

Fixes three bugs assigned to me in one atomic commit.


Closes #621 — CachedImage Animated.Value in render body

File: src/components/ui/CachedImage.tsx

  • Imported Animated from react-native
  • Changed opacity to const opacity = useRef(new Animated.Value(0)).current — reference is now stable across re-renders
  • Removed expo-image's built-in transition={250} and replaced with an explicit Animated.timing fade-in that fires once on onLoadingComplete
  • Wrapped ExpoImage in Animated.View driven by the stable opacity ref

Closes #620 — SWR cache does not invalidate after POST/PUT mutations

Files: src/services/api/cache.ts, src/config/apiCacheConfig.ts, src/services/api/axios.config.ts

  • Added invalidateByPattern(pattern: RegExp) to cache.ts — iterates memory store and persistent layer
  • Created src/config/apiCacheConfig.ts with MUTATION_INVALIDATION_MAP mapping URL patterns + HTTP methods → invalidation RegExps (courses, users, lessons)
  • Updated axios response interceptor to look up each successful mutation in the map and call invalidateByPattern synchronously before returning the response

Closes #622 — backgroundTaskScheduler tasks unbounded (iOS 30-second limit)

Files: src/utils/backgroundTaskScheduler.ts, src/services/syncService.ts

  • Added timeoutPromise(ms) helper and runWithTimeout(taskFn, taskName, timeoutMs=25000) that wraps execution in Promise.race
  • On timeout: logs warn with task name and elapsed ms, returns { timedOut: true, taskDurationMs }
  • enqueueLowPriorityTask now accepts an optional name parameter and routes through runWithTimeout
  • Added SyncService.runBackgroundSync() — calls backgroundScheduler.runWithTimeout and checkpoints isSyncing=false on timeout so the next run can resume cleanly

Tests

src/__tests__/issues/fixes_620_621_622.test.ts

Issue Test
#621 Object.is confirms opacity ref is identical across 5 re-renders
#620 Cache miss immediately after invalidateByPattern call; count returned correctly
#622 Fake timers confirm timedOut=true fires at exactly 25 000 ms

rinafcode#621 - CachedImage: move Animated.Value to useRef so the reference is
stable across re-renders; fade-in animation now plays once on load.

rinafcode#620 - SWR cache: add invalidateByPattern(RegExp) to cache.ts, define
MUTATION_INVALIDATION_MAP in apiCacheConfig.ts, and wire the axios
response interceptor to call invalidateByPattern after successful
POST/PUT/PATCH/DELETE requests.

rinafcode#622 - backgroundTaskScheduler: add runWithTimeout wrapping task
execution in Promise.race with a 25-second timeout, logging the event
on expiry. SyncService.runBackgroundSync delegates to runWithTimeout
and checkpoints isSyncing=false on timeout.

Tests: src/__tests__/issues/fixes_620_621_622.test.ts
@drips-wave

drips-wave Bot commented Jun 27, 2026

Copy link
Copy Markdown

@BashMan11 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER RUKAYAT-CODER merged commit deab507 into rinafcode:main Jun 27, 2026
1 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants