Skip to content

[lexical][lexical-html] Bug Fix: restore the capitalization formats from text-transform on import - #8991

Closed
LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:fix/8915-text-transform
Closed

LeSingh1 wants to merge 1 commit into
meta:mainfrom
LeSingh1:fix/8915-text-transform

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #8915

TextNode.exportDOM writes the three capitalization formats out as CSS:

// Add text-transform styles for capitalization formats
if (this.hasFormat('lowercase')) {
  element.style.textTransform = 'lowercase';
} else if (this.hasFormat('uppercase')) {
  element.style.textTransform = 'uppercase';
} else if (this.hasFormat('capitalize')) {
  element.style.textTransform = 'capitalize';
}

Nothing ever read text-transform back. applyTextFormatFromStyle (the legacy
<span> / <b> / <em> … converters) reads fontWeight, textDecoration,
fontStyle and verticalAlign; readElementFormatStyle /
styleFormatOverride in the @lexical/html rule pipeline read the same four.
So IS_LOWERCASE / IS_UPPERCASE / IS_CAPITALIZE were written on export and
silently dropped on import — copy/paste between editors, and any
$generateHtmlFromNodes -> $generateNodesFromDOM round trip, lost the format
while every other text format survived.

Read text-transform in both importers, mirroring how vertical-align is
already handled — including the mutual exclusion, since only one of the three
can apply. On the @lexical/html side, text-transform: none clears all three
(the same "explicit non-decorating value clears the bit" rule that
font-weight: normal and vertical-align: baseline already follow), and
text-transform joins FORMAT_BIT_STYLE_PROPS so the property is owned by the
format bit mask and does not also get materialized onto the node's inline
style.

Test plan

New packages/lexical-html/src/__tests__/unit/Issue8915Repro.test.ts: for each
of the three formats, one export assertion (passes before and after — it is the
writer the readers are held to) plus a round trip through each of the two
import pipelines. A fourth case pins that an unrelated text-transform: none
alongside font-weight: bold neither sets a capitalization format nor disturbs
the bold one.

The test lives in its own IssueNNNN Repro file because
LexicalTextNode.test.tsx is already being edited by #8924.

Before

$ npx vitest run packages/lexical-html/src/__tests__/unit/Issue8915Repro.test.ts

     ✓ exportDOM writes text-transform for lowercase 11ms
     ✓ exportDOM writes text-transform for uppercase 1ms
     ✓ exportDOM writes text-transform for capitalize 1ms
     × $generateNodesFromDOM restores lowercase 19ms
     × $generateNodesFromDOM restores uppercase 7ms
     × $generateNodesFromDOM restores capitalize 6ms
     × $generateNodesFromDOMViaExtension restores lowercase 7ms
     × $generateNodesFromDOMViaExtension restores uppercase 6ms
     × $generateNodesFromDOMViaExtension restores capitalize 6ms
     ✓ an unrelated text-transform: none does not clear other formats 6ms

AssertionError: expected false to be true // Object.is equality

      Tests  6 failed | 4 passed (10)

After

$ npx vitest run packages/lexical-html packages/lexical/src packages/lexical-clipboard

 Test Files  79 passed (79)
      Tests  1469 passed | 1 skipped (1470)

$ npx vitest run packages/lexical-table packages/lexical-list packages/lexical-markdown packages/lexical-playground

 Test Files  40 passed (40)
      Tests  982 passed (982)

The real-world paste fixtures that carry text-transform: none (Slack, GitHub
and Facebook payloads in HTMLCopyAndPaste.test.ts, CodeBlock.test.ts,
LexicalTableNode.test.tsx) put it on block tags — <p>, <ul>, <pre>,
<table> — not on the inline-format tags these converters handle, and they all
still pass.

…rom text-transform on import

## Description

Closes meta#8915

`TextNode.exportDOM` writes the three capitalization formats out as CSS:

```ts
// Add text-transform styles for capitalization formats
if (this.hasFormat('lowercase')) {
  element.style.textTransform = 'lowercase';
} else if (this.hasFormat('uppercase')) {
  element.style.textTransform = 'uppercase';
} else if (this.hasFormat('capitalize')) {
  element.style.textTransform = 'capitalize';
}
```

Nothing ever read `text-transform` back. `applyTextFormatFromStyle` (the legacy
`<span>` / `<b>` / `<em>` … converters) reads `fontWeight`, `textDecoration`,
`fontStyle` and `verticalAlign`; `readElementFormatStyle` /
`styleFormatOverride` in the `@lexical/html` rule pipeline read the same four.
So `IS_LOWERCASE` / `IS_UPPERCASE` / `IS_CAPITALIZE` were written on export and
silently dropped on import — copy/paste between editors, and any
`$generateHtmlFromNodes` -> `$generateNodesFromDOM` round trip, lost the format
while every other text format survived.

Read `text-transform` in both importers, mirroring how `vertical-align` is
already handled — including the mutual exclusion, since only one of the three
can apply. On the `@lexical/html` side, `text-transform: none` clears all three
(the same "explicit non-decorating value clears the bit" rule that
`font-weight: normal` and `vertical-align: baseline` already follow), and
`text-transform` joins `FORMAT_BIT_STYLE_PROPS` so the property is owned by the
format bit mask and does not also get materialized onto the node's inline
style.

## Test plan

New `packages/lexical-html/src/__tests__/unit/Issue8915Repro.test.ts`: for each
of the three formats, one export assertion (passes before and after — it is the
writer the readers are held to) plus a round trip through each of the two
import pipelines. A fourth case pins that an unrelated `text-transform: none`
alongside `font-weight: bold` neither sets a capitalization format nor disturbs
the bold one.

The test lives in its own `IssueNNNN Repro` file because
`LexicalTextNode.test.tsx` is already being edited by meta#8924.

### Before

```
$ npx vitest run packages/lexical-html/src/__tests__/unit/Issue8915Repro.test.ts

     ✓ exportDOM writes text-transform for lowercase 11ms
     ✓ exportDOM writes text-transform for uppercase 1ms
     ✓ exportDOM writes text-transform for capitalize 1ms
     × $generateNodesFromDOM restores lowercase 19ms
     × $generateNodesFromDOM restores uppercase 7ms
     × $generateNodesFromDOM restores capitalize 6ms
     × $generateNodesFromDOMViaExtension restores lowercase 7ms
     × $generateNodesFromDOMViaExtension restores uppercase 6ms
     × $generateNodesFromDOMViaExtension restores capitalize 6ms
     ✓ an unrelated text-transform: none does not clear other formats 6ms

AssertionError: expected false to be true // Object.is equality

      Tests  6 failed | 4 passed (10)
```

### After

```
$ npx vitest run packages/lexical-html packages/lexical/src packages/lexical-clipboard

 Test Files  79 passed (79)
      Tests  1469 passed | 1 skipped (1470)

$ npx vitest run packages/lexical-table packages/lexical-list packages/lexical-markdown packages/lexical-playground

 Test Files  40 passed (40)
      Tests  982 passed (982)
```

The real-world paste fixtures that carry `text-transform: none` (Slack, GitHub
and Facebook payloads in `HTMLCopyAndPaste.test.ts`, `CodeBlock.test.ts`,
`LexicalTableNode.test.tsx`) put it on block tags — `<p>`, `<ul>`, `<pre>`,
`<table>` — not on the inline-format tags these converters handle, and they all
still pass.
@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 #9052 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.

text-transform (uppercase/lowercase/capitalize) is lost on an HTML round trip

1 participant