Skip to content

Bug: There is an issue with indentation handling when importing DOM in LexicalParagraphNode #7729

@antilmid

Description

@antilmid

Lexical version: 0.33.1

Steps To Reproduce

  1. Override the CSS variable --lexical-indent-base-value to 2em.
  2. Create a paragraph node and set its indent value to 2.
  3. Export the node to DOM using exportDOM. The resulting DOM has padding-inline-start: calc(2 * 2em) = 4em.
  4. Import the DOM back into the editor using importDOM. The indent value on the imported LexicalParagraphNode becomes 0 (expected: 2)

Link to code example:

no

The current behavior

importDOM does not correctly infer the indent value from the padding-inline-start style or from the computed --lexical-indent-base-value. The imported node always falls back to indent = 0.

The expected behavior

When importing a DOM node with padding-inline-start: 4em and --lexical-indent-base-value: 2em, Lexical should correctly calculate and set indent = 2 on the resulting LexicalParagraphNode

Root Cause

In the LexicalParagraphNode.ts file, the importDOM method uses $convertParagraphElement to handle some import transformations. Among them, the setNodeIndentFromDOM function is responsible for processing the indentation level.

Inside the setNodeIndentFromDOM function, it determines the paragraph's indent level by dividing the element's paddingInlineStart by 40. However, this value 40 is hardcoded and does not change based on the --lexical-indent-base-value CSS variable.

position:facebook/lexical/packages/lexical/src/LexicalUtils.ts 1981:1

Image

Impact of fix

  1. Affects all users relying on accurate round-trip import/export of indentation styles

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions