Skip to content

[lexical] Feature: Only serialize ElementNode textFormat and textStyle when necessary#7971

Merged
etrepum merged 3 commits intofacebook:mainfrom
etrepum:elementnode-textFormat-serialization
Nov 3, 2025
Merged

[lexical] Feature: Only serialize ElementNode textFormat and textStyle when necessary#7971
etrepum merged 3 commits intofacebook:mainfrom
etrepum:elementnode-textFormat-serialization

Conversation

@etrepum
Copy link
Copy Markdown
Collaborator

@etrepum etrepum commented Nov 3, 2025

Breaking Change

Previously the derived properties textFormat and textStyle would always be serialized to JSON if not set to the default values. These should only be useful when the ElementNode does not currently have any TextNode children, to preserve formatting choices, and will be recomputed when reconciled. Now they are only reconciled when they are determined to be useful (in an ElementNode with no direct TextNode children that is not a root or shadow root).

Description

Avoid serializing derived textFormat and textStyle whenever their values would be useless (in a root or shadow root that should not have TextNode children) or recomputed on first reconcile (when the ElementNode has a TextNode child).

Also fixes a bug where in some cases the ElementNode's format and style could be coming from two different TextNodes. It should really only come from the first TextNode.

Closes #7968

Future Considerations

We should eventually start changing the JSON in backwards incompatible ways, notably to remove default and useless values (e.g. the version attribute). They make the data less compact and provide no value other than to be compatible with very old versions of lexical.

Test plan

New unit tests and all existing tests should pass (nothing exercised these edge cases)

@vercel
Copy link
Copy Markdown

vercel bot commented Nov 3, 2025

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

Project Deployment Preview Comments Updated (UTC)
lexical Ready Ready Preview Comment Nov 3, 2025 8:11pm
lexical-playground Ready Ready Preview Comment Nov 3, 2025 8:11pm

@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 Nov 3, 2025
@etrepum etrepum added this pull request to the merge queue Nov 3, 2025
Merged via the queue into facebook:main with commit da56dcf Nov 3, 2025
42 checks passed
@buondevid
Copy link
Copy Markdown

Thank you for this @etrepum!

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. extended-tests Run extended e2e tests on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor State from Headless Lexical and React Lexical slightly differs

3 participants