You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Fix syncedData not updating on manual writes in mutationFn (#1130)
* fix(db): ensure manual writes update syncedData during persisting transactions
Manual write operations (writeInsert, writeUpdate, writeDelete, writeUpsert)
were not updating syncedData when called from within a mutation handler
(e.g., onUpdate with refetch: false). This caused an "off by one" bug where
the cache would show stale data until the next sync operation.
Root cause: commitPendingTransactions() skipped processing sync transactions
when a persisting user transaction was active, but manual writes need to
update syncedData synchronously.
Fix: Add an `immediate` flag to sync transactions. When begin() is called
with { immediate: true }, the transaction bypasses the persisting transaction
check and is processed immediately. Manual write operations now use this flag.
Changes:
- Add `immediate?: boolean` to PendingSyncedTransaction interface
- Update begin() to accept optional { immediate?: boolean } parameter
- Modify commitPendingTransactions() to process immediate transactions
regardless of persisting transaction state
- Update performWriteOperations() to use begin({ immediate: true })
- Add regression test for writeUpsert in onUpdate with refetch: false
* refactor(test): use .some() for cleaner transaction state check
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* chore: add changeset for syncedData fix
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* docs: clarify why all committed sync txs are processed together
When hasImmediateSync or hasTruncateSync is true, we process ALL
committed sync transactions, not just the immediate ones. This
preserves causal ordering - if we only processed the immediate
transaction, earlier non-immediate ones would apply later and
could overwrite newer state.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
* refactor: simplify boolean checks in state.ts
Co-authored-by: Kevin <kevin-dp@users.noreply.github.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Kevin <kevin-dp@users.noreply.github.com>
Fix syncedData not updating when manual write operations (writeUpsert, writeInsert, etc.) are called after async operations in mutation handlers. Previously, the sync transaction would be blocked by the persisting user transaction, leaving syncedData stale until the next sync cycle.
0 commit comments