|
| 1 | +--- |
| 2 | +"@tanstack/db": major |
| 3 | +"@tanstack/electric-db-collection": major |
| 4 | +"@tanstack/query-db-collection": major |
| 5 | +--- |
| 6 | + |
| 7 | +**BREAKING**: Deprecate returning values from mutation handlers (`onInsert`, `onUpdate`, `onDelete`). Instead, use explicit sync coordination: |
| 8 | + |
| 9 | +- **Query Collections**: Call `await collection.utils.refetch()` to sync server state |
| 10 | +- **Electric Collections**: Call `await collection.utils.awaitTxId(txid)` or `await collection.utils.awaitMatch(fn)` to wait for synchronization |
| 11 | +- **Other Collections**: Use appropriate sync utilities for your collection type |
| 12 | + |
| 13 | +This change makes the API more explicit and consistent across all collection types. Magic return values like `{ refetch: false }` in Query Collections and `{ txid }` in Electric Collections are now deprecated. All handlers should coordinate sync explicitly within the handler function. |
| 14 | + |
| 15 | +Migration guide: |
| 16 | + |
| 17 | +```typescript |
| 18 | +// Before (Query Collection) |
| 19 | +onInsert: async ({ transaction }) => { |
| 20 | + await api.create(transaction.mutations[0].modified) |
| 21 | + // Implicitly refetches |
| 22 | +} |
| 23 | + |
| 24 | +// After (Query Collection) |
| 25 | +onInsert: async ({ transaction, collection }) => { |
| 26 | + await api.create(transaction.mutations[0].modified) |
| 27 | + await collection.utils.refetch() |
| 28 | +} |
| 29 | + |
| 30 | +// Before (Electric Collection) |
| 31 | +onInsert: async ({ transaction }) => { |
| 32 | + const result = await api.create(transaction.mutations[0].modified) |
| 33 | + return { txid: result.txid } |
| 34 | +} |
| 35 | + |
| 36 | +// After (Electric Collection) |
| 37 | +onInsert: async ({ transaction, collection }) => { |
| 38 | + const result = await api.create(transaction.mutations[0].modified) |
| 39 | + await collection.utils.awaitTxId(result.txid) |
| 40 | +} |
| 41 | +``` |
0 commit comments