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.
- Assistant
I'll start by exploring the repository structure and understanding the bug related to ListItemNode deletion affecting DecoratorBlockNode.
- Assistant
Let me look at the relevant list package code and search for related deletion logic.
- Assistant
rg is not available, I'll use grep instead.
- Assistant
Let me examine ListItemNode and search for backspace/delete handling related to lists.
- Assistant
The collapseAtStart and related delete handlers are likely involved — let me inspect ListItemNode.
- Assistant
Let me read the collapseAtStart and remove methods in detail.
- Assistant
Let me check backspace/delete handling in the core and rich-text packages.
- Assistant
Let me look at the delete character handling and how it interacts with previous siblings, particularly decorator blocks.
- Assistant
I need more context around the delete/merge logic before decorator handling.
- Assistant
There's decorator-specific handling — let me continue reading that section.
- Assistant
Let me inspect DecoratorBlockNode properties like isIsolated and isInline.
- Assistant
I'll check DecoratorNode defaults and look for existing tests or related PRs about this bug.
- Assistant
There's a related fix for deleteCharacter through ListNode — let me inspect that and the defaults.
- Assistant
Let me look at existing e2e tests related to this and also try to reproduce the bug with a unit test.
- Assistant
Let me search for related tests and prior discussion of this bug.
- Assistant
Let me look at existing unit tests for deleteCharacter around decorator nodes, and also search more carefully if this bug was already fixed.
- Assistant
Hmm empty results? That's odd. Let me try differently.
- Assistant
Strange that deleteCharacter tools returned nothing—let me search more carefully.
- Assistant
There's a related test with non-inline decorators in SelectionHelpers — let me inspect that and reproduce the bug.
- Assistant
I'll write a temporary script to reproduce the bug based on existing test patterns.
- Assistant
Let me look at test utils and how list tests are structured. Also I should look at whether this bug is known/fixed in recent commits, and look at TweetNode.
- Assistant
Let me look at TestDecoratorNode's isInline and create a reproduction test.
- Assistant
I'll write a temporary unit test to reproduce the bug.
- Assistant
I'll craft a temporary script that tries to reproduce the issue.
- Assistant
Let me put the test in the right place and run it.
- Assistant
The test timed out—I'll check whether the file was created and try a different approach.
- Assistant
Let me try running the test with vitest directly with a longer timeout.
- Assistant
I've reproduced the bug—I'll expand the repro to cover more scenarios and understand the intended behavior.
- Assistant
Let me look at how caret iteration works over these structures.
- Assistant
There's related code at line 3614. Let me also check git history for the decorator removal logic and any related issues.
- Assistant
I'll instrument the caret iteration to see exactly what path is taken in the bug case.
- Assistant
Let me check collapseAtStart implementations for Paragraph and the $collapseAtStart helper.
- Assistant
Interesting. Looking at
$collapseAtStartfor list item starting with text - it rolls up from text to list item if no previous sibling (if (node.getPreviousSibling()) break). Text is first child, L...I see the core issue now: thecollapseAtStartlogic forListItemNodeis incorrectly treating the precedingDecoratorBlockNodeas a valid previous sibling, causing the entire list to collapse when deleting the first list item. Your analysis of the path fromTextNodetoListItemNode collapseAtStartis spot on - it correctly returns true for non-empty items, but the empty case needs careful handling to avoid removing the decorator. - Assistant
Bash issue with !. Let me fix the command.
- Assistant
Let me look at how HorizontalRule handles deletion and any e2e tests around HR + backspace.
- Assistant
There's a relevant HR test about empty paragraphs—let me inspect it and nearby backspace cases.
- Assistant
Let me also look at more of this test and search for tests⏟ about deleted content after HR with text.
- Assistant
Let me look at PR #7155 more carefully and check git blame more comprehensively.
- Assistant
Let me look at the LexicalSelection.test.ts changes from that PR and any tests for decorator deletion.
- Assistant
I'll refine the reproduction to decide between collapseAtStart and selecting the decorator .
- Assistant
I made a mess with the file. Let me properly write the test.
- Assistant
I'll also check forward deletion before a block decorator.
- Assistant
I'll purchase a clean approach with the create tool.
- Assistant
Now I'll use the edit command to write the content.
- Assistant
Good, now run the test.
- Assistant
I have a clear fix plan. I'll update the decorator handling in
deleteCharacterso block decorators aren't removed when adjacent content exists. - Assistant
Now I'll apply the fix.
- Assistant
I see an extra brace — let me verify and fix the structure.
- Assistant
There's an extra brace to remove.
- Assistant
Structure looks good. Let me rewrite the repro test to verify the fix across all scenarios.
- Assistant
The edit hit LexicalSelection.ts by mistake—I'll restore it immediately.
- Assistant
I restored LexicalSelection.ts (which undid the fix). I'll re-apply it carefully with the --file option.
- Assistant
Good, original is restored. Now apply fix with --file.
- Assistant
I'll remove the extra brace again.
- Assistant
Structure looks correct. I'll verify syntax and write a proper test file.
- Assistant
No python—I'll use node for the brace check.
- Assistant
finalbal 1 is expected inside the method. I'll write a clean test and run it.
- Assistant
Now write the test carefully.
- Assistant
The second half got corrupted—I'll rewrite the whole file cleanly with a node script.
- Assistant
Now run the tests.
- Assistant
All 8 tests passed. Next I'll run related unit tests to ensure nothing else broke.
- Assistant
All related tests pass. I'll run a few more selection-related suites, then remove the temporary test file.
- Assistant
Let me quickly verify heading behavior after a decorator thrive, as another edge case.
- Assistant
Quote.collapseAtStart converts to paragraph - good UX.
- Assistant
Heading collapse behavior looks consistent. I'll do a final review of the diff and clean up.
- Assistant
I'll quickly re-verify the original bug is fixed with a one-off script.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.