[lexical] Feature: Only serialize ElementNode textFormat and textStyle when necessary#7971
Merged
etrepum merged 3 commits intofacebook:mainfrom Nov 3, 2025
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
ivailop7
approved these changes
Nov 3, 2025
|
Thank you for this @etrepum! |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking Change
Previously the derived properties
textFormatandtextStylewould 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
textFormatandtextStylewhenever 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)