-
Notifications
You must be signed in to change notification settings - Fork 0
offline sync
ɳTask is a free-forever local task manager. It must work fully offline. This document describes how offline sync works.
The offline queue is backed by react-native-mmkv (primary) with @react-native-async-storage/async-storage as an automatic fallback (e.g. Expo Go without a native build). The queue survives app backgrounding and force-quit because MMKV writes synchronously to a memory-mapped file.
Queue key: ntask:mutation-queue:v1
Each entry is a QueuedMutation:
{
id: string; // unique entry ID (timestamp + random)
type: QueuedMutationType; // create_task | toggle_task | delete_task | ...
payload: Record<string, unknown>;
idempotencyKey: string; // client-generated; sent as X-Idempotency-Key header
enqueuedAt: number; // unix ms
retries: number; // incremented on failure
}- User performs an action while offline (create, toggle, delete task).
- Mutation is enqueued via
enqueue()insrc/lib/offline-queue.ts. - An optimistic placeholder appears in the UI immediately (for create).
-
useNetworkState(src/hooks/useNetworkState.ts) detects network change via NetInfo. - On reconnect,
onReconnectcallback fires →processQueue()is called. - Each mutation is dispatched in FIFO order with its idempotency key.
- On success: entry removed from queue.
- On failure:
retriesincremented. After 3 failures: entry removed, user notified.
Every create/update mutation carries an X-Idempotency-Key header generated by src/lib/idempotency.ts. The key is deterministic within a 5-minute window based on mutation type + seed. If the same mutation is retried (e.g. after a network blip), the server returns the same response rather than creating a duplicate.
When isConnected is false:
-
OfflineBannerappears at the top of every screen showing the count of pending mutations. - Previously cached tasks remain visible (urql
cache-and-networkpolicy). - New tasks created offline appear immediately with a spinner + "Saving…" label (pending state).
- Swipe-to-delete enqueues a delete mutation rather than executing immediately.
- Toggle (complete/uncomplete) enqueues a toggle mutation.
No configuration required. Offline sync is automatic and always-on. It cannot be disabled (it is a free core feature per the Security-Always-Free Doctrine).
- Conflict resolution: last-write-wins (server clock). If the same task is modified on two offline devices, the last sync wins.
- Max retries: 3. After 3 failures a mutation is dropped and the user is notified.
- Queue size: unbounded (MMKV storage limit is device storage).
Getting Started
Features
CLI & Agents
Backend
Architecture
Deployment
Reference
External