From 36fdce9ae7de66ab50e327c084aa6421c82dec2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Su=C3=A1rez?= Date: Thu, 19 Oct 2023 18:42:48 +0100 Subject: [PATCH] AI Assistant: fix issue when getting AI assistant block instance (#33690) * fix issue when selecting the AI block * changelog * pass clientId to getBlock() calls --- .../changelog/update-ai-assistant-block-get-block | 4 ++++ .../jetpack/extensions/blocks/ai-assistant/edit.js | 9 +++------ 2 files changed, 7 insertions(+), 6 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/update-ai-assistant-block-get-block diff --git a/projects/plugins/jetpack/changelog/update-ai-assistant-block-get-block b/projects/plugins/jetpack/changelog/update-ai-assistant-block-get-block new file mode 100644 index 0000000000000..c7aa805b0a68d --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-ai-assistant-block-get-block @@ -0,0 +1,4 @@ +Significance: patch +Type: bugfix + +AI Assistant: fix issue when getting AI assistant block instance diff --git a/projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js b/projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js index 942892bdcb65d..6fa8730716448 100644 --- a/projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js +++ b/projects/plugins/jetpack/extensions/blocks/ai-assistant/edit.js @@ -58,10 +58,7 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId } const { tracks } = useAnalytics(); const postId = useSelect( select => select( 'core/editor' ).getCurrentPostId() ); - const getBlock = useSelect( - select => () => select( 'core/block-editor' ).getBlock( clientId ), - [ clientId ] - ); + const { getBlock } = useSelect( 'core/block-editor' ); const aiControlRef = useRef( null ); const blockRef = useRef( null ); @@ -174,7 +171,7 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId } } // Bail out if the block already has children blocks - const block = getBlock(); + const block = getBlock( clientId ); if ( block?.innerBlocks?.length ) { return; } @@ -339,7 +336,7 @@ export default function AIAssistantEdit( { attributes, setAttributes, clientId } * - Blocks are already created * - blocks are children of the current block */ - newGeneratedBlocks = getBlock(); + newGeneratedBlocks = getBlock( clientId ); newGeneratedBlocks = newGeneratedBlocks?.innerBlocks || []; }