Skip to content

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

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

LeSingh1 wants to merge 1 commit into
meta: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.

@LeSingh1

Copy link
Copy Markdown
Contributor Author

Consolidated into #9060 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

This branch was successfully deployed

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