Skip to content

[lexical-list] Bug Fix: keep the list's dir attribute in exported HTML - #9001

Closed
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:list-export-dir
Closed

[lexical-list] Bug Fix: keep the list's dir attribute in exported HTML#9001
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:list-export-dir

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

Both list importers read dir off the <ol>/<ul>: $convertListNode
calls $setDirectionFromDOM(node, domNode), and so does ListRule in the
DOMImportExtension pipeline. Nothing writes it back out.

ElementNode.exportDOM is what normally emits element.dir from
getDirection(), but ListNode.exportDOM builds its element with
createDOM and returns it directly without going through super.exportDOM,
so the direction is dropped. ListItemNode.exportDOM, right next to it, does
emit element.dir, so a copied RTL list currently exports as
<ul><li dir="rtl">…</li></ul> — the item keeps its direction and the list
that owns it silently loses it, and re-importing that HTML no longer produces
the node it came from.

This emits dir from ListNode.exportDOM when the node has an explicit
direction, matching ListItemNode and what the importers expect to read. A
node with no explicit direction is unaffected, so existing output is
unchanged.

Test plan

npx vitest run packages/lexical-list/src/__tests__/unit/LexicalListNode.test.ts

Before

 FAIL  |unit| packages/lexical-list/src/__tests__/unit/LexicalListNode.test.ts > LexicalListNode tests > ListNode.exportDOM() round-trips the dir attribute
AssertionError: expected '<ul><li value="1" dir="rtl"><span sty…' to contain '<ul dir="rtl">'

Expected: "<ul dir="rtl">"
Received: "<ul><li value="1" dir="rtl"><span style="white-space: pre-wrap;">שלום</span></li></ul>"

 Test Files  1 failed (1)
      Tests  1 failed | 18 passed (19)

After

 Test Files  1 passed (1)
      Tests  19 passed (19)

npx vitest run packages/lexical-list packages/lexical-html packages/lexical-clipboard packages/lexical-markdown is also green (25 files, 667 tests).

## Description

Both list importers read `dir` off the `<ol>`/`<ul>`: `$convertListNode`
calls `$setDirectionFromDOM(node, domNode)`, and so does `ListRule` in the
`DOMImportExtension` pipeline. Nothing writes it back out.

`ElementNode.exportDOM` is what normally emits `element.dir` from
`getDirection()`, but `ListNode.exportDOM` builds its element with
`createDOM` and returns it directly without going through `super.exportDOM`,
so the direction is dropped. `ListItemNode.exportDOM`, right next to it, does
emit `element.dir`, so a copied RTL list currently exports as
`<ul><li dir="rtl">…</li></ul>` — the item keeps its direction and the list
that owns it silently loses it, and re-importing that HTML no longer produces
the node it came from.

This emits `dir` from `ListNode.exportDOM` when the node has an explicit
direction, matching `ListItemNode` and what the importers expect to read. A
node with no explicit direction is unaffected, so existing output is
unchanged.

## Test plan

`npx vitest run packages/lexical-list/src/__tests__/unit/LexicalListNode.test.ts`

### Before

```
 FAIL  |unit| packages/lexical-list/src/__tests__/unit/LexicalListNode.test.ts > LexicalListNode tests > ListNode.exportDOM() round-trips the dir attribute
AssertionError: expected '<ul><li value="1" dir="rtl"><span sty…' to contain '<ul dir="rtl">'

Expected: "<ul dir="rtl">"
Received: "<ul><li value="1" dir="rtl"><span style="white-space: pre-wrap;">שלום</span></li></ul>"

 Test Files  1 failed (1)
      Tests  1 failed | 18 passed (19)
```

### After

```
 Test Files  1 passed (1)
      Tests  19 passed (19)
```

`npx vitest run packages/lexical-list packages/lexical-html packages/lexical-clipboard packages/lexical-markdown` is also green (25 files, 667 tests).
@vercel

vercel Bot commented Aug 9, 2026

Copy link
Copy Markdown

@LeSingh1 is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 9, 2026
@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9050 with the other PRs that share this defect, per @etrepum's note on #9027 and @mayrang's on #9035. Same fix and same tests, one review.

@LeSingh1 LeSingh1 closed this Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant