Skip to content

Fix InnerBlocks inserter to respect allowedBlocks constraint - #76999

Closed
kushagra-goyal-14 wants to merge 1 commit into
WordPress:trunkfrom
kushagra-goyal-14:fix/innerblocks-inserter-filtering
Closed

kushagra-goyal-14 wants to merge 1 commit into
WordPress:trunkfrom
kushagra-goyal-14:fix/innerblocks-inserter-filtering

Conversation

@kushagra-goyal-14

Copy link
Copy Markdown
Contributor

What?

Closes #76859

Fixed the InnerBlocks inserter to properly respect the allowedBlocks constraint. The inserter now only shows blocks that are explicitly allowed by the parent block's allowedBlocks configuration instead of displaying the entire global block catalog.

Why?

When blocks use InnerBlocks with an allowedBlocks constraint (e.g., <InnerBlocks allowedBlocks={['core/paragraph', 'core/heading']} />), users expect the inserter to show only those allowed blocks. Instead, it was showing all blocks globally, causing confusion and allowing insertion of invalid block types.

Root Cause

This is a regression from PR #74453 (merged Jan 14) which introduced getClosestAllowedInsertionPoint() filtering to ensure only insertable blocks appear in the inserter. While that PR successfully showed insertable blocks, it didn't properly account for the allowedBlocks constraint on parent blocks.

As noted in the PR #74453 review by @youknowriad:

"Any logic that doesn't depend on rootClientId is fine but when the logic of whether something can be inserted depends on rootClientId, it may create an issue."

The bug occurs because getClosestAllowedInsertionPoint() finds where a block can be inserted (traversing up the tree), but doesn't validate the parent block's allowedBlocks attribute. This results in showing all blocks instead of respecting parent constraints.

How?

Updated the getInserterItems selector in /packages/block-editor/src/store/selectors.js to properly pass the rootClientId parameter to canIncludeBlockTypeInInserter().

This ensures the filtering logic:

  1. Checks allowedBlocks - Respects the parent block's allowedBlocks constraint via blockListSettings
  2. Checks editor-level restrictions - Validates editor-wide block restrictions
  3. Validates parent relationships - Ensures blocks have valid parent declarations
  4. Uses correct context - Properly evaluates constraints for the specific rootClientId

Example: Test Block Implementation

The issue is demonstrated with this simple test block using allowedBlocks:

// edit.js - Test block implementation
import { useBlockProps, InnerBlocks } from '@wordpress/block-editor';

export default function Edit() {
    return (
        <div { ...useBlockProps() }>
            <p>Test Block - Only allows Paragraph, Heading, and List</p>
            <InnerBlocks
                allowedBlocks={ [ 'core/paragraph', 'core/heading', 'core/list' ] }
                template={ [ [ 'core/paragraph', { content: 'Add content here...' } ] ] }
            />
        </div>
    );
}

Testing Instructions

  1. Navigate to http://localhost:8888/wp-admin/
  2. Create a new post/page
  3. Search for and insert "Test Block"
  4. Click the + button inside the block to open the nested inserter
  5. Expected (after fix): Inserter shows only 3 blocks: Paragraph, Heading, and List
  6. Previous behavior (bug): Inserter showed all available blocks globally

Screenshots or screencast

Before (Bug) Inserter shows all ~100+ blocks
Screenshot 2026-04-02 at 2 17 13 PM

Inserter shows only 3 blocks (Paragraph, Heading, List)
Screenshot 2026-04-02 at 2 13 23 PM

@github-actions github-actions Bot added the [Package] Block editor /packages/block-editor label Apr 2, 2026
@youknowriad

Copy link
Copy Markdown
Contributor

Looking at the example you shared in the PR, I'm not sure that this is what we want. If I'm not wrong, in the editor top level you can insert any block, so in that case, the blocks should actually show up in the inserter. The logic of the inserter that we want is that if you click a block, it's going to be inserted in the closest parent position possible, in the case of the example above it's the "root" right?

@kushagra-goyal-14

Copy link
Copy Markdown
Contributor Author

Hi @youknowriad ,

Thank you for the clarification! I see what you mean now, as maintaining a consistent global list to avoid a "disappearing block" UX makes sense from a high-level usability perspective and as it's a design choice mentioned here.

Since the current behavior is intentional to allow insertion at the closest possible parent, I’ll go ahead and close this PR.

@youknowriad

Copy link
Copy Markdown
Contributor

Thanks for your efforts :)

@youknowriad youknowriad closed this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InnerBlocks inserter shows all blocks and causes editor confusion

2 participants