[Breaking Change][lexical-extension][lexical-rich-text][lexical-plain-text] Feature: Remove empty inline elements#8497
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
etrepum
left a comment
There was a problem hiding this comment.
I wonder if it would be better to just register a transform on ElementNode instead of adding more code directly to the update cycle
|
This should probably also be marked as a breaking change. Even though they were basically broken before you could still create empty inline ElementNodes before that had some behavior. Perhaps the right solution is to add transforms in RichTextExtension and PlainTextExtension that can be configured on or off (default on). This way anyone with legacy code that predates extensions would work as-is and people using a newer stack can still opt-out of the transform while they migrate their code. |
This cannot be done, at the very least because ElementNode does not implement the |
|
There are plenty of ways to do it like just manipulating editor._nodes. We don't have to only rely on public APIs for internal functionality, e.g. if (!config.disableEmptyInlineElementNormalization) {
for (const {klass, transforms} of editor._nodes.values()) {
if (klass.prototype instanceof ElementNode && klass.prototype.isInline !== ElementNode.prototype.isInline) {
transforms.add(normalizeEmptyInlineElementTransform);
}
}
} |
466b01e to
d41ae1b
Compare
d41ae1b to
04a7176
Compare
|
I set the default option to |
Description
Breaking Change
A new extension,
NormalizeInlineElementsExtension, has been added. It removes any empty inline ElementNodes. This extension is enabled by default forRichTextExtensionandPlainTextExtension. For custom inline elements that are explicitly declared as emptyable and returntruefromcanBeEmpty, a warning will be logged to the consoleIf you need to preserve empty inline elements, you can temporarily disable the extension during the migration:
If you think there are useful cases where empty inline elements should be preserved, please open an issue with a detailed description and an example
Closes #8205
Test plan
Before
If a user creates an emptyable inline element node, this creates “invisible” positions in the document that cannot be navigated
After
Inline nodes with
isInline(): trueandisEmpty(): trueare removed at runtime, and a warning is logged to the console