Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/block-editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 ]
);
Expand Down