Bug: syncYjsChangesToLexical unable to find active editor in headless mode
See original GitHub issueI am currently working on converting the representation of lexical in yjs to html. I received a very helpful gist when I initially enquired about this in discord. Whilst working on implementing this, I have come across an issue using the syncYjsChangesToLexical
method. The stack trace of the error is as follows:
Error: Unable to find an active editor. This method can only be used synchronously during the callback of editor.update().
[0] at getActiveEditor (C:<project
-path>\node_modules\lexical\Lexical.dev.js:5541:13)
[0] at $setNodeKey (C:<project
-path>\node_modules\lexical\Lexical.dev.js:550:18)
[0] at new LexicalNode (C:<project
-path>\node_modules\lexical\Lexical.dev.js:6334:5)
[0] at new ElementNode (C:<project
-path>\node_modules\lexical\Lexical.dev.js:7077:5)
[0] at new LinkNode (C:<project
-path>\node_modules\@lexical\link\LexicalLink.dev.js:33:5)
[0] at createLexicalNodeFromCollabNode (C:<project
-path>\node_modules\@lexical\yjs\LexicalYjs.dev.js:336:23)
[0] at CollabElementNode.syncChildrenFromYjs (C:<project
-path>\node_modules\@lexical\yjs\LexicalYjs.dev.js:847:34)
[0] at createLexicalNodeFromCollabNode (C:<project
-path>\node_modules\@lexical\yjs\LexicalYjs.dev.js:345:16)
[0] at CollabElementNode.syncChildrenFromYjs (C:\<project
-path>\node_modules\@lexical\yjs\LexicalYjs.dev.js:847:34)
[0] at syncEvent (C:<project
-path>\node_modules\@lexical\yjs\LexicalYjs.dev.js:1523:18)
This errror does not occur when the editor contains simple text. Once I start using more sophisticated nodes such as links and tables, the error is thrown.
Lexical version: 0.6.0
Steps To Reproduce
- Create a nodejs project
- implement a headless editor using jsdom
- Try to generate html from yjs doc
An example of code to reproduce this is shown below.
Link to code example:
A gist containing a modified version of the gist provided previously can be found here.
The current behavior
As mentionned above, when generating html which only contains text, this works as expected. When generating html which contains nodes such as tables and links, an error with the stack trace above is shown.
The expected behavior
I would expect that the behaviour is the same for both text nodes and other nodes.
Issue Analytics
- State:
- Created 10 months ago
- Reactions:1
- Comments:15 (15 by maintainers)
Top GitHub Comments
It’s still single threaded so yes it should be fine.
You really can’t use two separate lexicals. You must keep it to one as those variables may seem “global” but they’re actually lexicallly bound to the lexical source (one of the reasons it’s called Lexical). Can you avoid duplicating lexical in your env?