Skip to content

Support Non-Optimistic Mutations Within Transactions #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
KyleAMathews opened this issue Apr 28, 2025 · 0 comments
Open

Support Non-Optimistic Mutations Within Transactions #26

KyleAMathews opened this issue Apr 28, 2025 · 0 comments

Comments

@KyleAMathews
Copy link
Collaborator

Problem

Currently, all insert, update, and delete mutations immediately modify the local optimistic store upon transaction creation.
There is no way to mark a mutation as "non-optimistic" — meaning it should only apply locally after server confirmation.

This limits developer control in cases where immediate speculative updates are undesirable:

  • Inserts that depend on complex server-side generation (e.g., cascading foreign keys).
  • Deletes where UX should wait for confirmation before removing data.
  • Updates where backend-side validation or side-effects must be confirmed first.

Proposed Solution

Extend mutation methods to accept an optimistic option.

Example usage:

tx.collection('posts').insert({ title: 'New' }, { optimistic: true });
tx.collection('comments').delete('commentId', { optimistic: false });

Behavior

  • optimistic: true (default):

    • Immediately apply mutation to the local store.
    • Speculative view updates.
    • Rollback required if server rejects.
  • optimistic: false:

    • Do not modify local store immediately.
    • Queue mutation for server persistence.
    • Apply to store only after server confirmation.
    • No rollback necessary if server rejects (no state change was staged).

Design Principles

  • Unified transaction model: both optimistic and non-optimistic mutations live within the same transaction scope.
  • No new transaction modes.
  • No separate mutation API.
  • Explicit developer control per mutation.

Constraints

  • optimistic defaults to true for backward compatibility.
  • Non-optimistic mutations may still fail server-side; appropriate error handling must be surfaced.
  • No speculative local store impact for optimistic: false mutations.

Future Work

  • Potential support for mixed optimistic/non-optimistic batching strategies.
  • Extended tooling to visually distinguish speculative vs confirmed data if desired.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant