AddThisFeature

Optimistic Updates

Make actions feel instant while still recovering cleanly when the server disagrees.

involved User Experience

What it adds

Apply the expected result of a mutation immediately, then reconcile with the server response or roll back.

What your agent is told to do

5
  1. 1

    Apply optimism only to actions that almost always succeed and are cheap to reverse: toggles, reordering, renaming, adding a comment.

  2. 2

    Keep the pre-mutation value so a failure can restore exactly that, and no more.

  3. 3

    Give newly created records a temporary client identifier and swap it for the server identifier when the response lands, updating anything already referencing it.

  4. 4

    Show the pending item as pending. Instant does not mean pretending the write already reached the server.

  5. 5

    Do not apply optimism to payments, deletions of anything expensive to recreate, or actions with side effects the user cannot see. Wait for the server and say so.

Edge cases it handles

6
  • A rollback must revert only its own mutation, leaving later successful changes to the same record intact.
  • Responses arriving out of order must not overwrite a newer value with an older one. Sequence them.
  • A permission or validation failure discovered on the server needs a real explanation, not a silent revert.
  • The revert must not jump the scroll position or move the item the user is about to click.
  • A mutation on an item the user has since navigated away from still has to report its failure somewhere.
  • Repeated failures against the same record should stop being optimistic and fall back to waiting.

Definition of done

8
  • Eligible actions render immediately and show a pending state.
  • A failure reverts only that mutation and explains what happened.
  • Temporary client IDs are reconciled with server IDs, including in referencing views.
  • Out-of-order responses cannot restore stale values.
  • Reverts do not shift layout or scroll position.
  • Irreversible and side-effecting actions are excluded by design.
  • The feature matches the existing design system.
  • No existing functionality is broken.

Related features

How it works

  1. 1

    Copy the link

    Grab the Markdown instruction URL for this feature.

  2. 2

    Give it to your AI

    Paste it into Claude Code, Cursor, v0, Lovable — whatever you build with.

  3. 3

    It inspects, then implements

    Your agent reads your existing app first, then adds the feature to fit it.

Works with your stack

These instructions are written to adapt. They tell the agent to detect your framework, match your existing design system, and reuse what you already have — rather than assuming a particular stack.

Need it tighter than that? Customize the feature and tell it exactly what you're running.