[lexical-link] Bug Fix: Toggle links with nested children#8078
[lexical-link] Bug Fix: Toggle links with nested children#8078etrepum merged 1 commit intofacebook:mainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
This structure is a normalization failure, LinkNode is only supposed to wrap inline nodes as currently implemented. It's probably fine to do a little more extra work here so that it does work, but the real bug is that this structure was created in the first place (due to lack of normalization code to handle paste, probably).
Generally speaking there are three kinds of ElementNode and that determines what kind of children they are allowed to have:
- Roots (RootNode and shadow roots like TableNode, TableRowNode, TableCellNode) must be non-inline and must only have block ElementNode (or DecoratorNode) children
- Blocks (any other non-inline node, like ParagraphNode or HeadingNode; non-inline DecoratorNode are blocks too, like HorizontalRuleNode, but they can not have children), if it is an ElementNode it must only have inline children
- Inline (like LinkNode, ListNode, ListItemNode, or MarkNode), must only have inline children
If that general rule about ElementNodes isn't followed, you'll hit edge cases because there are tacit assumptions that this structure is followed all over the place.
|
I have actually worked on the normalization already - did you want me to include it in this PR or a separate change? |
|
That's not necessary, having normalization be separate from this makes more sense. I was just leaving some comments while I was waiting to make sure the extended test suite still passed |
Description
When a link has nested children, the TOGGLE_LINK_COMMAND does nothing (it should remove the link). This PR adds handling for such cases.
Here's an example of the problematic lexical state:
This can be reproduced by copying the title of a google search result and pasting it into the editor.
Changes
The link removal logic only checks the immediate parent of selected nodes, so it cant find the LinkNode if the parent is a HeadingNode.
Test plan
Captured the behaviour in a unit test, which now passes