Optimistic UI & Rollback
Optimistic updates change the UI before the server confirms the operation. This can make interactions feel immediate, but it requires a rollback strategy.
For a simple toggle, the UI can update immediately, then revert if the server rejects the change. For complex mutations, preserve enough information to reconstruct the previous state or invalidate/refetch the affected data.
Optimistic UI is appropriate when the operation is likely to succeed and the temporary state is understandable. Do not hide important failures merely to make the UI feel fast.
Key Takeaways
- Optimistic UI needs a failure path.
- Keep enough information to rollback or invalidate stale data.
- Communicate pending or failed mutations clearly.