facebook / facebook/lexical

Bug: yjs collab doesn't load state from already-loaded YDoc

Open
#4,999 2 comments 6 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
23.9k
Forks
2.2k
Avg merge
1d 14h
Merged PRs (30d)
55

Description

Lexical version: 0.11.3

## Steps To Reproduce

1. set up lexical with the CollaborationPlugin
2. in the providerfactory, return a provider with a document that has already loaded

Link to code example: If the bug is unclear I'll make one

## The current behavior

The editor remains empty

## The expected behavior

The editor shows the state of the XmlText

## Details

The plugin normally gets documents that need loading and registers an event listener with observeDeep and applies the incoming transactions to the editor.

The observer is [here](https://github.com/facebook/lexical/blob/a0e7596748626a17f004ce94ad8968dbe4347e18/packages/lexical-react/src/shared/useYjsCollaboration.tsx#L104-L115).

When the YDoc is already in loaded, there are no events and therefore it doesn't apply the changes.

So the YJs initialization should also apply the current state of the document before it attaches the observer.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.