|
1 | 1 | # @tanstack/db |
2 | 2 |
|
| 3 | +## 0.4.17 |
| 4 | + |
| 5 | +### Patch Changes |
| 6 | + |
| 7 | +- Add offline-transactions package with robust offline-first capabilities ([#559](https://github.com/TanStack/db/pull/559)) |
| 8 | + |
| 9 | + New package `@tanstack/offline-transactions` provides a comprehensive offline-first transaction system with: |
| 10 | + |
| 11 | + **Core Features:** |
| 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 | + - Automatic fallback chain: IndexedDB → localStorage → online-only |
| 20 | + - Detects and handles private mode, SecurityError, QuotaExceededError |
| 21 | + - Custom storage adapter support |
| 22 | + - Diagnostic callbacks for storage failures |
| 23 | + |
| 24 | + **Developer Experience:** |
| 25 | + - TypeScript-first with full type safety |
| 26 | + - Comprehensive test suite (25 tests covering leader failover, storage failures, e2e scenarios) |
| 27 | + - Works in all modern browsers and server-side rendering environments |
| 28 | + |
| 29 | + **@tanstack/db improvements:** |
| 30 | + - Enhanced duplicate instance detection (dev-only, iframe-aware, with escape hatch) |
| 31 | + - Better environment detection for SSR and worker contexts |
| 32 | + |
| 33 | + Example usage: |
| 34 | + |
| 35 | + ```typescript |
| 36 | + import { |
| 37 | + startOfflineExecutor, |
| 38 | + IndexedDBAdapter, |
| 39 | + } from "@tanstack/offline-transactions" |
| 40 | + |
| 41 | + const executor = startOfflineExecutor({ |
| 42 | + collections: { todos: todoCollection }, |
| 43 | + storage: new IndexedDBAdapter(), |
| 44 | + mutationFns: { |
| 45 | + syncTodos: async ({ transaction, idempotencyKey }) => { |
| 46 | + // Sync mutations to backend |
| 47 | + await api.sync(transaction.mutations, idempotencyKey) |
| 48 | + }, |
| 49 | + }, |
| 50 | + onStorageFailure: (diagnostic) => { |
| 51 | + console.warn("Running in online-only mode:", diagnostic.message) |
| 52 | + }, |
| 53 | + }) |
| 54 | + |
| 55 | + // Create offline transaction |
| 56 | + const tx = executor.createOfflineTransaction({ |
| 57 | + mutationFnName: "syncTodos", |
| 58 | + autoCommit: false, |
| 59 | + }) |
| 60 | + |
| 61 | + tx.mutate(() => { |
| 62 | + todoCollection.insert({ id: "1", text: "Buy milk", completed: false }) |
| 63 | + }) |
| 64 | + |
| 65 | + await tx.commit() // Persists to outbox and syncs when online |
| 66 | + ``` |
| 67 | + |
3 | 68 | ## 0.4.16 |
4 | 69 |
|
5 | 70 | ### Patch Changes |
|
0 commit comments