Skip to content

[lexical-table] Bug Fix: Import the dir attribute in table importDOM - #8914

Merged
etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/table-import-dir
Aug 5, 2026
Merged

etrepum merged 1 commit into
meta:mainfrom
LeSingh1:fix/table-import-dir

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

ElementNode.exportDOM writes the explicit dir attribute for every element node, but the @lexical/table DOM converters never read it back. An explicit direction on a TableNode, TableRowNode, or TableCellNode therefore survives exportJSON/importJSON but is silently dropped through $generateHtmlFromNodes → $generateNodesFromDOM, and a pasted <table dir="rtl"> is ignored.

#8412 fixed this for ParagraphNode, HeadingNode, QuoteNode, ListNode and ListItemNode, and added the shared $setDirectionFromDOM helper. Tables were missed. This applies the same helper in $convertTableElement, $convertTableRowElement and $convertTableCellNodeElement.

One intentional consequence a reviewer should look at, matching the snapshot updates #8412 made across its e2e specs: the existing Copy table from an external source like gdoc with formatting fixture carries dir="ltr" on its <table>, so that table is now explicitly ltr rather than bidi-auto, and its rows no longer auto-detect (a parent with an explicit __dir suppresses dir="auto" on descendants). The test expectation is updated accordingly, with an inline comment. If you'd rather tables keep auto-detecting for external pastes, that's the point to push back on.

I deliberately left table indent alone even though data-lexical-indent has the same asymmetry: all three table node types declare canIndent(): false, so indent isn't user-reachable there, and wiring it up would newly interpret padding-inline-start on arbitrary pasted <table>/<td> as indent on nodes that explicitly opt out.

Test plan

Before

New importDOM preserves the dir attribute block in LexicalTableNode.test.tsx, on main:

× dir=rtl
× dir=ltr
× round trips the dir attribute through exportDOM
× Copy table from an external source like gdoc with formatting (x2)

AssertionError: expected null to be 'rtl'
AssertionError: expected null to be 'ltr'

- <table class="test-table-class" dir="ltr">
+ <table class="test-table-class" dir="auto">
-   <tr style="height: 21px">
+   <tr dir="auto" style="height: 21px">

Tests  5 failed | 37 passed (42)

After

Test Files  10 passed (10)
     Tests  152 passed (152)

Full pnpm run test-unit: 4940 passed. The only failures are the two pre-existing 5000ms testTimeout flakes in MdastTextRuns.test.ts and FastPathCrossParent.test.ts — timeouts, not assertion failures, in files this PR doesn't touch. tsc --noEmit, eslint and prettier all clean.

ElementNode.exportDOM writes the explicit `dir` attribute for every
element node, but the @lexical/table converters never read it back, so
an explicit direction on a table, row, or cell is dropped on import.
meta#8412 fixed this for paragraph, heading, quote, list, and list item;
tables were missed.

Apply $setDirectionFromDOM in $convertTableElement,
$convertTableRowElement, and $convertTableCellNodeElement so the
attribute round trips through $generateHtmlFromNodes /
$generateNodesFromDOM and is honored when pasting HTML that specifies a
direction.
@vercel

vercel Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview Aug 4, 2026 5:39am
lexical-playground Ready Ready Preview Aug 4, 2026 5:39am

Request Review

@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 4, 2026
@etrepum
etrepum added this pull request to the merge queue Aug 5, 2026
Merged via the queue into meta:main with commit d099e85 Aug 5, 2026
44 checks passed
@etrepum etrepum mentioned this pull request Aug 31, 2026

This branch was successfully deployed

2 active deployments
Preview – lexical — b233a4c3 Deployed Aug 4, 2026 by vercel[bot]
Preview – lexical-playground — b233a4c3 Deployed Aug 4, 2026 by vercel[bot]
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.

2 participants