Skip to content

optimistic UI updates with rollback for swap interface mutations #723

Description

@mikewheeleer

Summary

Mutations on the swap interface wait for the server before the UI reflects them, which feels sluggish and hides intent. Apply changes optimistically and roll back cleanly on failure.

Why this matters

Optimistic updates make the app feel instant while preserving correctness. Done right (with rollback + reconciliation), they improve UX without lying to the user.

Requirements

  • Apply swap interface mutations to local state immediately, before the server responds.
  • On success, reconcile with the server's canonical result.
  • On error, roll back to the pre-mutation state and surface a clear, accessible message.
  • Guard against a stale response overwriting a newer local change.

Technical guidance

  • Key the optimistic entry so the server echo can replace it deterministically.
  • Announce failures via a polite live region.

Edge cases — each must have a test

  • success -> optimistic value replaced by server value
  • error -> state rolls back exactly
  • rapid successive edits -> no stale overwrite
  • concurrent unrelated updates -> unaffected
  • failure is announced to assistive tech

Acceptance criteria

  • All requirements and every edge case above implemented and covered by tests
  • New unit and integration tests; existing tests still pass and no regressions
  • Structured, typed errors (no leaked internals; stable codes)
  • npm run lint, npm test, and npm run build all pass locally
  • Code follows the repo's existing conventions; no duplication or dead code
  • Short docs/comments explaining the design and any non-obvious decisions
  • PR description explains the approach and includes Closes #<issue>

Out of scope

  • Server-side conflict merging
  • Offline queueing

Rewards

Part of the GrantFox OSS / Official Campaign (FWC26) — this task may be rewarded. PR quality is assessed by AI: depth, correctness under edge cases, meaningful tests, and clean design are what earn the reward. Shallow changes (typos, formatting, trivial docs) do not qualify.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions