Why optimistic updates are corrosive

I was having an X conversation with @ben_codez, and they asked: why is showing an update as succeeded, before the underlying operation has actually succeeded, corrosive?

我曾在 X 上与 @ben_codez 进行过对话,他们问道:为什么在底层操作真正成功之前就显示更新已成功,会具有腐蚀性?

It’s corrosive because it normalizes software that is plainly broken and doesn’t respect our users. If a user flips a switch, and sees it flip, and then comes back, and the switch is unflipped, the software is broken. How can you operate software that doesn’t do what you request it to do? It erodes trust.

这种做法具有腐蚀性,因为它使那些明显损坏且不尊重用户的软件变得常态化。如果用户拨动开关,看到它翻转了,随后回来发现开关又变回原样,那么这个软件就是坏的。你如何操作一个无法执行你所请求操作的软件?这会侵蚀信任。

Ben’s position I made a chart of what I understand to be Ben’s position on communicating with their users. “Booking confirmed” shown before the server checks the seat No self respect Ben: “No self respecting dev would show the user a booking had succeeded before server verification.” Ben’s line Your like shows as done before the server says “ok” Ben: “liking a post”, “(It can retry silently).” If the user closes the tab before the server has it, their like is lost and the user is never told.

Ben 的立场:我制作了一张图表,表达了我对 Ben 在与用户沟通方面的立场理解。“预订确认”在服务器检查座位前显示。缺乏自尊的 Ben:“没有一个有自尊的开发者会在服务器验证前就向用户显示预订已成功。” Ben 的底线:你的点赞在服务器说“确定”之前就显示已完成。Ben:“点赞帖子”,“(它可以静默重试)”。如果用户在服务器收到请求前关闭标签页,他们的点赞就会丢失,且用户永远不会被告知。

Instant intent show only what is known to be true Your post shows greyed out until the server says “ok” Ben: “Right!”, to a post shown “greyed out maybe, to indicate it wasn’t committed”.

即时意图:只显示已知为真的内容。你的帖子显示为灰色,直到服务器说“确定”。Ben:“没错!”,对于显示为“灰色或许是为了表明它尚未提交”的帖子。

Demo But in addition to that, it’s actually easier to make software that doesn’t lie to your users. You can skip all the reconciliation machinery that’s required to create UI that communicates to users that the change they thought had gone through had indeed not gone through.

演示:但除此之外,制作不欺骗用户的软件实际上更容易。你可以跳过所有为了创建 UI 而必需的协调机制,这些机制原本是为了告知用户他们以为已经完成的更改实际上并未完成。

Here’s a quick demo of using instant intent to communicate the state toggling a switch e.g. a like button. on add extra latency 0 ms 50 ms 200 ms 500 ms 1 s 5 s offline

这是一个使用即时意图来传达状态切换(例如点赞按钮)的快速演示。开启,增加额外延迟:0 毫秒、50 毫秒、200 毫秒、500 毫秒、1 秒、5 秒、离线。

Client-side affordances When you click the switch, the client shows the button as pressed straight away and sends the click to the server. The switch takes no more clicks while it’s pressed, and if there’s no answer within half a second, it starts to blink. The client then won’t update until the server answers with the reconciled HTML view, which Datastar morphs in place.

客户端交互:当你点击开关时,客户端会立即显示按钮为按下状态,并将点击发送到服务器。在按下期间,开关不再接受其他点击;如果半秒内没有响应,它会开始闪烁。随后,客户端不会更新,直到服务器返回协调后的 HTML 视图,Datastar 会将其原地变形(morph)。

Experiment with different latencies and taking it offline, to see how the interaction feels under different scenarios. The pressed and blinking look is the same CSS the seats use, on the main page.

尝试不同的延迟并将其离线,看看在不同场景下交互的感觉如何。按下和闪烁的外观与主页面上座位所使用的 CSS 相同。