Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
42f371a
feat: add useSerializedMutations hook with timing strategies
KyleAMathews Oct 20, 2025
61eba8f
Fix feedback-4 issues and add interactive demo
KyleAMathews Oct 20, 2025
1e7240a
Merge origin/main into serialized-transaction
KyleAMathews Oct 21, 2025
53fdefc
fix: serialized mutations strategy execution and transaction handling
KyleAMathews Oct 21, 2025
b050bf7
prettier
KyleAMathews Oct 21, 2025
c62164f
test: add comprehensive tests for queue and throttle strategies
KyleAMathews Oct 21, 2025
eb60264
fix: resolve TypeScript strict mode errors in useSerializedMutations …
KyleAMathews Oct 22, 2025
ebd80fe
refactor: convert demo to slider-based interface with 300ms default
KyleAMathews Oct 22, 2025
dc155ad
fix(demo): improve UI and fix slider reset issue
KyleAMathews Oct 22, 2025
f1deaa7
fix(queue): capture transaction before clearing activeTransaction
KyleAMathews Oct 22, 2025
969d532
fix(queue): explicitly default to FIFO processing order
KyleAMathews Oct 22, 2025
051e138
docs: clarify queue strategy creates separate transactions with confi…
KyleAMathews Oct 22, 2025
066e79a
refactor: rename "Serialized Mutations" to "Paced Mutations"
KyleAMathews Oct 22, 2025
05fecc6
update lock
KyleAMathews Oct 22, 2025
c99cfd4
chore: change paced mutations changeset from minor to patch
KyleAMathews Oct 22, 2025
bb0fb11
fix: update remaining references to useSerializedMutations
KyleAMathews Oct 22, 2025
90e8f0a
docs: mention TanStack Pacer in changeset
KyleAMathews Oct 22, 2025
cc237ef
docs: clarify key design difference between strategies
KyleAMathews Oct 22, 2025
e64f3d3
docs: add comprehensive Paced Mutations guide
KyleAMathews Oct 22, 2025
3b03ead
fix: remove id property from PacedMutationsConfig
KyleAMathews Oct 22, 2025
3960b8a
fix: prevent unnecessary recreation of paced mutations instance
KyleAMathews Oct 23, 2025
1f8253f
test: add memoization tests for usePacedMutations
KyleAMathews Oct 23, 2025
7b4e55a
fix: stabilize mutationFn to prevent recreating paced mutations instance
KyleAMathews Oct 23, 2025
1ea79dd
Merge remote-tracking branch 'origin/main' into serialized-transaction
KyleAMathews Oct 27, 2025
a403d52
Refactor paced mutations to work like createOptimisticAction
claude Oct 27, 2025
755d706
Update paced mutations demo to use new onMutate API
KyleAMathews Oct 27, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .changeset/paced-mutations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
"@tanstack/db": patch
"@tanstack/react-db": patch
---

Add paced mutations with pluggable timing strategies

Introduces a new paced mutations system that enables optimistic mutations with pluggable timing strategies. This provides fine-grained control over when and how mutations are persisted to the backend. Powered by [TanStack Pacer](https://github.com/TanStack/pacer).

**Key Design:**

- **Debounce/Throttle**: Only one pending transaction (collecting mutations) and one persisting transaction (writing to backend) at a time. Multiple rapid mutations automatically merge together.
- **Queue**: Each mutation creates a separate transaction, guaranteed to run in the order they're made (FIFO by default, configurable to LIFO).

**Core Features:**

- **Pluggable Strategy System**: Choose from debounce, queue, or throttle strategies to control mutation timing
- **Auto-merging Mutations**: Multiple rapid mutations on the same item automatically merge for efficiency (debounce/throttle only)
- **Transaction Management**: Full transaction lifecycle tracking (pending → persisting → completed/failed)
- **React Hook**: `usePacedMutations` for easy integration in React applications

**Available Strategies:**

- `debounceStrategy`: Wait for inactivity before persisting. Only final state is saved. (ideal for auto-save, search-as-you-type)
- `queueStrategy`: Each mutation becomes a separate transaction, processed sequentially in order (defaults to FIFO, configurable to LIFO). All mutations are guaranteed to persist. (ideal for sequential workflows, rate-limited APIs)
- `throttleStrategy`: Ensure minimum spacing between executions. Mutations between executions are merged. (ideal for analytics, progress updates)

**Example Usage:**

```ts
import { usePacedMutations, debounceStrategy } from "@tanstack/react-db"

const mutate = usePacedMutations({
mutationFn: async ({ transaction }) => {
await api.save(transaction.mutations)
},
strategy: debounceStrategy({ wait: 500 }),
})

// Trigger a mutation
const tx = mutate(() => {
collection.update(id, (draft) => {
draft.value = newValue
})
})

// Optionally await persistence
await tx.isPersisted.promise
```
Loading
Loading