Skip to content

Commit

Permalink
Block inserter: prevent editor from crashing if blockType.parent is…
Browse files Browse the repository at this point in the history
… a string (#66234)

Co-authored-by: oandregal <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: gziolo <[email protected]>
  • Loading branch information
4 people authored Oct 21, 2024
1 parent 2fe909b commit 88de21b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1628,8 +1628,18 @@ const isBlockVisibleInTheInserter = (
checkedBlocks.add( blockName );

// If parent blocks are not visible, child blocks should be hidden too.
if ( !! blockType.parent?.length ) {
return blockType.parent.some(
//
// In some scenarios, blockType.parent may be a string.
// A better approach would be sanitize parent in all the places that can be modified:
// block registration, processBlockType, filters, etc.
// In the meantime, this is a hotfix to prevent the editor from crashing.
const parent =
typeof blockType.parent === 'string' ||
blockType.parent instanceof String
? [ blockType.parent ]
: blockType.parent;
if ( Array.isArray( parent ) ) {
return parent.some(
( name ) =>
( blockName !== name &&
isBlockVisibleInTheInserter(
Expand All @@ -1643,6 +1653,7 @@ const isBlockVisibleInTheInserter = (
name === 'core/post-content'
);
}

return true;
};

Expand Down

0 comments on commit 88de21b

Please sign in to comment.