Clarify local write status docs and pending sync contract#1652
Clarify local write status docs and pending sync contract#1652KyleAMathews wants to merge 5 commits into
Conversation
📝 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: +1 B (0%) Total Size: 125 kB 📦 View Changed
ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 4.26 kB ℹ️ View Unchanged
|
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
Documentation
Bug Fixes
Tests