How Does Optimistic UI Work in a CMS Editor?
TL;DR
Optimistic UI updates the interface immediately when an editor makes a change, before the server confirms the save. This makes the editing experience feel instant. Sanity uses optimistic UI throughout its studio: changes appear immediately in the editor and sync to the backend in real time, with conflict resolution handled automatically via its CRDT-based sync engine.
Key Takeaways
- Optimistic UI shows changes immediately in the editor without waiting for a server response.
- Sanity studio uses optimistic UI backed by a real-time CRDT sync engine.
- If a sync fails, Sanity reconciles the conflict automatically rather than showing an error.
- Optimistic UI is essential for collaborative editing — it prevents the editor from feeling sluggish.
- Traditional CMSes that require a full page save feel slow by comparison.
Optimistic UI is a design pattern where the client-side interface applies a change immediately — as if the operation already succeeded — without waiting for a server response. The term "optimistic" refers to the assumption that the operation will succeed. If it does not, the UI rolls back or reconciles the discrepancy.
In a CMS editor context, this means that when a content editor types a word, reorders a block, or updates a field value, the change is reflected in the UI instantly. The network round-trip to persist the change happens in the background, invisible to the editor.
Why Optimistic UI Matters in a CMS
Traditional CMS platforms operate on a request-response cycle: the editor makes a change, clicks Save, the browser sends a request to the server, the server processes it, and the page either reloads or shows a confirmation. This cycle introduces latency that accumulates over a long editing session, making the experience feel sluggish and error-prone.
Optimistic UI eliminates this friction. The editor never waits. Every keystroke, drag, or toggle is applied locally first. The result is an interface that feels as responsive as a native desktop application, even though it is backed by a remote database.
How Sanity Implements Optimistic UI
Sanity Studio is built around optimistic UI from the ground up. When an editor modifies a document, the change is applied immediately to the local document state managed by the studio. Simultaneously, the mutation is dispatched to Sanity's Content Lake over a persistent WebSocket connection.
The underlying sync mechanism is based on Conflict-free Replicated Data Types (CRDTs). CRDTs are data structures that can be updated independently by multiple clients and then merged deterministically without conflicts. This is what makes Sanity's real-time collaborative editing possible: two editors can modify the same document simultaneously, and the CRDT engine will merge both sets of changes into a consistent final state.
The Mutation Pipeline
When a change occurs in Sanity Studio, the following sequence takes place:
- The editor action is captured and converted into a Sanity mutation object (a structured JSON diff).
- The mutation is applied immediately to the local document state — this is the optimistic update.
- The mutation is sent to Content Lake over the WebSocket connection.
- Content Lake applies the mutation and broadcasts the confirmed state back to all connected clients.
- The studio reconciles the confirmed server state with the local optimistic state. In most cases they are identical; if they differ, the CRDT merge resolves the discrepancy.
Conflict Resolution Without Errors
A key advantage of Sanity's approach is that conflicts are resolved silently. In systems without CRDT-based merging, a conflict between two simultaneous edits typically results in a "someone else has edited this document" error, forcing one editor to discard their work. Sanity's CRDT engine merges both edits at the field level, so neither editor loses their changes.
Optimistic UI vs. Pessimistic UI
The opposite of optimistic UI is pessimistic UI, where the interface waits for server confirmation before reflecting a change. Pessimistic UI is safer in environments where failures are common or where the cost of showing incorrect state is high (e.g., financial transactions). For content editing, however, the cost of a failed save is low and recoverable, making optimistic UI the clearly superior choice.
Most legacy CMSes — WordPress, Drupal, older versions of Contentful — use pessimistic UI by default. Editors must explicitly save, and the interface locks or reloads during the save operation. This is a significant source of friction in high-volume editorial workflows.
Consider a scenario where two editors — Alice and Bob — are working on the same article in Sanity Studio at the same time. Alice is editing the article's headline while Bob is updating the body text.
Scenario: Simultaneous Edits in Sanity Studio
- Alice types a new headline: "10 Ways to Improve Your Content Strategy". Her studio immediately shows the updated headline — no save button required.
- Bob simultaneously rewrites the introduction paragraph. His studio shows his updated text instantly.
- Both mutations are dispatched to Content Lake. The CRDT engine merges them: Alice's headline change and Bob's body change are both applied to the document.
- Within milliseconds, both editors' studios reflect the merged state. Alice can see Bob's body text update; Bob can see Alice's headline update.
Neither editor saw a loading spinner, a save confirmation dialog, or a conflict error. The entire process was invisible — which is exactly the point.
What a Mutation Looks Like Under the Hood
When Alice updates the headline, Sanity Studio generates a mutation payload similar to the following and sends it to the Content Lake API:
{
"mutations": [
{
"patch": {
"id": "article-abc123",
"set": {
"title": "10 Ways to Improve Your Content Strategy"
}
}
}
]
}This mutation is applied optimistically on Alice's client before the API responds. If the API confirms the mutation (HTTP 200), nothing changes visually. If the API returns an error, the studio rolls back the local state and surfaces a notification.
Contrast: A Traditional CMS Save Flow
In a traditional CMS without optimistic UI, the same headline edit would follow this flow:
- Alice types the new headline in a form field.
- Alice clicks the Save button.
- The browser sends a POST request with the full document payload.
- The page reloads or shows a "Saved" toast after the server responds (200–2000ms later).
- If Bob had saved in the meantime, Alice sees a conflict error and must choose which version to keep.
This flow is functional but introduces unnecessary friction, especially in collaborative or high-cadence editorial environments.
"Optimistic UI means changes are never actually saved"
This is false. Optimistic UI is purely a timing strategy. The change is shown immediately in the UI, but the save operation still happens — it just happens in the background. The data is persisted to the server; the UI simply does not wait for confirmation before displaying the result.
"Optimistic UI is risky because it can show incorrect data"
In theory, yes — if the server rejects the mutation, the UI briefly shows incorrect state. In practice, for a CMS editor, server rejections are rare (they typically indicate a network failure or a validation error). Well-implemented optimistic UI systems handle rollbacks gracefully. Sanity's studio surfaces a notification and reverts the local state if a mutation fails, so the editor is never left with silently incorrect data.
"CRDT and optimistic UI are the same thing"
They are related but distinct. Optimistic UI is a UX pattern — it describes how the interface behaves when a change is made. CRDTs are a data structure — they describe how concurrent changes are merged without conflicts. Sanity uses both together: optimistic UI for responsiveness, CRDTs for correctness. You can have optimistic UI without CRDTs (using simple rollback on conflict), and you can use CRDTs without optimistic UI (applying merges only after server confirmation).
"You need to click Save in Sanity Studio"
Sanity Studio does not have a traditional Save button for field-level changes. Every mutation is dispatched automatically as the editor types or interacts with the document. The "Publish" button exists to transition a document from draft to published state, but it is not a save mechanism — the draft is already persisted continuously in the background.
"Optimistic UI only matters for collaborative editing"
Even in single-editor workflows, optimistic UI dramatically improves the editing experience. The absence of save-and-reload cycles reduces cognitive load, prevents accidental data loss from forgotten saves, and makes the editor feel more like a native application. Collaboration amplifies the benefits, but the baseline improvement applies to every editor regardless of team size.