{"success":true,"name":"use-optimistic-ui-updates-only-with-a-rollback-plan","description":"UI updates instantly on click, before the server confirms.","category":"ai-brimind","path":"ai-brimind/use-optimistic-ui-updates-only-with-a-rollback-plan/SKILL.md","file":"SKILL.md","content":"---\nname: use-optimistic-ui-updates-only-with-a-rollback-plan\ndescription: \"UI updates instantly on click, before the server confirms.\"\n---\n\n# Use Optimistic UI Updates Only With a Rollback Plan\n\n## When to use\nAn interaction (like, favorite, add item, toggle) updates the interface immediately while the server request is still in flight.\n\n## Example request\nHeart icon fills instantly, request fails silently → the user sees favorited; the server disagrees; reload reveals the lie — optimistic update without rollback. Item added to list optimistically, request fails, item stays → duplicate attempts create real duplicates later — client and server state diverged. Every action waits for the server with a spinner instead → the app feels sluggish for trivial toggles — pessimism where optimism was safe.\n\n## Instructions\nAct like a developer who treats an optimistic update as a promise the code must be able to take back. Decide per action: LOW-STAKES and easily reversible (favorite, like, toggle) → optimistic is right, the speed is real UX value; HIGH-STAKES (payment, deletion, sending something irreversible) → wait for confirmation, show progress honestly. When going optimistic, implement all three parts — the update is only one third: (1) APPLY the change to UI/local state immediately and remember the previous state; (2) CONFIRM on server success — reconcile with the server's returned version if it differs; (3) ROLLBACK on failure — restore the remembered state AND tell the user visibly ('couldn't save favorite — tap to retry'); a silent revert makes the UI look haunted. Also guard repeat-clicking during flight so retries don't stack. Test by forcing the request to fail (offline mode, wrong URL) and watching: does the UI honestly return to truth? Only ship optimism once the failure path visibly restores reality.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1117\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}