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.
Assistant
Now let's remove the debug line and look for the git history/tests explaining the decorator merge-next-block logic to understand intended semantics before fixing.
Assistant
Now let's apply the fix:
Assistant
Now let's check that
$collapseAtStartis imported/available in this file (it's defined locally in the same file per earlier grep), and run our repro tests.Assistant
Good, it's a local function in the same file. Now let's run our repro tests.
Assistant
Empty list item after decorator correctly removes the (empty) list and selects the decorator, unaffected by our change. Now let's clean up the temporary test files and run the full existing test suites for LexicalSelection, lists, and related packages to make sure nothing broke.
Assistant
All 1064 tests pass. Let's also run the full lexical unit test project and lexical-table, lexical-code (which might use decorator-adjacent deletion) as sanity checks.
Assistant
All pass. Now let's run a broader full unit test suite for the whole repo to be safe.
Assistant
All 157 test files / 2962 tests pass across the whole repo's unit project. Let's view the final diff for review.
Assistant
This is a clean, minimal, well-targeted fix. Let's verify no leftover temp files remain and double check git status.
Assistant
Clean. Let's also verify TypeScript type-checking passes for this file (no compile errors introduced).
Assistant
Type checking passes cleanly with no errors. Let's also run lint on the modified file if a linter is configured.
Assistant
Lint passes too. Let's do a final review of the change in context.
Assistant
Now let's run the nested test again plus the existing ListItemNode test suite to verify nothing breaks.
Assistant
Excellent! Now "Nested" text is preserved, list properly unindented (outer wrapper removed), and the decorator remains intact. Let's run the full list-related test suites and the full unit project again.
Assistant
All list tests pass. Now let's re-run the complete unit test project to confirm nothing else broke due to the ListItemNode change.
Assistant
All 160 test files (2965 tests) pass. Now let's run tsc and eslint again for the whole change.
Assistant
Clean type-check now. Let's run eslint on the two changed files.
Assistant
Both files pass lint. Let's do one final full test run to be safe, and check git diff.
Assistant
All 157 test files (2962 tests) pass with the temp files removed. Let's view the final diff.
Assistant
This is a clean, well-scoped diff addressing both the reported bug and the latent data-loss issue it would have otherwise unlocked. Let's clean up and do a final sanity check with the exact reproduction scenario from the issue plus the checklist review.
Assistant
No leftover temp test files, only the two intended source files modified.
Assistant
The fix confirmed and cleaned up. Let's confirm final state.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.