Skip to content

feat(home): add AsyncStorage feed cache for instant startup load (#895) - #1127

Merged
ONEONUORA merged 1 commit into
Fracverse:masterfrom
Peace-001:feat/feed-asyncstorage-cache
Oct 19, 2026
Merged

ONEONUORA merged 1 commit into
Fracverse:masterfrom
Peace-001:feat/feed-asyncstorage-cache

Conversation

@Peace-001

Copy link
Copy Markdown
Contributor

Summary

Closes #895

Implements local AsyncStorage caching for the home feed so content is visible instantly on app startup, before any network request completes.

What changed

mobileapp/app/(personal)/home.tsx

  • Added FEED_CACHE_KEY = "feed_items_cache" constant.
  • On mount, the useEffect now runs a two-phase load:
    1. Cache phase — reads feed_items_cache from AsyncStorage and immediately populates the feed state so users see content with zero network latency.
    2. Network phase — fetches fresh data from the backend (fetchFeed), updates the feed state, and writes the result back to AsyncStorage for the next launch.
  • Pull-to-refresh (onPullRefresh) also writes the latest data back to the cache.
  • All errors (corrupt cache JSON, network failure, empty response) are handled gracefully — the last known good data stays visible.

mobileapp/__tests__/homeCache.test.tsx (new)

Seven focused tests covering every path through the caching logic:

# Scenario Assertion
1 Cache hit on mount Cached items rendered before network responds
2 Successful network fetch Fresh items replace cached items
3 Empty cache Falls back to INITIAL_FEED without crashing
4 AsyncStorage.getItem throws Error swallowed; INITIAL_FEED shown
5 Write-back after fetch Fresh items persisted to AsyncStorage
6 Network fetch throws Cached items remain visible; cache unchanged
7 Network returns [] Existing cache not overwritten

Acceptance criteria

  • Cached items load immediately on mount (before network)
  • Fresh data fetched and displayed after cache hydration
  • Cache updated after every successful fetch
  • All error paths handled without crashing or data loss

Testing

cd mobileapp
npx jest --testPathPattern="homeCache" --runInBand

Cover the two-phase load (cache-first then network) introduced in
home.tsx:

- Cached items are shown immediately on mount before network responds
- Fresh network data replaces cached items after a successful fetch
- Empty cache gracefully falls back to INITIAL_FEED
- AsyncStorage read errors are swallowed; INITIAL_FEED shown instead
- Fetched items are written back to AsyncStorage after success
- Network fetch errors leave existing cached items visible on screen
- Empty network response does not overwrite a populated cache
@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@Peace-001 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

@ONEONUORA ONEONUORA left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job @Peace-001

@ONEONUORA
ONEONUORA merged commit 9830a5e into Fracverse:master Oct 19, 2026
9 of 10 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

Development

Successfully merging this pull request may close these issues.

frontend: Add local caching for feed items using AsyncStorage

3 participants