Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this condition still necessary. I guess right now it's more if ( !! parent )

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious why we'd need both typeof blockType.parent === 'string' || blockType.parent instanceof String.. 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm curious why we'd need both typeof blockType.parent === 'string' || blockType.parent instanceof String..

Otherwise, we don't cover all potential issues. Note the issue was that we checked for .length in a type that wasn't an array (didn't have .some). That's the case for both literal & object strings.

Copy link
Member

Choose a reason for hiding this comment

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

It's interesting, but it's possible to pass some constructs like:

Screenshot 2024-10-22 at 09 43 55

I don't think it would ever happen, but the check will cover it.

return parent.some(
( name ) =>
( blockName !== name &&
isBlockVisibleInTheInserter(
Expand All @@ -1643,6 +1653,7 @@ const isBlockVisibleInTheInserter = (
name === 'core/post-content'
);
}

return true;
};

Expand Down
Loading