Skip to content

Fix: handle Delete merging with following paragraph after nested list…#77261

Open
yyppsk wants to merge 6 commits intoWordPress:trunkfrom
yyppsk:fix/77245-list-merge-with-following-paragraph
Open

Fix: handle Delete merging with following paragraph after nested list…#77261
yyppsk wants to merge 6 commits intoWordPress:trunkfrom
yyppsk:fix/77245-list-merge-with-following-paragraph

Conversation

@yyppsk
Copy link
Copy Markdown

@yyppsk yyppsk commented Apr 13, 2026

What?

Closes #77245

Fixes forward Delete at the end of a nested list item so it correctly merges the following block (e.g. a paragraph) into the list.

Why?

When pressing Delete at the end of a nested list item, nothing happens if the next block is outside the list hierarchy (e.g. a paragraph after the list). This is because getNextId only searches within the list's own tree and returns undefined for nested items that are the last at every level, causing the code to fall through to onMerge( forward ), which itself has no effect since the list-item is not top-level.

Top-level list items already merge correctly with following blocks; only nested items are broken.

How?

Added a new helper getNextOuterBlockClientId in useMerge that, when getNextId returns nothing, walks up through ancestor list-items and checks whether any ancestor list has a next sibling block. If one is found, mergeBlocks is called between the ancestor list and that following block, which uses the existing __experimentalOnMerge merge path on core/list to absorb the block as new list items.

The fix is intentionally not guarded to only core/paragraph , the mergeBlocks codepath already handles non-convertible block types gracefully (it simply selects the first block without modifying anything), and top-level items already merge with any block type, so nested items should behave consistently.

Testing Instructions

  1. Create a new post.
  2. Add a List block with one outer item and one nested (indented) item.
  3. Add a Paragraph block with some text after the list.
  4. Place the cursor at the end of the nested item.
  5. Press Delete.
  6. Expected: The paragraph merges into the list as a new nested list item.
  7. Before this fix: Nothing happened.

Testing Instructions for Keyboard

Same as above.

Screenshots or screencast

Before After
Pressing Delete at the end of a nested list item does nothing The following paragraph is merged into the nested list as a new item
Screen.Recording.2026-04-13.at.2.59.15.PM.mov
Screen.Recording.2026-04-13.at.2.55.36.PM.mov

Use of AI Tools

Claude was used to review the patch, evaluate correctness. All code was reviewed manually.

@github-actions github-actions Bot added the [Package] Block library /packages/block-library label Apr 13, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: yyppsk <pranjalpratapsingh@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: mcsf <mcsf@git.wordpress.org>
Co-authored-by: dpmehta <mehtadev@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions github-actions Bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Apr 13, 2026
@github-actions
Copy link
Copy Markdown

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @yyppsk! In case you missed it, we'd love to have you join us in our Slack community.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@mikachan mikachan added the [Type] Bug An existing feature does not function as intended label Apr 13, 2026
Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

These changes look good, and they're testing well for me. I see you added some tests, but then reverted them. I think testing these changes would be a good idea, so I'd suggest adding some tests back before we merge this.

Comment thread packages/block-library/src/list-item/hooks/use-merge.js
@yyppsk
Copy link
Copy Markdown
Author

yyppsk commented Apr 14, 2026

Thanks for working on this!

These changes look good, and they're testing well for me. I see you added some tests, but then reverted them. I think testing these changes would be a good idea, so I'd suggest adding some tests back before we merge this.

I’ve also included the reverted and improved tests in the new commit.t @mikachan .

Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the recent changes! I've spotted one other potential change in the test file.

Comment thread test/e2e/specs/editor/blocks/list.spec.js
Comment thread test/e2e/specs/editor/blocks/list.spec.js Outdated
@Mamaduka Mamaduka requested a review from mcsf April 20, 2026 11:35
@mcsf
Copy link
Copy Markdown
Contributor

mcsf commented Apr 24, 2026

Thanks for the work here, @yyppsk!

There is one more edge case that this fix reveals, though. I wonder if we should fix it in this same PR or separately:

  1. Have two separate consecutive List blocks (see the List View in the recording below)
  2. Add a nested item in the first list
  3. Try to Delete into the next list
  4. Observed: No merge happens, but the nested List gets selected (confusing and prone to accidental deletion)
delete-into-sibling-list.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Writing flow: Deleting at the edge of a nested list item does not merge with following paragraph

4 participants