Add synced state introspection APIs for conflict detection#1245
Draft
KyleAMathews wants to merge 3 commits intomainfrom
Draft
Add synced state introspection APIs for conflict detection#1245KyleAMathews wants to merge 3 commits intomainfrom
KyleAMathews wants to merge 3 commits intomainfrom
Conversation
…te conflicts When using paced/debounced mutations alongside server-side updates (e.g., from websockets), pending optimistic mutations can overwrite incoming server state. This adds a `rollbackOptimisticUpdates(keys?)` method on Collection that cancels pending transactions for specific keys (or all keys), allowing the server update to take precedence. Also makes the paced mutations commit callback resilient to externally rolled-back transactions — instead of throwing when the debounce/throttle timer fires after a rollback, it silently clears the reference and allows the next mutation to create a fresh transaction. https://claude.ai/code/session_01FPgcCTxP2SC8NTeWx9xhJV
…paced mutations Replace rollbackOptimisticUpdates with synced state introspection. Rolling back optimistic updates would yank controlled input state out from under the user mid-keystroke. Instead, expose the server-side state so the mutationFn can detect conflicts at persist time and reconcile (merge, skip, or retry) without disrupting the UI. - `collection.getSyncedValue(key)` — returns the authoritative server value for a key, ignoring optimistic overlays - `collection.getSyncedMetadata(key)` — returns sync metadata (revision numbers, ETags, etc.) for conflict detection The paced mutations commit callback is also made resilient to externally rolled-back transactions (e.g. via manual tx.rollback() or cascade) so the debounce/throttle timer doesn't throw. https://claude.ai/code/session_01FPgcCTxP2SC8NTeWx9xhJV
|
…s-server-updates-IKyA0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Changes
This PR adds two new public APIs to the
CollectionImplclass to enable introspection of synced (server-side) state, independent of optimistic updates:getSyncedValue(key)- Returns the authoritative server-side value for a given key, ignoring any pending optimistic mutations. This allows applications to detect server-side changes and implement conflict resolution strategies.getSyncedMetadata(key)- Returns sync metadata (e.g., revision numbers, ETags) associated with a synced entity, useful for version-based conflict detection.These APIs enable robust conflict detection in paced mutations by allowing the
mutationFnto compare the original mutation state against the current server state before persisting changes. The PR includes comprehensive test coverage demonstrating:Additionally, the paced mutations implementation is hardened to gracefully handle external transaction rollbacks (e.g., from cascade conflicts or manual rollback). When a debounce fires after a transaction has been externally cancelled, the strategy callback now safely returns early instead of throwing an error, and the next
mutate()call creates a fresh transaction.✅ Checklist
pnpm test:pr.🚀 Release Impact
https://claude.ai/code/session_01FPgcCTxP2SC8NTeWx9xhJV