From 2001df409d0e2af6a1db6335bfee32307bdf7ae3 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Thu, 13 Jul 2023 16:40:19 +0200 Subject: [PATCH] Avoid passing undefined `selectedBlockClientId` in `BlockActionsMenu` (#52595) 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 bff035173b2909..5b7e0c6fccc944 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;