diff --git a/packages/block-editor/src/store/selectors.js b/packages/block-editor/src/store/selectors.js index 5b70183acccf2..543da7dd1debb 100644 --- a/packages/block-editor/src/store/selectors.js +++ b/packages/block-editor/src/store/selectors.js @@ -55,6 +55,17 @@ const MILLISECONDS_PER_WEEK = 7 * 24 * 3600 * 1000; */ const EMPTY_ARRAY = []; +/** + * Shared reference to an empty Set for cases where it is important to avoid + * returning a new Set reference on every invocation, as in a connected or + * other pure component which performs `shouldComponentUpdate` check on props. + * This should be used as a last resort, since the normalized data should be + * maintained by the reducer result in state. + * + * @type {Set} + */ +const EMPTY_SET = new Set(); + /** * Returns a block's name given its client ID, or null if no block exists with * the client ID. @@ -2722,11 +2733,15 @@ export function isBlockVisible( state, clientId ) { */ export const __unstableGetVisibleBlocks = createSelector( ( state ) => { - return new Set( + const visibleBlocks = new Set( Object.keys( state.blockVisibility ).filter( ( key ) => state.blockVisibility[ key ] ) ); + if ( visibleBlocks.size === 0 ) { + return EMPTY_SET; + } + return visibleBlocks; }, ( state ) => [ state.blockVisibility ] );