Skip to content

Bug: serialized direction in headless editor is always null #4998

@giacomoran

Description

@giacomoran

Lexical version: 0.12.2

Steps To Reproduce

  1. Instantiate an headless editor
  2. Add a ParagraphNode and a non-empty TextNode
  3. Log the serizialized editor state

Link to code example: https://codesandbox.io/s/lexical-headless-direction-2c6cg4

Screenshot 2023-09-14 at 11 45 25 Screenshot 2023-09-14 at 11 45 46

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    text directionRelated to bidirectional text input (rtl, ltr)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions