Building an Optimistic User Interface in React
blog.bitsrc.io
blog.bitsrc.io
So, a user on a slow network thinks that the request went through and closes the tab. Boom! You've got yourself the first version of MongoDB on the client side!
Somethings we use are already optimistic - When you use Jira to drag and drop tasks, the drop event occurs immediately, without waiting for network response.
There is nothing break thru about this pattern.
There are a lot of ways that google docs indicate to you that you might lose your data, but unless you have the engineering resources and time to invest into accomodatingg and recovering from every potential failure scenario in a distributed system, it’s better to focus on building a transparent product that fails quickly and clearly when something isn’t right. Optimistic UI, when done badly, makes users mistrust the data they’re presented. Trust is more fundamental to a product’s value than how zippy it feels.
But dear God please don’t use it in Enterprise apps.
action -> UI recognition of action -> display API response
For actions that succeed 99% of the time, I think the "UI recognition of action" can be the success state. For actions with higher failure rates, the "UI recognition" should be a spinner or something to show the user that work is being done.If you've got a project where it's not acceptable to show "success" -> "oops I mean failure", just go with the spinner all the time. But, it makes a huge difference if you respond to a click in < 100ms vs. > 100ms.
> An Optimistic User Interface is when a user triggers an action and the UI updates immediately, even though there may be a request pending.
This is also called "lying to your users"
This is the same principle that multiplayer games use. When a game character is moved in a particular direction, the client shows "optimistic" movement before the server confirms the movement. This is the difference between a playable and unplayable game in many cases.
It turns out, though, that it might take _weeks_ for the cheque to clear, and they reserve the right to reverse the deposit and ding me for an NSF fee at any time.
Users often prefer optimistic processes to ACID trips.
In the article it describes reverting the state of the component if the action fails, asynchronously. IMO that’s much worse than briefly representing a progress state for a few ms.
Two things.
1. Likes are not a small detail of a social network app
2. If you're handling a failure state when the HTTP request comes back (like the author does), handling the success state is just an `else`
Is optimistic, but is not lying.
But if it make believe something have happened whitout proper feedback....
Doesn't this introduce unnecessary complexity?