diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 95dc770c70b31f..1e51cd770493c7 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -225,18 +225,21 @@ export const __unstableGetClientIdsTree = createSelector( * * @return {Array} ids of descendants. */ -export const getClientIdsOfDescendants = ( state, clientIds ) => { - const collectedIds = []; - for ( const givenId of clientIds ) { - for ( const descendantId of getBlockOrder( state, givenId ) ) { - collectedIds.push( - descendantId, - ...getClientIdsOfDescendants( state, [ descendantId ] ) - ); +export const getClientIdsOfDescendants = createSelector( + ( state, clientIds ) => { + const collectedIds = []; + for ( const givenId of clientIds ) { + for ( const descendantId of getBlockOrder( state, givenId ) ) { + collectedIds.push( + descendantId, + ...getClientIdsOfDescendants( state, [ descendantId ] ) + ); + } } - } - return collectedIds; -}; + return collectedIds; + }, + ( state ) => [ state.blocks.order ] +); /** * Returns an array containing the clientIds of the top-level blocks and