Skip to content

[lexical-text] Bug Fix: preserve style and detail when a text entity reverts to plain text - #8919

Open
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/text-entity-preserve-style
Open

[lexical-text] Bug Fix: preserve style and detail when a text entity reverts to plain text#8919
LeSingh1 wants to merge 1 commit into
facebook:mainfrom
LeSingh1:fix/text-entity-preserve-style

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

registerLexicalTextEntity replaces an entity node with a plain TextNode ($replaceWithSimpleText) whenever the text stops matching. It copies format but not style or detail, so inline styling applied to an entity node is silently dropped the moment the entity breaks — a coloured hashtag loses its colour when you delete the #, keeping bold but turning black.

@lexical/link already does this correctly when it builds the text node for an auto-link:

textNode.setFormat(linkTextNode.getFormat());
textNode.setDetail(linkTextNode.getDetail());
textNode.setStyle(linkTextNode.getStyle());

This copies style and detail as well, so the two paths agree.

Test plan

Before

New unit test at packages/lexical-text/src/__tests__/unit/registerLexicalTextEntity.test.ts fails:

AssertionError: expected '' to be 'color: red' // Object.is equality
- color: red

Tests  1 failed (1)

After

Test Files  2 passed (2)     Tests  2 passed (2)

format, style and detail all survive the revert, verified alongside packages/lexical-hashtag. Full unit suite green (228 files, 4939 passed).

@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 5, 2026 5:52am
lexical-playground Ready Ready Preview Aug 5, 2026 5:52am

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
Comment on lines 51 to 55
const textNode = $createTextNode(node.getTextContent());
textNode.setFormat(node.getFormat());
textNode.setStyle(node.getStyle());
textNode.setDetail(node.getDetail());
node.replace(textNode);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can save some code size by chaining all of this

Suggested change
const textNode = $createTextNode(node.getTextContent());
textNode.setFormat(node.getFormat());
textNode.setStyle(node.getStyle());
textNode.setDetail(node.getDetail());
node.replace(textNode);
const textNode = $createTextNode(node.getTextContent())
.setFormat(node.getFormat())
.setStyle(node.getStyle())
.setDetail(node.getDetail());
node.replace(textNode);

@LeSingh1
LeSingh1 force-pushed the fix/text-entity-preserve-style branch from 779a75c to e5a2d50 Compare August 5, 2026 05:51
@LeSingh1

LeSingh1 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Applied in e5a2d50 — chained, same behaviour. packages/lexical-text passes, and reverting the file still fails the new test. tsc clean.

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