fix(tasks): revalidate stale MMKV task cache on mount - #151
Merged
cybermax4200 merged 2 commits intoAug 28, 2026
Merged
Conversation
Add tasksLastFetchedAt timestamp to taskStore (persisted to MMKV) and trigger a silent background fetch on mount when the warm cache is older than TASK_FEED_STALE_MS (5 min). The revalidation shows no loading skeleton and never clobbers selectedTask. - taskStore: tasksLastFetchedAt set in setTasks, passed through sanitizePersistedTaskState, cleared on reset - useTaskFeed: silent loadTasks mode + stale-check in mount effect - TASK_FEED_STALE_MS extracted to mockable config module - tests cover within-TTL (no fetch), past-TTL (silent fetch), and selectedTask preservation
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The offline task feed cache (MMKV) had no TTL and no revalidation trigger. If the store held tasks from a previous session,
useTaskFeedserved them indefinitely and never called the API again — even on a fresh app start with connectivity. New tasks, status changes, and reward updates were invisible until a manual pull-to-refresh.This adds a
tasksLastFetchedAttimestamp and a mount-time stale check that silently revalidates the cache when it's older thanTASK_FEED_STALE_MS(default 5 min).Changes
src/store/taskStore.tstasksLastFetchedAt: string | nulltoTaskStateandPersistedTaskSlice(persisted to MMKV).setTasksstampstasksLastFetchedAtwith the current ISO time on every page-1 fetch.sanitizePersistedTaskStatepassestasksLastFetchedAtthrough (reset to null when the cache is empty).reset()clearstasksLastFetchedAt.src/hooks/useTaskFeed.tsloadTasks(pageNum, silent = false)— silent mode skips the loading skeleton (setLoading).isStalefromtasksLastFetchedAtand, when the warm cache is older thanTASK_FEED_STALE_MS, triggers a silent background fetch (loadTasks(1, true)).selectedTaskis never clobbered during revalidation becausesetTasksonly replaces tasks.src/config/taskFeedCache.ts(new)TASK_FEED_STALE_MS = 5 * 60 * 1000as a separately-mockable module so tests can override the threshold.Tests
useTaskFeed.test.ts/useTaskFeedRefetch.test.tsx: within-TTL → no fetch; past-TTL → silent fetch with no loading skeleton;selectedTaskpreserved after revalidation.stores.test.ts: updated assertions for the new persisted field.Acceptance Criteria
taskStoregains atasksLastFetchedAtfield, persisted to MMKV.useTaskFeedtriggers a background fetch on mount whentasksLastFetchedAtis older thanTASK_FEED_STALE_MS(5 min default), even if the store has tasks.selectedTaskis not clobbered during background revalidation.selectedTaskpreserved after revalidation.Test plan
npm test— all task feed / store suites pass (48 tests).npx tsc --noEmitandnpx eslintclean.Out of scope
tasksLastFetchedAt).Closes #150