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
Let's write a quick reproduction script using the jest test environment for lexical core, simulating the caret traversal logic directly through the editor.
Assistant
Uses vitest. Let's create a temp test file for reproduction.
Assistant
Good, TestDecoratorNode already included, and ListNode/ListItemNode already default too. Let's write the temp test file properly using this pattern.
Assistant
Now let's view exact current lines to make a precise edit.
Assistant
No python3 available. Let me rewrite as node script instead.
Assistant
Now let's remove the debug console.log I added earlier for testing (already restored from backup so it's clean). Let's verify no leftover console.log lines.
Assistant
Good, clean. Now let's run our repro tests.
Assistant
Also add a log after the loop and around modify/collapseAtStart section.
Assistant
Now let's run the broader test suites: lexical-list, lexical core selection tests, lexical-rich-text (heading), and playground unit tests.
Assistant
All pass. Now let's run the full lexical package unit test suite plus caret tests to be thorough.
Assistant
All 986 tests pass (the DOMException stderr is pre-existing noise, unrelated). Let's also run lexical-table, lexical-code, and other packages that might use decorators/collapseAtStart to be safe.
Assistant
All pass. Let's also run the entire unit test suite across the whole repo to be safe (not just selected packages).
Assistant
All 157 test files / 2962 tests pass (1 skipped, pre-existing). Now let's double-check the final diff and clean up any temp files.
Assistant
Clean diff, no leftover debug code or temp test files. Let's do a final sanity check by writing a temporary reproduction test once more (matching the exact issue scenario with a forward-delete direction too, and nested list edge cases), then remove it.
Assistant
Good, debug logging removed. Let's confirm this content-loss behavior is pre-existing in
ListItemNode.collapseAtStartitself, independent of our change, by directly invoking it.Assistant
Now let's run the full unit test suite one more time as a final sanity check before submission.
Assistant
All 157 test files pass (2962 tests, 1 pre-existing skip). Let's view the final diff once more for the record.
Assistant
This is the complete and final fix. Let's go through the checklist.
Assistant
Checklist review
-
[x] If an error was reported in the issue description, I have successfully reproduced it. I wrote a temporary vitest reproduction (using the existing
TestDecoratorNodetest fixture as a stand-in forTweetNode/DecoratorBlockNode) that builtDecorator + List[li1("one"), li2("two")], placed the cursor at the very start ofli1's text, and calledselection.deleteCharacter(true)(the same code pathBackspacetriggers). Before the fix, this deleted theDecoratorNodeentirely, leaving only theListNode— exactly matching the reported bug. -
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error. After the fix, the same repro produces
[decorator, list["two"]](the decorator survives, only the first list item is consumed/merged forward as expected), and a single-item-list variant produces[decorator, paragraph]— matching the issue author's stated preference ("I will be more than happy to see the ListNode be replaced by a ParagraphNode"). -
[x] I have thought about edge cases and made sure my fix handles them as well. I checked: (1) plain non-empty paragraph directly after a decorator (existing "adjacent decorator is removed" behavior preserved), (2) plain empty paragraph directly after a decorator (existing "select decorator via NodeSelection" behavior preserved), (3) list directly after a plain paragraph, no decorator (existing cross-block text merge behavior preserved), (4) single-item list after a decorator (converts to paragraph, decorator preserved), (5) nested/indented list's first item preceded (at the outer level) by a decorator (decorator preserved; the nested-list-content-loss behavior I found there is a pre-existing, independent bug in
ListItemNode.collapseAtStart's indent branch, reproducible even without any decorator or my change involved, so it's out of scope for this issue and was left untouched). The fix only changes behavior when the backward/forward deletion traversal has to ascend through more than one structural block wrapper (e.g.ListItemNodeinsideListNode) before reaching aDecoratorNode— in that case it now defers to the node-specificcollapseAtStarthandling instead of blindly merging with/deleting the decorator. -
[x] I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Ran the full unit test suite (
vitest --project unit run): 157 test files / 2962 tests passed (1 pre-existing skip), including alllexical-list,lexicalcore (LexicalSelection,LexicalCaret),lexical-rich-text,lexical-table, and other package suites. All temporary reproduction test files were removed before submission, and no test files were modified.
-
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 →
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 →