ISSUE DESCRIPTION Bug: List: delete the leading ListItemNode will also delete the…
- User
ISSUE DESCRIPTION
Bug: List: delete the leading ListItemNode will also delete the previous DecoratorBlockNode Lexical version: 0.12.2
Steps To Reproduce
- Open the playground at https://playground.lexical.dev/
- Append a
DecoratorBlockNodeto the document, for example, aTweetNode - Insert a list after the
DecoratorBlockNode - Delete the first list item, and the previous
DecoratorBlockNodewill also be removed
https://github.com/facebook/lexical/assets/6022672/2ccbc2a0-af27-4d3f-a244-804f43249fec
The current behavior
Both the
ListNodeand the previousDecoratorBlockNodeare deleted.The expected behavior
Only
ListNodewould be deleted. (I will be more than happy to see theListNodebe replaced by aParagraphNodeif possible! That's the default behavior in other editors.)Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /lexical, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure and understanding the bug related to ListItemNode deletion affecting DecoratorBlockNode.
- Assistant
Let me search for relevant code around list item deletion and DecoratorBlockNode handling.
- Assistant
rg is not available, let me use grep instead.
- Assistant
Let me examine list item deletion logic and search for related history.
- Assistant
Let me search git history and code related to this specific bug.
- Assistant
Let me read the ListItemNode collapseAtStart and related deletion logic.
- Assistant
Let me examine deleteCharacter and how it merges with the previous node.
- Assistant
Let me continue reading the deleteCharacter logic around the decorator handling.
- Assistant
Looking at the decorator handling: I see the issue now. The caret traversal logic is hitting the decorator before the list node when deleting backward from an empty list item, which triggers the decorator removal path instead of the list node.
Let me break down the caret iteration:
- Assistant
Let me check DecoratorBlockNode and existing deletion tests involving decorators.
- Assistant
Let me look at test utilities and search for related deletion tests with block decorators.
- Assistant
I'll write a quick reproduction script using the test infrastructure.
- Assistant
Let me look at TestDecoratorNode more carefully and how isInline works. Also look at related reproducible tests like Issue files.
- Assistant
Let me find the utils path.
- Assistant
It's a directory.
- Assistant
Let me open that file.
- Assistant
I'll create a temporary reproduction test to confirm the bug.
- Assistant
I'll create a temporary test file to reproduce the bug.
- Assistant
Let me run the test.
- Assistant
The bug is confirmed. Let me check the console output for more detail.
- Assistant
Let me understand caret iteration and when the decorator gets removed.
- Assistant
Let me inspect caret behavior during this deletion more carefully.
- Assistant
Let me enhance the debugging to dump caret states during the deletion.
- Assistant
Let me check git history for this decorator deletion logic and related issues.
- Assistant
Let me understand how delete works when previous is a normal paragraph and check
$getAdjacentNode. - Assistant
Let me check
$getAdjacentNodeand how empty paragraph vs nested structures should behave. - Assistant
Let me read $getAdjacentNode
- Assistant
Let me check expected behavior for decorator followed by a paragraph with text.
- Assistant
Let me search for the original GitHub issue and any related PRs.
- Assistant
Let me look at the deleteCharacter through ListNode fix - it might be related.
- Assistant
Let me re-read the full current deleteCharacter loop carefully.
- Assistant
Let me dump carets for the two-paragraph merge case and empty-prev cases.
- Assistant
Let me check $getAdjacentChildCaret behavior.
- Assistant
Let me read $getAdjacentChildCaret specifically.
- Assistant
Let me dump caret sequence for non-empty paragraph after decorator.
- Assistant
Let me dump the inline decorator case as well.
- Assistant
Let me fix the syntax error.
- Assistant
For inline decorator: 0. sibling decorator (inline) - state is initial, not merge-next-block!I understand you're working on fixing the bug where deleting the first ListItemNode also removes the preceding DecoratorBlockNode. Your analysis of the caret handling logic is spot on, and the proposed fix for the decorator case makes sense.
- Assistant
Let me check getChildCaret for empty elements.
- Assistant
Let me dump list after empty paragraph.
- Assistant
I keep making typos. Let me be more careful.
- Assistant
Let me check current behavior for list after empty paragraph.
- Assistant
I had typos again. Let me write the file carefully.
- Assistant
python3 not found, use python or node.
- Assistant
Let me check if there's a Selection.modify polyfill and how list collapse tests work.
- Assistant
Empty? Let me try differently.
- Assistant
Checking imports in LexicalSelection.ts for $getAdjacentNode.
- Assistant
I'll implement the fix using
$getAdjacentNodeto only handle truly adjacent decorators. - Assistant
Next I'll update the decorator handling logic.
- Assistant
I need to navigate to that line first.
- Assistant
Now I can replace.
- Assistant
Let me check how $collapseAtStart is defined and whether we can call it early.
- Assistant
Calling collapseAtStart directly for non-adjacent decorators will avoid depending on DOM Selection.modify.
- Assistant
Need to goto again.
- Assistant
Now replace.
- Assistant
Now I'll write a comprehensive test to verify the fix.
- Assistant
All 6 tests passed. Let me run related existing tests to ensure nothing broke.
- Assistant
All related unit tests passed. Let me check for more selection/decorator tests and playground e2e coverage.
- Assistant
Let me check regression tests involving HR/decorators and lists - those are similar edge cases.
- Assistant
Cleaning up the temporary test file and running a broader test suite.
- Assistant
All tests passed. Let me review the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →