optimistic-ui
Skill15 starsChanged 5 days agoMITView on GitHub
Implements optimistic UI updates for user mutations (messages, edits, toggles, image uploads) using stable client IDs and content hashes, flicker-free image swaps, and restrained enter-only micro-animations. Use when building interactive mutations, chat/messaging flows, forms, file/image uploads, or fixing UI flicker during network reconciliation.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- claudialnathan/skillstheir own version, first seen Nov 15, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- claudialnathan/skills★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- agent-instruction-auditSkill
- agent-tool-auditSkill
- changes-verificationSkill
- cheap-ui-auditSkill
- code-reviewSkill
- create-prSkill
- debuggingSkill
- engineering-decisionSkill
- formal-verificationSkill
- micro-animationSkill
- optimize-ciSkill
- oxlint-setupSkill
- test-auditSkill
- zstack-modeSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 10
Read references/patterns.md when implementing optimistic state stores, flicker-free image uploads, or WebSocket/SSE deduplication.
- Very specific: line 24
Generate a stable
clientId: Create a UUID (crypto.randomUUID()) or idempotency key client-side before issuing the request. - Very specific: line 26
Reconcile in place: When the server responds, merge serverId and canonical fields into the existing record matched by clientId without …
- Distinctive: line 31
Never allow reconciliation to unmount and remount DOM nodes:
- Very specific: line 39
When the remote URL returns, preload and decode it off-screen (img.decode()) before swapping src, and only revoke the object URL …
- Very specific: line 46
Zero re-animation on reconciliation: Keep the element mounted when status transitions from pending to synced.
- Very specific: line 47
No layout-thrashing animations: Never animate height, width, margin, or top/left for status badges or retry banners.
- Very specific: line 61
Always call URL.revokeObjectURL after remote image handoff or component unmount to prevent memory leaks.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Optimistic UI
Make every user mutation feel instantaneous by updating UI state immediately, reconciling server responses in place via stable client IDs and hashes, and ensuring reconciliation never unmounts nodes, flickers images, or replays animations.
Read references/patterns.md when implementing optimistic state stores, flicker-free image uploads, or WebSocket/SSE deduplication.
When to Use
- Sending chat messages, comments, posts, or form submissions
- Updating, toggling, reordering, or deleting UI records
- Uploading and previewing optimistic images, attachments, or avatars
- Fixing UI flashes, lost focus/scroll jumps, or re-triggered animations on API confirmation
Core Optimistic Pattern
Apply this lifecycle to every user-initiated mutation:
- Snapshot prior state: Capture rollback state before mutating so failures can roll back or surface inline retry cleanly.
- Generate a stable
clientId: Create a UUID (crypto.randomUUID()) or idempotency key client-side before issuing the request. - Mutate state immediately: Insert or update the item with
status: "pending"andclientId. - Reconcile in place: When the server responds, merge
serverIdand canonical fields into the existing record matched byclientIdwithout changing its UI key. - Handle failures gracefully: On error, set
status: "failed"with inline Retry/Discard controls (for user-authored content) or roll back cleanly (for toggles/reactions).
Stable IDs, Hashes & Image Uploads
Never allow reconciliation to unmount and remount DOM nodes:
- Keep UI list keys immutable: Key rendered items by
clientId(never swapkey={tempId}tokey={serverId}, and never key mutable lists by array index). Swapping keys destroys and recreates DOM nodes, causing flashes, lost scroll/focus, and replayed enter animations. - Deduplicate with idempotency keys: Send
clientIdin the mutation payload and echo it back in both REST responses and WebSocket/SSE events so retries and real-time updates merge in place instead of appending duplicates. - Flicker-free optimistic image uploads:
- Compute a stable attachment
clientIdand content hash (SHA-256 of file bytes orname + size + lastModifiedpaired withclientId) before starting upload. - Render immediately via
URL.createObjectURL(file)inside a container with locked dimensions (aspect-ratioor explicit width/height) to eliminate layout shift. - Render upload progress as a lightweight overlay (
opacity/transform) without resizing the media frame. - When the remote URL returns, preload and decode it off-screen (
img.decode()) before swappingsrc, and only revoke the object URL (URL.revokeObjectURL) after the remote image is verified ready (or on unmount).
- Compute a stable attachment
Animation Discipline
Pair optimistic updates with restrained, composite-only motion:
- Animate only on initial insertion: Play one
ease-outenter transition (150msto220ms,transform+opacity) when the optimistic item is inserted. - Zero re-animation on reconciliation: Keep the element mounted when
statustransitions frompendingtosynced; transition only subtle indicators (such asopacity: 0.7 -> 1.0over120ms ease-out). - No layout-thrashing animations: Never animate
height,width,margin, ortop/leftfor status badges or retry banners; reserve space or animatetransformandopacity. - Honor
prefers-reduced-motion: Fall back to instant updates or subtleopacityfades when reduced motion is active.
Red Flags
- Using
serverIdor array index as the UIkeyand swapping keys after API confirmation - Blocking UI updates until the network request finishes
- Swapping a local blob preview
srcto an uncached remote URL before decoding completes (causes image blink) - Replaying enter animations when REST or WebSocket confirmation arrives
- Dropping user input on network failure instead of providing Retry
Gotchas
- Propagate
clientIdthrough both REST responses and real-time streams (WebSockets/SSE) so real-time echoes reconcile the optimistic item in place. - Always call
URL.revokeObjectURLafter remote image handoff or component unmount to prevent memory leaks.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

