Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-5· anthropicHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Bug: List: delete the leading ListItemNode will also delete the…

  1. User

    ISSUE DESCRIPTION

    Bug: List: delete the leading ListItemNode will also delete the previous DecoratorBlockNode Lexical version: 0.12.2

    Steps To Reproduce

    1. Open the playground at https://playground.lexical.dev/
    2. Append a DecoratorBlockNode to the document, for example, a TweetNode
    3. Insert a list after the DecoratorBlockNode
    4. Delete the first list item, and the previous DecoratorBlockNode will also be removed

    https://github.com/facebook/lexical/assets/6022672/2ccbc2a0-af27-4d3f-a244-804f43249fec

    The current behavior

    Both the ListNode and the previous DecoratorBlockNode are deleted.

    The expected behavior

    Only ListNode would be deleted. (I will be more than happy to see the ListNode be replaced by a ParagraphNode if 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 using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to 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-$

  2. Claude Assistant

    Great, ListNode/ListItemNode/TestDecoratorNode are all in DEFAULT_NODES. Let's write a repro test script.

  3. Claude Assistant

    Reproduced the bug: the decorator was deleted, leaving only ['list']. Now let's trace the logic to understand why and fix it.

  4. Claude Assistant

    Let's add debug logging to trace state through the loop for our repro scenario.

  5. Claude Assistant

    Good, inserted correctly despite the bash warning.

  6. Claude Assistant

    Now let's apply the targeted fix using replace.

  7. Claude Assistant

    It was written as Python. Let me rewrite it as a proper Node script.

  8. Claude Assistant

    Now let's run the repro test.

  9. Claude Assistant

    Good, the earlier debug prints were removed by restoring from bak2 (which was saved right after applying my clean patch, before adding debug logs). Let's verify current state of that section.

  10. Claude Assistant

    All lexical unit tests pass. Now let's run lexical-list, lexical-rich-text, lexical-table, lexical-horizontal-rule, lexical-plain-text test suites.

  11. Claude Assistant

    All pass. Now let's run the full lexical unit test suite across the whole repo to be safe.

  12. Claude Assistant

    All 157 test files (2962 tests) pass. Now let's also verify additional edge cases with a more thorough manual test script, then clean up.

  13. Claude Assistant

    Let's view the final diff to make sure everything is clean.

  14. Claude Assistant

    I need to fix this to preserve the original "isolated decorator → stop/no-op" behavior.

  15. Claude Assistant

    Now let's re-verify the whole block once more, and re-run the full test suites.

  16. Claude Assistant

    Good, this now matches the original semantics exactly except for the new !isInnermostBlock branch. Let's rerun the full test suite.

  17. Claude Assistant

    All 157 test files pass. Let's also re-run our repro scripts once more to confirm the fix still works, then check lint/typecheck.

  18. Claude Assistant

    Now let's check TypeScript compiles correctly and run lint.

  19. Claude Assistant

    TypeScript compiles cleanly with no errors. Let's run eslint on the modified file.

  20. Claude Assistant

    Clean. Let's do a final review of the diff and ensure the repo is clean of temp files.

  21. Claude Assistant

    Clean. Let's also run the specific e2e-related unit tests one more time just to be thorough, plus a broader grep to ensure no stray console.log debug statements remain.

  22. Claude Assistant

    No debug logs left (grep exit 1 = no matches). Let's do one final full test run to be safe.

  23. Claude Assistant

    All tests pass. The fix is complete and verified. Let me now go through the checklist.

  24. Claude Assistant

    Checklist review

    • [x] If an error was reported in the issue description, I have successfully reproduced it. I wrote a temporary reproduction test (using lexical's TestDecoratorNode as a stand-in for TweetNode/DecoratorBlockNode, plus ListNode/ListItemNode) that placed a block decorator immediately before a list, then called deleteCharacter(true) at the start of the first list item's text. This reproduced the bug exactly as described: the decorator was deleted along with the merge, leaving only ['list'] in the document.

    • [x] If an error was reported in the issue description, I have confirmed that my fix resolves the error. After the fix, the same test produces ['test_decorator', 'paragraph', 'list'] — the decorator is preserved, the first (now-empty-of-content) list item is converted into a standalone paragraph before the list (matching the behavior the issue reporter explicitly said they'd be happy with), and the list continues with its remaining item(s).

      Root cause: in RangeSelection.deleteCharacter's "no text in direction" exploration loop, the merge-next-block state's block was unconditionally overwritten every time a non-inline ElementNode boundary was exited while walking up the tree (e.g. exiting ListItemNode, then exiting ListNode). When a decorator was then found immediately before that outer wrapper, it was treated as though it were directly adjacent to the anchor's own block, triggering deletion of the decorator. Additionally, $modifySelectionAroundDecoratorsAndBlocks had a similar unguarded escalation that produced a non-collapsed selection spanning the decorator, which then got removed via the generic removeText() fallback.

      The fix tracks whether the merge candidate block is still the innermost (first) block found, i.e. we haven't yet crossed more than one structural container boundary. If a decorator is encountered after crossing multiple boundaries (as with a ListItemNode nested in a ListNode), we no longer merge with/delete it — instead we give the anchor's own block chain (e.g. ListItemNode.collapseAtStart) the opportunity to handle the operation, which is exactly the list-specific "convert to paragraph" logic that already existed but was being bypassed.

    • [x] I have thought about edge cases and made sure my fix handles them as well. Verified via extra temporary tests (since removed):

      • Flat adjacency (paragraph directly preceded by a decorator, no list): unchanged legacy behavior — decorator is still deleted on backspace (only one boundary is crossed, so isInnermostBlock stays true).
      • Empty first list item preceded by a decorator: now converts to an empty paragraph via collapseAtStart instead of the previous "select decorator" behavior — a reasonable and consistent outcome, not previously covered by any test.
      • Normal same-list item merging (backspacing at the start of the second item to merge into the first item's text): unaffected, still works via the existing merge-block path, which never even reaches the decorator-handling code.
      • Nested list (sublist) preceded by a decorator: decorator preserved as well.
      • Isolated decorators (isIsolated()): preserved the exact original semantics (no-op backspace) by adding back the missing return for that branch, which I had initially dropped when refactoring the if/else chain — caught this during review and fixed it before finalizing.
    • [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 entire unit test suite (vitest --project unit --no-watch run): 157 test files / 2962 tests passed (1 pre-existing skip), including LexicalSelection.test.ts, all of lexical-list, lexical-rich-text, lexical-table, lexical-selection, etc. Also confirmed tsc --noEmit and eslint on the modified file report no errors. All temporary reproduction test files were deleted before submission, leaving only the source fix in packages/lexical/src/LexicalSelection.ts.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.