Bug: First issues with named slots
Lexical version: 0.45.0+dev
Description
I decided not to wait for the 0.46 release and immediately leave feedback on the slot issues I discovered at the playground. I discovered many of these bugs after this issue https://github.com/facebook/lexical/issues/8707 But I don’t deny that they may not reproduce artificially, but by users after the first integrations of named slots
Below I'll describe several bugs I found, mostly related to shadow root slots. All tests were conducted on Google Chrome 149.0 on MacOS Tahoe 26.4
Selected DecoratoreNode is not deleted via Backspace
Steps To Reproduce
- Insert a HorizontalRuleNode into the slot shadow-root-container
- Click on HorizontalRuleNode to select the node
- Press Backspace
The current behavior
The selected decorator is not deleted. However, if you press Ctrl + C, then Backspace, it will be deleted.
https://github.com/user-attachments/assets/a131a21b-b19a-4326-9b3d-0ed4aa228d96
The expected behavior
The selected decorator is deleted
Copying a DecoratoreNode from slot shadow-root to an external document
Steps To Reproduce
- Insert a HorizontalRuleNode into the slot shadow-root-container
- Click on HorizontalRuleNode to select the node
- Press Ctrl + C to copy
- Click to outside document
- Press Ctrl + V to paste
The current behavior
- The node is not copied and therefore not pasted. The clipboard is empty
- Ctrl + X deletes the selected node, but the clipboard is still empty.
https://github.com/user-attachments/assets/9703118d-94a2-405e-a18d-cc6196e4db40
btw, the text is copied correctly
The expected behavior
DecoratorNode is copied to the clipboard and successfully pasted outside the slot
Copying a decorator from outside and pasting it into a slot shadow-root in block cursor
Steps To Reproduce
- Insert a HorizontalRuleNode outside the slot shadow-root-container
- Click on the external HorizontalRuleNode to select the node
- Press Ctrl + C to copy
- Click to HorizontalRuleNode in slot
- Press ArrowLeft to show block cursor (!)
- Press Ctrl + V to paste
The current behavior
The decorator isn't inserted into a block cursor (there's no error with a regular cursor). An exception is thrown: Uncaught RangeError: Maximum call stack size exceeded
https://github.com/user-attachments/assets/7f9eea09-e378-4c66-99b4-5ba3cefb2720
The expected behavior
The decorator is correctly inserted into the block cursor inside the slot-root-container
SELECT_ALL_COMMAND in slot-root-container with decorator and text
Steps To Reproduce
- Insert a HorizontalRuleNode in the slot shadow-root-container
- Write the text before (!) the HorizontalRuleNode via block cursor
- Press Ctrl + A when caret at the text
The current behavior
The content inside the slot is not selected. An exception is thrown: Uncaught Error: Children of root nodes must be elements or decorators
(!) No error occurs if text was entered after the HorizontalRuleNode
https://github.com/user-attachments/assets/cbe2f492-1d80-46c8-a58c-d7afade560c8
The expected behavior
Correct selection occurs within the slot root
An empty slot element is removed if an empty paragraph is removed after it
Steps To Reproduce
- Insert any node with slot
- Create an empty paragraph after the node
- Press Backspace in a paragraph
The current behavior
If the node with slots is empty, it is deleted along with the paragraph
https://github.com/user-attachments/assets/5c27122d-817d-4e88-9a08-e5fb3fd901a5
The expected behavior
Only the paragraph is deleted, the caret moves to the previous node with the slot
@mayrang fyi
Opened #8716 for four of these. Quick summary:
- Selected DecoratoreNode is not deleted via Backspace —
KEY_BACKSPACE_COMMANDwas passing through on a NodeSelection because the click target lives inside the decorator. Now skips the pass-through on NodeSelection. Same fix for forward-Delete. - Copying a DecoratoreNode from slot shadow-root to an external document —
$generateJSONFromSelectedNodesonly redirected through the slot frame for RangeSelection. Extended to NodeSelection. - Copying a decorator from outside and pasting it into a slot shadow-root in block cursor —
RangeSelection.insertNodesslot-host redirect re-entered itself when the slot's first child was a non-element. Seeds a paragraph before the redirect. - SELECT_ALL_COMMAND in slot-root-container with decorator and text — fixed at two layers: the typing path that produced this shape (defensive guard symmetric to #8686), and a hydrate-time normalize that wraps any raw text in slot values parsed in from outside (URL doc, imported JSON, etc.) so existing invalid states like the URL in this issue also stop throwing.
The last one (An empty slot element is removed if an empty paragraph is removed after it) reads to me as intentional — registerSlotHostBackspace was designed for the empty-host case, and the deleteCharacter guard at LexicalSelection.ts:2004-2008 (a slot-bearing host is removed only as a unit by an explicit host deletion, never silently via backspace) only covers the non-empty case — so I left it as-is in this PR. But I'm not certain about the policy here; what's your read? Should the empty-host case also stay protected?
The last one (An empty slot element is removed if an empty paragraph is removed after it) reads to me as intentional — registerSlotHostBackspace was designed for the empty-host case, and the deleteCharacter guard at LexicalSelection.ts:2004-2008 (a slot-bearing host is removed only as a unit by an explicit host deletion, never silently via backspace) only covers the non-empty case — so I left it as-is in this PR. But I'm not certain about the policy here; what's your read? Should the empty-host case also stay protected?
From a user's perspective, I think it would be more natural to see that pressing Backspace deletes only the current empty node where the cursor is positioned.
For example, if there were an empty heading before an empty paragraph, pressing Backspace on the paragraph should not delete the heading. Details such as the node type, whether it contains slots or not, and so on, are not that important to the end user of the editor
Added that fix too — PR #8716 updated. Host stays, paragraph only is removed.