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.)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 first inspect the repository structure and locate list deletion/keyboard handling and relevant tests. Then I’ll reproduce the node transformation in the existing test framework, patch the narrow behavior, and run the affected suites.
- Assistant
rgis unavailable, so I’ll usegrep/findto identify the implementation and test files. - Assistant
The likely path is
ListItemNode.collapseAtStart, invoked when Backspace is pressed at the beginning of the first item. I’ll inspect that method and its surrounding unit tests, plus the core deletion implementation that calls it. - Assistant
I need the complete
collapseAtStartbranch and nearby tests to understand why a decorator sibling is selected/removed and what behavior is already expected for paragraphs and multiple items. - Assistant
The current implementation already converts a sole top-level list item to a paragraph, matching the preferred expected behavior. The bug may instead occur before this callback: core character deletion treats an adjacent decorator as an atomic node and removes it. I’ll inspect
$collapseAtStartand backward-delete logic, then find test utilities for dispatching Backspace. - Assistant
The critical ordering is confirmed: selection is first extended across the decorator; only if it stays collapsed does
ListItemNode.collapseAtStartrun. Thus a block decorator gets selected and removed before list conversion. I’ll inspect the full method andDecoratorNodeselection behavior to design a generic fix without coupling core to React’sDecoratorBlockNode. - Assistant
A generic and extensible fix is to honor
collapseAtStartbefore traversing/removing an adjacent decorator whenever Backspace is at offset 0. Nodes that return false (ordinary paragraphs) retain existing decorator deletion semantics;ListItemNodereturns true and converts/unindents before the decorator can be touched. I’ll verify repository history/context and use the test decorator configured as block-level to reproduce this directly against the editor model. - Assistant
This checkout has extensive history, so I’ll search commits for a prior fix or regression related to list/decorator deletion. That can reveal intended scope and avoid duplicating or conflicting with newer caret refactors.
- Assistant
No commit title directly matches. I’ll inspect the historical deletion changes and use
git log -Sto see whether an early collapse check existed before the caret refactor; this is useful regression analysis. - Assistant
The modern caret refactor introduced the pre-modify decorator removal but preserved the same underlying ordering from older code. I’ll search older list commits around the reported version/date for a fix that may have later regressed, using commit diffs involving
collapseAtStart. - Assistant
I’ll create a temporary (non-submitted) regression test inside the existing list test directory. It will build
block decorator -> one-item list, place a collapsed selection at the item start, calldeleteCharacter(true), and assert the decorator remains while the list becomes a paragraph. This directly reproduces the model-level bug without browser automation. - Assistant
The first test attempt was blocked by Corepack’s interactive download prompt, not by the code. Dependencies are already installed, so I’ll invoke the local Vitest binary directly. I’ll also confirm the temporary file was created.
- Assistant
The temporary test reproduces the issue exactly: only one root child remains because the decorator is removed. To minimize behavioral change, I won’t globally move collapse handling ahead of all cross-block merges. Instead, when traversal encounters a non-isolated decorator, I’ll first give the anchor’s element ancestry its documented
collapseAtStartopportunity. Ordinary blocks still return false and preserve existing decorator behavior; lists consume Backspace and preserve the decorator. Isolated decorators will retain their existing no-op semantics. - Assistant
Python is unavailable, so the source was not changed and the test correctly continued failing. I’ll apply the same focused edit with the repository’s
editcommand after locating exact lines, then rerun the unit project only. - Assistant
I’ll insert the collapse branch between isolated-decorator handling and the existing empty-block/decorator behavior.
- Assistant
The regression test now passes: the decorator remains and the sole-item list becomes a paragraph. The same callback also handles multi-item lists by extracting only the leading item and handles element-point selections on empty items, but I’ll validate those edge cases in the temporary test before deleting it. Then I’ll run the full affected unit files.
- Assistant
All three temporary regression variants pass (sole item, leading item of a multi-item list, and an empty item with element selection), and the 92 existing tests in the two directly affected files pass. I’ve removed the temporary test as required. Next I’ll inspect the final diff, ensure no accidental files remain, and run the repository’s formatter/type/lint checks available for the changed file.
- Assistant
The diff is a single focused branch and passes whitespace validation. I’ll run Prettier and ESLint specifically on the changed source, followed by the project TypeScript check if its script can be invoked non-interactively with local tooling.
- Assistant
Formatting, ESLint, and the repository TypeScript compilation all pass. As a final verification, I’ll run the complete
lexical-listunit directory (not justListItemNode) because list normalization and transforms could interact with the converted paragraph/list split.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.