Skip to content

Commit

Permalink
AI Assistant: fix issue when getting AI assistant block instance (#33690
Browse files Browse the repository at this point in the history
)

* fix issue when selecting the AI block

* changelog

* pass clientId to getBlock() calls
  • Loading branch information
retrofox authored Oct 19, 2023
1 parent bc96042 commit 36fdce9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

AI Assistant: fix issue when getting AI assistant block instance
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 || [];
}

Expand Down

0 comments on commit 36fdce9

Please sign in to comment.