Skip to main content

Block IDs

BlockIdExtension stores each block's id as NodeState, so ids sync through any collaboration binding that synchronizes NodeState.

  • Assignment. The collaborator who creates a block assigns its id. A pasted or duplicated block is repaired in the update that creates it, so it reaches the others with its own id. Two clients that put the same initial content into empty editors give it the same ids.
  • Duplicates. Duplicates that appear only when concurrent edits merge are repaired the same way on every replica: the earliest holder in document order keeps the id, and the others get ids derived from it. Every replica reaches the same result without coordination.

Enable the extension on every client that writes. A client without it writes blocks without ids, which every collaborator then names by place (positional ids). Positional ids come from the document a collaborator sees, so when such a client writes between two collaborators' repairs (while one of them has unsynced edits, or when they open the document at different moments), they derive different ids for the same block. The shared document keeps one of them, and on the other collaborator an id it already wrote changes once. The collaborators converge, the ids stay unique, and nothing changes after that, but an id read in between can stop naming its block.

With @lexical/y, the binding names the blocks a remote change brings without a unique id as it reads them, and writes nothing: a block that stores no id (written by a client without the extension), or that stores an id an earlier block also stores (a list whose items all store its id, split by concurrent edits), shows an id derived from its own Yjs identity (y, a client, _, a clock, in base 36), the same on every client and every reader. The next local edit of that block stores the id it shows. Blocks inside named slots that repeat an id (a decorator copied with its slots) are the exception: BlockIdExtension renames them after the read, as with other bindings, and every client writes those names. Clients without BlockIdExtension show only the ids that are stored. YCollabExtension also sets BlockIdExtension's repairTransforms to false: a naming update that runs the editor's transforms would change what a remote change brought.