Clarify local write status docs and pending sync contract#1652
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthroughThis PR clarifies documentation for ChangesWrite-status semantics clarification
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
More templates
@tanstack/angular-db
@tanstack/browser-db-sqlite-persistence
@tanstack/capacitor-db-sqlite-persistence
@tanstack/cloudflare-durable-objects-db-sqlite-persistence
@tanstack/db
@tanstack/db-ivm
@tanstack/db-sqlite-persistence-core
@tanstack/electric-db-collection
@tanstack/electron-db-sqlite-persistence
@tanstack/expo-db-sqlite-persistence
@tanstack/node-db-sqlite-persistence
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/react-native-db-sqlite-persistence
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/tauri-db-sqlite-persistence
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: +80 B (+0.06%) Total Size: 125 kB 📦 View Changed
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 4.22 kB ℹ️ View Unchanged
|
| } | ||
|
|
||
| /** | ||
| * Checks if a row has pending optimistic mutations (not yet confirmed by sync). |
There was a problem hiding this comment.
I find "(not yet confirmed by sync)" clearer than "in the visible projection"
There was a problem hiding this comment.
One of the clarifications this PR is trying to make is that not all "confirmations by the collection" means that the write has been persisted to the backend e.g. powersync just confirms when the write is in the local sqlite. I pushed this commit which hopefully is clearer 4bbc268
Summary
Clarifies TanStack DB's existing local write status docs and tightens the core pending-sync contract around optimistic temp-key inserts. User-visible docs now distinguish local optimistic write state from backend upload/read-path confirmation, and the core test makes explicit that ambiguous server-key sync is not exposed while the local mutation is still pending.
Root cause
$syncedandtx.isPersisted.promisewere easy to read as backend confirmation APIs. In practice, they describe TanStack DB's local transaction/projection state: a row may have no pending local optimistic mutation without proving backend read-back, and a transaction may settle without representing a generic sync-observation guarantee.Approach
$syncedJSDoc to describe whether a row currently has pending local optimistic mutations in the collection's visible projection.isPersisted.promiseJSDoc to describe transaction settlement, including rollback/failure, while noting that non-empty commits normally settle through the mutation function.@tanstack/db.Key invariants
$syncedis local write/projection status; it is not backend upload, confirmation, or read-path observation.tx.isPersisted.promiseis the promise to await for transaction settlement; callers should not await the deferred object itself.Non-goals
Verification
Files changed
.changeset/clarify-local-write-status.md— records the patch-level docs/test clarification for@tanstack/db.packages/db/src/virtual-props.ts— clarifies$syncedas local pending optimistic write state.packages/db/src/transactions.ts— clarifiesisPersisted.promisetransaction settlement semantics.packages/db/src/collection/state.ts— aligns an internal$syncedhelper comment with the new wording.packages/db/tests/collection.test.ts— makes the ambiguous temp/server-key pending sync contract explicit.Refs #20, #661, #1017, #1166, #1215, #1219, #1322, #1431, #1526.
Summary by CodeRabbit
$syncedand row sync status) reflect pending local optimistic writes, not backend-confirmed state.isPersisted.promiselifecycle semantics.