Repository navigation
Fix InnerBlocks inserter to respect allowedBlocks constraint - #76999
kushagra-goyal-14 wants to merge 1 commit into
Conversation
|
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? |
|
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. |
|
Thanks for your efforts :) |
What?
Closes #76859
Fixed the InnerBlocks inserter to properly respect the
allowedBlocksconstraint. The inserter now only shows blocks that are explicitly allowed by the parent block'sallowedBlocksconfiguration instead of displaying the entire global block catalog.Why?
When blocks use InnerBlocks with an
allowedBlocksconstraint (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 theallowedBlocksconstraint on parent blocks.As noted in the PR #74453 review by @youknowriad:
The bug occurs because
getClosestAllowedInsertionPoint()finds where a block can be inserted (traversing up the tree), but doesn't validate the parent block'sallowedBlocksattribute. This results in showing all blocks instead of respecting parent constraints.How?
Updated the
getInserterItemsselector in/packages/block-editor/src/store/selectors.jsto properly pass therootClientIdparameter tocanIncludeBlockTypeInInserter().This ensures the filtering logic:
allowedBlocks- Respects the parent block'sallowedBlocksconstraint viablockListSettingsrootClientIdExample: Test Block Implementation
The issue is demonstrated with this simple test block using
allowedBlocks:Testing Instructions
+button inside the block to open the nested inserterScreenshots or screencast
Before (Bug) Inserter shows all ~100+ blocks

Inserter shows only 3 blocks (Paragraph, Heading, List)
