Optimistic UI updates: how do you roll back cleanly when the server says no?
I love how snappy optimistic updates feel. Tap "like," the counter goes up instantly, the request happens in the background. The trouble is when the request fails.
Right now I keep a copy of the previous state and restore it on error, plus a small toast saying it didn't save. That works for single fields but gets messy for lists where items are added, reordered and removed quickly.
How do you structure rollbacks for more complex updates? And do you tell the user every time, or only when it matters?
Comments · 3
For lists, restoring a snapshot can clobber other changes that landed in between. Many apps instead keep a queue of pending operations and replay the remaining ones on top of the server state after a failure, which also makes retries straightforward. A toast only for failures that actually lose the user's work keeps noise down.
Tell the user why it failed. A silent rollback is worse than a visible error, since people think the app is glitching.
Subtle animation on the revert helps, so the counter visibly goes back instead of just snapping. It communicates "that didn't go through".