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
Now let's write a reproduce script using jest test format, run via existing test runner but as a scratch test file outside repo test dirs (won't be added to repo), then delete after.
Assistant
Uses vitest. Let's create a temp test file and run vitest for it.
Assistant
Restored. Let's use the
edittool instead for precise insertion.Assistant
Let's use the
replacecommand to insert debug logging safely (no shell interpolation issues).Assistant
Now also log the "anchor.origin" info before the loop, and run the test.
Assistant
Now let's view the exact current section to craft a precise replace.
Assistant
Now let's test with our repro test.
Assistant
Right, my SEARCH block itself ended with
} else if (which duplicated with what follows, causing stray marker text. Let me fix line 1878 directly withedit.Assistant
Now remove the duplicate stray line 1878.
Assistant
Now let's verify the whole block compiles fine and run repro test.
Assistant
Good, this looks correct now. Let's run the repro test.
Assistant
Legacy behavior preserved for a plain paragraph directly adjacent to a decorator (decorator removed as before). Now let's run the full existing test suites to check nothing else broke.
Assistant
Now let's run the full lexical, lexical-list, lexical-rich-text unit test suites broadly.
Assistant
All 1268 tests pass. Now let's also check lexical-table and lexical-playground e2e-related regression test files exist for decorator+table scenarios that might rely on similar code paths, plus run broader repo test suite for lexical-react and any other affected packages.
Assistant
All 2962 unit tests pass across the entire monorepo. Now let's double check git diff and clean up.
Assistant
Good, clean diff with only the intended change. Let's view the final diff to review it fully.
Assistant
No TypeScript errors related to our change. Let's also run the eslint check on the modified file to catch lint issues.
Assistant
No lint errors. Let's also double check for edge case: nested lists (indented list item as first item of nested list, previous outer sibling being a decorator won't normally happen, but let's also verify normal list-merging test (#7246 regression) still passes precisely with our change.
Assistant
That matches the original #7246 regression test's expected output exactly. Let's clean up the temp test file.
Assistant
Now let's also test nested list (indented) scenario to be thorough — first item of a nested (indented) list, backspace should unindent per collapseAtStart, not eat outer content.
Assistant
Now let's do a final full test run to make sure everything is clean, plus check lint/typecheck once more.
Assistant
All 2962 tests pass, 0 failures. Let's view the final diff once more for a clean review.
Assistant
Good,
.is()exists and handles null gracefully. Let's simplify the IIFE into a plain boolean expression for cleanliness.Assistant
Now let's run the tests again to confirm everything still passes after this cleanup.
Assistant
All clean. Let's do the final full-suite check once more and confirm git diff.
Assistant
All 2962 tests pass with a clean, minimal diff limited to
packages/lexical/src/LexicalSelection.ts.Checklist review
-
If an error was reported in the issue description, I have successfully reproduced it. Yes. I wrote a temporary unit test (removed before submission) building a document with a block
DecoratorNodefollowed by aListNodecontaining oneListItemNodewith text. Callingselection.deleteCharacter(true)at the start of the list item reproduced the exact bug: the previousDecoratorBlockNodewas deleted (in one variant the entire List also vanished without conversion to a paragraph). -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. Yes. After the fix, the same repro now yields
['test_decorator', 'paragraph']— the decorator is preserved and the list is converted into a paragraph (matching the reporter's preferred expected behavior), for both the case where the first list item has text and where it's empty. -
I have thought about edge cases and made sure my fix handles them as well. I verified:
- A plain paragraph directly adjacent to a decorator (no list wrapper) still deletes the decorator — legacy/existing behavior for genuinely adjacent blocks is preserved.
- The existing regression test scenario for issue #7246 (merging a paragraph into the last item of a preceding list) still behaves identically.
- Nested/indented lists: confirmed that a separate, pre-existing bug in
ListItemNode.collapseAtStart(losing content when unindenting a nested item, unrelated to decorators) already existed before my change and is out of scope for this issue — my change does not regress any previously-passing behavior in that area (it was already broken/untested). - The isolated decorator branch (
isIsolated()) is unaffected, and the "select decorator via NodeSelection when anchor is an empty element" branch is preserved for genuine same-level adjacency.
-
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) across the entire monorepo: 157 test files, 2962 tests passed, 1 skipped, 0 failed. Also verifiedtsc --noEmitandeslintreport no issues for the modified file.
Let's clean up any leftover temp files and submit.
-
Assistant
This is the final, clean diff. Let's submit.
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 →