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
Great, ListNode/ListItemNode/TestDecoratorNode are all in DEFAULT_NODES. Let's write a repro test script.
Assistant
Reproduced the bug: the decorator was deleted, leaving only
['list']. Now let's trace the logic to understand why and fix it.Assistant
Let's add debug logging to trace state through the loop for our repro scenario.
Assistant
Good, inserted correctly despite the bash warning.
Assistant
Now let's apply the targeted fix using
replace.Assistant
It was written as Python. Let me rewrite it as a proper Node script.
Assistant
Now let's run the repro test.
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.
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.
Assistant
All pass. Now let's run the full lexical unit test suite across the whole repo to be safe.
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.
Assistant
Let's view the final diff to make sure everything is clean.
Assistant
I need to fix this to preserve the original "isolated decorator → stop/no-op" behavior.
Assistant
Now let's re-verify the whole block once more, and re-run the full test suites.
Assistant
Good, this now matches the original semantics exactly except for the new
!isInnermostBlockbranch. Let's rerun the full test suite.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.
Assistant
Now let's check TypeScript compiles correctly and run lint.
Assistant
TypeScript compiles cleanly with no errors. Let's run eslint on the modified file.
Assistant
Clean. Let's do a final review of the diff and ensure the repo is clean of temp files.
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.
Assistant
No debug logs left (grep exit 1 = no matches). Let's do one final full test run to be safe.
Assistant
All tests pass. The fix is complete and verified. Let me now 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 reproduction test (using
lexical'sTestDecoratorNodeas a stand-in forTweetNode/DecoratorBlockNode, plusListNode/ListItemNode) that placed a block decorator immediately before a list, then calleddeleteCharacter(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, themerge-next-blockstate'sblockwas unconditionally overwritten every time a non-inlineElementNodeboundary was exited while walking up the tree (e.g. exitingListItemNode, then exitingListNode). 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,$modifySelectionAroundDecoratorsAndBlockshad a similar unguarded escalation that produced a non-collapsed selection spanning the decorator, which then got removed via the genericremoveText()fallback.The fix tracks whether the merge candidate
blockis 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 aListItemNodenested in aListNode), 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
isInnermostBlockstays true). - Empty first list item preceded by a decorator: now converts to an empty paragraph via
collapseAtStartinstead 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-blockpath, 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 missingreturnfor that branch, which I had initially dropped when refactoring theif/elsechain — caught this during review and fixed it before finalizing.
- 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
-
[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), includingLexicalSelection.test.ts, all oflexical-list,lexical-rich-text,lexical-table,lexical-selection, etc. Also confirmedtsc --noEmitandeslinton the modified file report no errors. All temporary reproduction test files were deleted before submission, leaving only the source fix inpackages/lexical/src/LexicalSelection.ts.
-
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 →