# Building a Local-First Collaborative Editor With Yjs, Lexical, and IndexedDB

DevFeed: [Building a Local-First Collaborative Editor With Yjs, Lexical, and IndexedDB](<https://devfeed.tech/articles/building-a-local-first-collaborative-editor-with-yjs-lexical-and-indexeddb-147794.md>)

Original publisher: [Read original article](<https://hackernoon.com/building-a-local-first-collaborative-editor-with-yjs-lexical-and-indexeddb?source=rss>)

Author: sammii

Published: 2026-11-22T05:00:02Z

Content type: tutorial

Language: en

Sources: [HackerNoon](<https://devfeed.tech/sources/hackernoon.md>)

Topics: [Local-First](<https://devfeed.tech/topics/local-first.md>), [Kakoune](<https://devfeed.tech/topics/kakoune.md>), [LocalStorage](<https://devfeed.tech/topics/localstorage.md>), [autosave](<https://devfeed.tech/topics/autosave.md>), [User interface design](<https://devfeed.tech/topics/ui-design.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [authentication](<https://devfeed.tech/tags/authentication.md>), [business-strategy](<https://devfeed.tech/tags/business-strategy.md>), [content-creation](<https://devfeed.tech/tags/content-creation.md>), [crdt](<https://devfeed.tech/tags/crdt.md>), [data-science](<https://devfeed.tech/tags/data-science.md>), [editor](<https://devfeed.tech/tags/editor.md>), [indexeddb](<https://devfeed.tech/tags/indexeddb.md>), [lexical](<https://devfeed.tech/tags/lexical.md>), [local-first](<https://devfeed.tech/tags/local-first.md>), [web-development](<https://devfeed.tech/tags/web-development.md>), [websocket-synchronization](<https://devfeed.tech/tags/websocket-synchronization.md>), [yjs-crdts](<https://devfeed.tech/tags/yjs-crdts.md>)

## AI overview

Lattiq keeps the Yjs document canonical in the browser, persists it with IndexedDB, and syncs through a WebSocket when available. Yjs CRDT edits can merge after collaborators work offline; unlike the article's description of operational transform in Google Docs, this does not require a central server to order edits. The article emphasizes initialization order: wait for IndexedDB to load before rendering Lexical or connecting the socket, avoiding races and visible content problems. Lexical's Provider abstraction uses either a real WebSocket provider or a LocalProvider backed by the same Y.Doc, with Awareness for ephemeral cursor and user state. A five-state status model distinguishes never-connected local work from a dropped connection. The server maintains and broadcasts room documents; Lattiq caps reconnection attempts at ten with exponential backoff to limit mobile battery use. Awareness resets on reconnect and must be rebroadcast.

## Source excerpt

Most collaborative editors break the moment the connection drops. Lattiq does not, because the source of truth is the user's own browser. This is how to wire...