Skip to content

feat: improve offline caching, stale data handling, and sync resilience - #539

Open
Joyful12-tech wants to merge 1 commit into
BlockDash-Studios:mainfrom
Joyful12-tech:feat/offline-caching-stale-data-534
Open

feat: improve offline caching, stale data handling, and sync resilience#539
Joyful12-tech wants to merge 1 commit into
BlockDash-Studios:mainfrom
Joyful12-tech:feat/offline-caching-stale-data-534

Conversation

@Joyful12-tech

Copy link
Copy Markdown
Contributor
  • Add src/lib/watchlist.ts with CacheState type (fresh/stale/unavailable), STALE_THRESHOLD_MS, loadWatchlistFromStorage, saveWatchlistToStorage, getCacheState, and isNewerThanLocal helpers
  • Update WatchlistContext to expose cacheState and use watchlist lib
  • Update NotificationCenterProvider to persist sync timestamps and guard against stale server responses overwriting newer local mutations
  • Add StaleDataBanner to notifications/page.tsx shown when cacheState=stale
  • Rewrite sw.js with three-tier caching strategy: navigation → network-first with offline fallback
    API calls → stale-while-revalidate
    static → cache-first
  • Include PWAHandler in layout.tsx for SW registration
  • Upgrade PWAHandler to handle online/offline transitions, emit
    RustAcademy.lastOnlineAt/lastOfflineAt timestamps, and relay SW
    cache stats via postMessage
  • Update offline/page.tsx to show cached data status (last sync
    timestamps, stale indicators, API cache entry count)
  • Update api.ts with fetchWithCache and getCacheAge helpers
  • Add stale data banner to dashboard/page.tsx when cached data is used

Closes #534

- Add src/lib/watchlist.ts with CacheState type (fresh/stale/unavailable),
  STALE_THRESHOLD_MS, loadWatchlistFromStorage, saveWatchlistToStorage,
  getCacheState, and isNewerThanLocal helpers
- Update WatchlistContext to expose cacheState and use watchlist lib
- Update NotificationCenterProvider to persist sync timestamps and guard
  against stale server responses overwriting newer local mutations
- Add StaleDataBanner to notifications/page.tsx shown when cacheState=stale
- Rewrite sw.js with three-tier caching strategy:
    navigation  → network-first with offline fallback
    API calls   → stale-while-revalidate
    static      → cache-first
- Include PWAHandler in layout.tsx for SW registration
- Upgrade PWAHandler to handle online/offline transitions, emit
  RustAcademy.lastOnlineAt/lastOfflineAt timestamps, and relay SW
  cache stats via postMessage
- Update offline/page.tsx to show cached data status (last sync
  timestamps, stale indicators, API cache entry count)
- Update api.ts with fetchWithCache and getCacheAge helpers
- Add stale data banner to dashboard/page.tsx when cached data is used

Closes BlockDash-Studios#534
@Joyful12-tech
Joyful12-tech force-pushed the feat/offline-caching-stale-data-534 branch from ef232ba to 9880a38 Compare August 18, 2026 23:42
@MaryammAli

Copy link
Copy Markdown
Contributor

@Joyful12-tech
you have conflict
please resolve

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.

Improve offline caching, stale data handling, and sync resilience for user state

2 participants