Skip to content
Source
Sign inSign up
TanStack/db

usePacedMutations value regression while persisting #1060

Send to my agent
Closedfcannizzaro(GitHub profile, opens in a new tab) opened this issue 1 comment
  • I've validated the bug against the latest version of DB packages

Describe the bug (I tested this using only electric) It seems there is a regression (to the latest value before any optimistic update) in collection's data using paced mutations while persisting (that also causes a re-render, that seems an ui glitch).

It seems similar to #904, but the behavior is somehow different.

To Reproduce https://github.com/fcannizzaro/tanstack-db-previous-value/

Expected behavior It should keep the latest value while persisting (like the non paced mutation)

Screenshots

UILogs
ImageImage
  1. Thanks for the clear reproduction. I checked this again on current main (bef12e24).

    In the linked InputsBroken.tsx, the paced mutationFn waits for updatePost to return { txid }, but it does not wait for that transaction to arrive through Electric. The Collection's separate onUpdate handler is not invoked by this paced mutation. That means the optimistic transaction can finish before the source update is acknowledged. A controlled replay on current main reproduced the reported fallback from the second optimistic value to the original value (0 → 1 → 2 → 0) when both handlers resolved before source acknowledgement.

    The paced handler needs to await Electric explicitly after the server write:

    const { txid } = await updatePost({ data: { id, changes } })
    await postCollection.utils.awaitTxId(txid)

    I also replayed same-row edits 0 → 1 → 2 with handlers held until their source updates, using queue and debounce strategies. The debounce cases included the second write starting before the first acknowledgement. At every checkpoint after the second edit, both the Collection and an ordered, limited live-query Collection remained at 2; the live-query callback after that edit reported only 2. These are controlled core and live-query checks, not a full React/Electric/PostgreSQL host run.

    I’m closing this based on the documented awaitTxId handler contract. If the rollback still occurs after adding that await to the paced mutationFn, please reopen with the updated repro and the order of the returned txids and Electric stream messages. That would give us the missing legal-path trace to investigate.

Sign in to join this conversation.