-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Bug: serialized direction in headless editor is always null #4998
Description
Lexical version: 0.12.2
Steps To Reproduce
- Instantiate an headless editor
- Add a
ParagraphNodeand a non-emptyTextNode - Log the serizialized editor state
Link to code example: https://codesandbox.io/s/lexical-headless-direction-2c6cg4
The current behavior
In both the serialized ParagraphNode and RootNode the direction is null, instead of ltr.
By taking a quick look at the codebase, it seems that the direction is set by the DOM reconciler. It is inferred from a regex on the text content. The headless editor is never reconciled, therefore the direction is always null, I think it could either:
- be similarly inferred from the text content
- never be serialized, since it is inferred at runtime anyways
The expected behavior
The direction should be inferred to be ltr.
Our use case is to dynamically create serialized nodes (think on the server). The problem we are facing is that the serialized nodes differ before/after reconciliation, because of the direction property. To solve this we are manually calling setDirection on the nodes, but that is causing other issues depending on where the serialized node is used.