|
| 1 | +--- |
| 2 | +"@tanstack/offline-transactions": minor |
| 3 | +"@tanstack/db": patch |
| 4 | +--- |
| 5 | + |
| 6 | +Add offline-transactions package with robust offline-first capabilities |
| 7 | + |
| 8 | +New package `@tanstack/offline-transactions` provides a comprehensive offline-first transaction system with: |
| 9 | + |
| 10 | +**Core Features:** |
| 11 | + |
| 12 | +- Persistent outbox pattern for reliable transaction processing |
| 13 | +- Leader election for multi-tab coordination (Web Locks API with BroadcastChannel fallback) |
| 14 | +- Automatic storage capability detection with graceful degradation |
| 15 | +- Retry logic with exponential backoff and jitter |
| 16 | +- Sequential transaction processing (FIFO ordering) |
| 17 | + |
| 18 | +**Storage:** |
| 19 | + |
| 20 | +- Automatic fallback chain: IndexedDB → localStorage → online-only |
| 21 | +- Detects and handles private mode, SecurityError, QuotaExceededError |
| 22 | +- Custom storage adapter support |
| 23 | +- Diagnostic callbacks for storage failures |
| 24 | + |
| 25 | +**Developer Experience:** |
| 26 | + |
| 27 | +- TypeScript-first with full type safety |
| 28 | +- Comprehensive test suite (25 tests covering leader failover, storage failures, e2e scenarios) |
| 29 | +- Works in all modern browsers and server-side rendering environments |
| 30 | + |
| 31 | +**@tanstack/db improvements:** |
| 32 | + |
| 33 | +- Enhanced duplicate instance detection (dev-only, iframe-aware, with escape hatch) |
| 34 | +- Better environment detection for SSR and worker contexts |
| 35 | + |
| 36 | +Example usage: |
| 37 | + |
| 38 | +```typescript |
| 39 | +import { |
| 40 | + startOfflineExecutor, |
| 41 | + IndexedDBAdapter, |
| 42 | +} from "@tanstack/offline-transactions" |
| 43 | + |
| 44 | +const executor = startOfflineExecutor({ |
| 45 | + collections: { todos: todoCollection }, |
| 46 | + storage: new IndexedDBAdapter(), |
| 47 | + mutationFns: { |
| 48 | + syncTodos: async ({ transaction, idempotencyKey }) => { |
| 49 | + // Sync mutations to backend |
| 50 | + await api.sync(transaction.mutations, idempotencyKey) |
| 51 | + }, |
| 52 | + }, |
| 53 | + onStorageFailure: (diagnostic) => { |
| 54 | + console.warn("Running in online-only mode:", diagnostic.message) |
| 55 | + }, |
| 56 | +}) |
| 57 | + |
| 58 | +// Create offline transaction |
| 59 | +const tx = executor.createOfflineTransaction({ |
| 60 | + mutationFnName: "syncTodos", |
| 61 | + autoCommit: false, |
| 62 | +}) |
| 63 | + |
| 64 | +tx.mutate(() => { |
| 65 | + todoCollection.insert({ id: "1", text: "Buy milk", completed: false }) |
| 66 | +}) |
| 67 | + |
| 68 | +await tx.commit() // Persists to outbox and syncs when online |
| 69 | +``` |
0 commit comments