Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/migrate-to-pacer-lite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tanstack/db": patch
---

Migrated paced mutations implementation from `@tanstack/pacer` to `@tanstack/pacer-lite`. The lite version provides the same core functionality with minimal overhead and no external dependencies, making it more suitable for library use. This is an internal implementation change with no impact on the public API - all paced mutation strategies (debounce, throttle, queue) continue to work exactly as before.
2 changes: 1 addition & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@standard-schema/spec": "^1.0.0",
"@tanstack/db-ivm": "workspace:*",
"@tanstack/pacer": "^0.16.3"
"@tanstack/pacer-lite": "^0.1.0"
},
"devDependencies": {
"@vitest/coverage-istanbul": "^3.2.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/strategies/debounceStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Debouncer } from "@tanstack/pacer/debouncer"
import { LiteDebouncer } from "@tanstack/pacer-lite/lite-debouncer"
import type { DebounceStrategy, DebounceStrategyOptions } from "./types"
import type { Transaction } from "../transactions"

Expand Down Expand Up @@ -28,7 +28,7 @@ import type { Transaction } from "../transactions"
export function debounceStrategy(
options: DebounceStrategyOptions
): DebounceStrategy {
const debouncer = new Debouncer(
const debouncer = new LiteDebouncer(
(callback: () => Transaction) => callback(),
options
)
Expand Down
31 changes: 22 additions & 9 deletions packages/db/src/strategies/queueStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AsyncQueuer } from "@tanstack/pacer/async-queuer"
import { LiteQueuer } from "@tanstack/pacer-lite/lite-queuer"
import type { QueueStrategy, QueueStrategyOptions } from "./types"
import type { Transaction } from "../transactions"

Expand Down Expand Up @@ -44,16 +44,29 @@ import type { Transaction } from "../transactions"
* ```
*/
export function queueStrategy(options?: QueueStrategyOptions): QueueStrategy {
const queuer = new AsyncQueuer<() => Transaction>(
async (fn) => {
const transaction = fn()
// Wait for the transaction to be persisted before processing next item
// Note: fn() already calls commit(), we just wait for it to complete
await transaction.isPersisted.promise
// Manual promise chaining to ensure async serialization
// LiteQueuer (unlike AsyncQueuer from @tanstack/pacer) lacks built-in async queue
// primitives and concurrency control. We compensate by manually chaining promises
// to ensure each transaction completes before the next one starts.
let processingChain = Promise.resolve()

const queuer = new LiteQueuer<() => Transaction>(
(fn) => {
// Chain each transaction to the previous one's completion
processingChain = processingChain
.then(async () => {
const transaction = fn()
// Wait for the transaction to be persisted before processing next item
await transaction.isPersisted.promise
})
.catch(() => {
// Errors are handled via transaction.isPersisted.promise and surfaced there.
// This catch prevents unhandled promise rejections from breaking the chain,
// ensuring subsequent transactions can still execute even if one fails.
})
},
{
concurrency: 1, // Process one at a time to ensure serialization
wait: options?.wait,
wait: options?.wait ?? 0,
maxSize: options?.maxSize,
addItemsTo: options?.addItemsTo ?? `back`, // Default FIFO: add to back
getItemsFrom: options?.getItemsFrom ?? `front`, // Default FIFO: get from front
Expand Down
4 changes: 2 additions & 2 deletions packages/db/src/strategies/throttleStrategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Throttler } from "@tanstack/pacer/throttler"
import { LiteThrottler } from "@tanstack/pacer-lite/lite-throttler"
import type { ThrottleStrategy, ThrottleStrategyOptions } from "./types"
import type { Transaction } from "../transactions"

Expand Down Expand Up @@ -48,7 +48,7 @@ import type { Transaction } from "../transactions"
export function throttleStrategy(
options: ThrottleStrategyOptions
): ThrottleStrategy {
const throttler = new Throttler(
const throttler = new LiteThrottler(
(callback: () => Transaction) => callback(),
options
)
Expand Down
Loading
Loading