Products3 min read

Lattiq

Repairing a local-first editor, from a misread heartbeat to measured convergence after offline edits.

Built with Next.js, Lexical, Yjs, IndexedDB, WebSockets

Lattiq screenshot

The promise had to work

Lattiq is an editor whose document lives on the device before it lives on a server. The release work restores the actual Lexical-to-Yjs binding, local persistence and collaboration, then checks the difficult paths: reload while offline, concurrent offline edits and reconnecting to a persisted room.

A protocol error disguised as a bundling problem

What happened

Collaboration had been removed after a lib0 decoder error, leaving a standalone editor without the promised sync.

Why

The server answered a heartbeat with a byte the client interpreted as an awareness message, then tried to decode a payload that was not there. The report reproduces this without a bundler.

The fix

Give heartbeat traffic its own message type, restore CollaborationPlugin inside LexicalCollaboration, and use Lexical’s own Yjs binding to build valid seeds.

Persist the document, not an outgoing queue

An in-memory offline buffer disappears on reload. A convincing offline demo must survive closing and reopening the page.

  • Queue unsent messages in memory

    Works only while the tab stays alive.

  • Persist Yjs state in IndexedDBChosen

    Load local state and apply the seed after the binding is ready, then connect and exchange missing state using Yjs state vectors.

Offline edits survive reload. A browser and server applying the same deterministic seed retain one copy. Undo follows the collaborative document rather than treating remote changes as local history.

A bounded room server

The room server validates document names and can require expiring, room-scoped HMAC tokens. Presence belongs to a socket and is removed when it leaves. Disk writes use a temporary file and rename. This is a single-instance design with anonymous per-tab identities, not a multi-tenant permissions system.

Measured on localhost

Cold book load
269 ms median127,360 words; empty IndexedDB; navigation to all blocks in the DOMSource: docs/live-sync-report.md and bench/results.json, release branch, 20 November 2026
Warm load with server down
213 ms medianThe same book loaded from IndexedDBSource: docs/live-sync-report.md, Measurements table
Keystroke to remote DOM
1.4 ms median100 single-keystroke samples on localhost; not internet latencySource: docs/live-sync-report.md, Measurements table
Offline merge after sockets reopen
21 ms median5 samples; excludes reconnect backoff. From server restart: 786 ms median.Source: docs/live-sync-report.md, Measurements table

What those numbers establish

The measurements use a production build and headless Chrome on an Apple M3, without network throttling. They measure the local code path. A hosted collaboration service will add network latency and needs a separate measurement. The browser tests cover two-way edits, presence removal, offline reload and convergence, seed deduplication, token rejection and console errors.