home / skills / harborgrid-justin / lexiflow-premium / optimistic-ui-mutation-patterns
/frontend/.github-skills/optimistic-ui-mutation-patterns
This skill helps implement optimistic UI mutation patterns by updating local cache instantly, queuing mutations, and reliably rolling back on failure.
npx playbooks add skill harborgrid-justin/lexiflow-premium --skill optimistic-ui-mutation-patternsReview the files below or copy the command above to add this skill to your agents.
---
name: optimistic-ui-mutation-patterns
description: Implement immediate UI feedback for mutations with robust rollback capabilities.
---
# Optimistic UI Mutation Patterns
## Summary
Implement immediate UI feedback for mutations with robust rollback capabilities.
## Key Capabilities
- Update local cache instantly upon mutation trigger.
- Queue mutations to handle network race conditions.
- Rollback to the correct server state on failure.
## PhD-Level Challenges
- Manage dependency updates for optimistic data.
- Handle cascading optimistic updates correctly.
- Visualize the 'pending' state effectively.
## Acceptance Criteria
- Demonstrate immediate feedback on a slow network.
- Show accurate rollback upon mocked server error.
- Document the mutation queue logic.
This skill implements optimistic UI mutation patterns to give users immediate feedback while changes are processed in the background. It provides a local cache update, a mutation queue to resolve race conditions, and robust rollback logic to reconcile with the authoritative server state. The focus is predictable UX under slow or failing networks in a legal management platform context.
On mutation trigger the skill updates the local cache and UI instantly with an optimistic patch. The mutation is enqueued and sent to the server; responses are applied in order to avoid races. If the server rejects or returns a differing state, the skill computes and applies the correct rollback or reconciliation patch to restore accurate data. Pending states are surfaced so components can show transient indicators until the operation settles.
How does the system avoid lost updates when multiple mutations run concurrently?
Mutations are enqueued and applied in a deterministic order; each includes an ID/timestamp so later server results can be reconciled against the expected state and older optimistic patches can be adjusted or discarded.
What happens when rollback is required?
The skill computes the minimal inverse patch or fetches authoritative state from the server, applies the correction to the cache, and emits a failure event so UI components can surface messaging and allow retry.
How are pending states represented in the UI?
Pending states are explicit flags on affected records with optional lightweight deltas; components can show spinners, dimming, or badges while an operation is unresolved.