From 37626f97f44863cc29c090a2f22e14dcca830acd Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Thu, 13 Jul 2023 13:22:19 +0200 Subject: [PATCH] Avoid passing undefined `selectedBlockClientId` in `BlockActionsMenu` When determining if the block is groupable/ungroupable, we now avoid passing an undefined value which leads to a crash. --- .../components/block-toolbar/block-toolbar-menu.native.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/block-toolbar/block-toolbar-menu.native.js b/packages/block-editor/src/components/block-toolbar/block-toolbar-menu.native.js index bff035173b290..5b7e0c6fccc94 100644 --- a/packages/block-editor/src/components/block-toolbar/block-toolbar-menu.native.js +++ b/packages/block-editor/src/components/block-toolbar/block-toolbar-menu.native.js @@ -100,9 +100,11 @@ const BlockActionsMenu = ( { } = getMoversSetup( isStackedHorizontally, moversOptions ); // Check if selected block is Groupable and/or Ungroupable. - const convertToGroupButtonProps = useConvertToGroupButtonProps( [ - selectedBlockClientId, - ] ); + const convertToGroupButtonProps = useConvertToGroupButtonProps( + // `selectedBlockClientId` can be undefined in some cases where this + // component gets re-rendered right after the block is removed. + selectedBlockClientId ? [ selectedBlockClientId ] : [] + ); const { isGroupable, isUngroupable } = convertToGroupButtonProps; const showConvertToGroupButton = ( isGroupable || isUngroupable ) && canRemove;