Skip to content

Conversation

@rezk2ll
Copy link
Collaborator

@rezk2ll rezk2ll commented Jan 30, 2026

Summary

Implements full offline functionality for SplitShare, allowing users to continue tracking workouts, viewing splits, and accessing exercise data even without an internet connection. All changes sync automatically when
connectivity is restored.

Key Features

🌐 PWA Infrastructure

  • PWA Manifest (static/manifest.json) - App metadata, icons, and display settings
  • Service Worker (src/service-worker.ts) - Advanced caching strategies:
    • Stale-while-revalidate for API calls (fast response, background refresh)
    • Cache-first for static assets
    • Background Sync API support for deferred actions

💾 Client-Side Storage (IndexedDB)

  • Dexie.js integration for robust IndexedDB management
  • Local data storage for:
    • Splits and split days
    • Exercises
    • Active workout sessions (critical for offline workouts)
    • Personal records
    • Weight entries
  • Sync tracking with isDirty flags on all mutable entities
  • Pending actions queue - Mutations queued when offline, synced when online
  • API response cache with 5-minute TTL for GET requests

🔄 Intelligent Sync System

  • Priority-based sync - Workout sessions synced first (most critical)
  • Retry logic - Up to 3 attempts with exponential backoff
  • Dead letter queue - Failed actions after max retries moved to separate table for inspection
  • Sync locking - Prevents concurrent sync operations
  • Automatic sync - Triggered when app comes back online

📡 Network-Aware API Client

  • Enhanced apiRequest() - Automatically handles offline scenarios
  • Offline fallback - Returns cached data for GET requests when offline
  • Mutation queueing - POST/PUT/DELETE requests queued for later sync
  • Request timeout - 10-second timeout to prevent hanging requests
  • Authentication handling - 401 errors properly detected and reported

📊 UI/UX Improvements

  • OfflineIndicator component - Shows:
  • Online/offline status with icon
  • Pending sync count badge
  • Manual sync button
  • Connection type (WiFi/cellular/unknown)
  • Automatic initialization - Offline support starts with app load

Testing

New Tests Added (74 tests, 222 total)

  • ✅ IndexedDB operations - 14 tests (CRUD, querying, caching)
  • ✅ Sync service - 13 tests (queuing, retry, prioritization)
  • ✅ Connection store - 22 tests (state management, events)
  • ✅ API client - 18 tests (offline behavior, error handling)
  • ✅ Service worker - 11 tests (registration, updates)

Test Infrastructure

  • Added fake-indexeddb for browser-compatible IndexedDB mocking
  • All 222 tests passing (29 test files)

Architecture Notes

  • Svelte 5 Runes - Connection store uses .svelte.ts extension for proper rune support
  • Clean Architecture - Follows existing patterns with services, stores, and components
  • No breaking changes - All existing functionality preserved

Implements comprehensive offline functionality for the fitness workout app:

## New Features

**PWA Infrastructure**
- Add PWA manifest (manifest.json) with app metadata and icons
- Create service worker with caching strategies:
  - Stale-while-revalidate for API calls
  - Cache-first for static assets
  - Background sync support for deferred actions

**Client-Side Storage (IndexedDB)**
- Add Dexie.js for IndexedDB management
- Store entities locally: splits, exercises, workout sessions, personal records
- Track sync state with isDirty flags
- Implement pending actions queue for offline mutations
- Add API response cache with TTL

**Network & Sync**
- Connection monitoring with Network Information API
- Priority-based sync (workout sessions first)
- Retry logic with max 3 attempts
- Failed actions moved to dead letter queue
- Sync locking to prevent concurrent operations
- Automatic sync when connection restored

**Offline-Aware API Client**
- Enhanced apiRequest() with offline fallback
- Queue mutations for later sync when offline
- GET request caching with 5-minute TTL
- Request timeout handling (10 seconds)
- Authentication error handling (401)

**UI Components**
- OfflineIndicator component showing:
  - Online/offline status
  - Pending sync count
  - Manual sync button
  - Connection type (WiFi/cellular)

**Integration**
- Initialize offline support in layout
- Service worker registration
- Connection monitoring setup

## Tests

Add 74 new tests (222 total):
- IndexedDB operations (14 tests)
- Sync service (13 tests)
- Connection store (22 tests)
- API client offline behavior (18 tests)
- Service worker utilities (11 tests)

All tests pass: 222 tests, 29 test files
Fix 'This expression is not callable' error by adding type assertion
to updateFoundHandler variable in tests. TypeScript was incorrectly
inferring the type as 'never' due to closure boundaries.

- Add type assertion: (updateFoundHandler as () => void)()
- Change null check from truthy to explicit !== null check
@rezk2ll rezk2ll merged commit 5edf355 into main Jan 30, 2026
4 checks passed
@github-actions
Copy link

Branch feat/offline has been automatically deleted after merge.

@github-actions github-actions bot deleted the feat/offline branch January 30, 2026 23:43
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.

2 participants