How offline mode works
CashCat uses TanStack Query for intelligent data caching and synchronization:- On app launch — all data fetches from Supabase and caches locally
- While online — reads from cache, updates in background
- When offline — reads from cache, queues writes
- On reconnect — syncs queued changes to server
The cache persists to IndexedDB using
idb-keyval, so your data survives app restarts and browser refreshes.Offline badge
The offline badge appears when network connectivity is lost:Badge behavior
- Position: Fixed to bottom-right (above navigation)
- Appearance: Amber/yellow color for offline state
- Transition: Fades in when offline, fades out when online
- Z-index:
100to appear above other UI elements
The badge shows “Online” briefly in green when connectivity is restored, then fades out after 300ms.
Network detection
CashCat uses the Capacitor Network plugin for network status:Detection methods
- Capacitor plugin (mobile apps) — native network monitoring
- Browser API fallback (web) —
window.onlineandwindow.offlineevents
Data caching strategy
CashCat caches all essential data using TanStack Query:Cached resources
- Transactions — all income and spending records
- Categories — budget categories with goals and settings
- Groups — category organization
- Assignments — monthly budget allocations
- Accounts — bank accounts and balances
- Vendors — merchant names for autocomplete
- Transfers — money moved between accounts
Cache configuration
Sync behavior
TheSyncInitializer component handles automatic synchronization:
Sync triggers
- App launch — syncs after 1 second delay
- Network reconnect — automatic sync when online
- Manual refresh — user-initiated sync
- Background sync — periodic updates while app is active
Query invalidation
CashCat invalidates queries intelligently to keep data fresh:After mutations
When you create, update, or delete data:Affected queries
Depending on the action:- Add transaction → invalidates transactions, assignments
- Update category → invalidates categories, groups
- Delete account → invalidates accounts, transactions
- Change budget → invalidates assignments, categories
Offline limitations
Some features require connectivity:Queued mutations
Mutations made offline are currently not queued. Support for offline mutation queues is planned:- Transactions will queue locally
- Sync when connection restored
- Conflict resolution for concurrent edits
- Optimistic UI updates
Storage persistence
Cached data persists across sessions:IndexedDB storage
- Database name: TanStack Query uses default IDB database
- Store name:
keyval(from idb-keyval) - Data format: Serialized query cache
- Expiration: Queries expire based on
staleTimeconfig
Cache lifetime
Different data types have different staleness times:- Transactions: 5 minutes
- Categories: 10 minutes
- Settings: 30 minutes
- Static data: 1 hour
Progressive enhancement
CashCat works progressively:- No cache — fetches all data from server (first visit)
- Cached, online — reads cache, updates in background
- Cached, offline — reads cache only, shows offline badge
- Cached, stale — shows cached data, fetches updates when online
Cache debugging
TanStack Query DevTools help debug cache:- Query status — loading, success, error, stale
- Cache entries — all cached data
- Mutations — in-flight and completed
- Network activity — fetch and update timeline
DevTools are only available in development mode and do not appear in production builds.
Future enhancements
Planned offline improvements:- Offline mutation queue — queue changes when offline, sync when online
- Conflict resolution — handle concurrent edits from multiple devices
- Partial sync — sync only changed data, not full refetch
- Background sync — use Service Worker for sync even when app closed
- Optimistic updates — instant UI updates before server confirms