Skip to content

πŸ“΄ Offline Sync ​

Offline Sync (providers/sync-provider.tsx) ​

SyncProvider monitors network state and app foreground transitions to automatically flush any notes created while offline.

Sync Triggers ​

TriggerDelay
Network reconnects1.5s debounce
App comes to foregroundImmediate
New note added to offline queueImmediate

Retry Strategy ​

Failed uploads use exponential backoff: 5 retries with delays of 5s, 25s, 125s, 625s, 3125s (max ~52 min total). After 5 failures, the note is marked failed and an alert is shown to the user.

Reading Sync State ​

tsx
import { useSyncContext } from '@/providers/sync-provider';

const { syncState, failedCount, retryAll } = useSyncContext();

// syncState: 'idle' | 'syncing' | 'error'
// failedCount: number of permanently failed notes
// retryAll(): manually retry all failed notes

Offline Queue (hooks/use-offline-queue.ts) ​

Notes created without connectivity are saved to MMKV (synchronous key-value storage, faster than AsyncStorage).

The offlineNotes array is shaped as Draft[] so it can be rendered in the same list component as synced notes.

ts
const { offlineNotes, addToQueue, removeFromQueue } = useOfflineQueue();

// Add a note to the queue (called automatically by useCreateNote on network error)
addToQueue(draft);

// Remove after successful sync
removeFromQueue(draft.id);