Skip to content

Commit

Permalink
Shuffle: Don't call '__experimentalGetAllowedPatterns' for every block (
Browse files Browse the repository at this point in the history
WordPress#64736)


Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>
Co-authored-by: wpsoul <wpsoul@git.wordpress.org>
  • Loading branch information
4 people authored and bph committed Aug 31, 2024
1 parent 6b3b0d0 commit bdaad2f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/block-editor/src/components/block-toolbar/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ export default function Shuffle( { clientId, as = Container } ) {
const _categories = attributes?.metadata?.categories || EMPTY_ARRAY;
const _patternName = attributes?.metadata?.patternName;
const rootBlock = getBlockRootClientId( clientId );
const _patterns = __experimentalGetAllowedPatterns( rootBlock );

// Calling `__experimentalGetAllowedPatterns` is expensive.
// Checking if the block can be shuffled prevents unnecessary selector calls.
// See: https://github.com/WordPress/gutenberg/pull/64736.
const _patterns =
_categories.length > 0
? __experimentalGetAllowedPatterns( rootBlock )
: EMPTY_ARRAY;
return {
categories: _categories,
patterns: _patterns,
Expand All @@ -45,12 +52,7 @@ export default function Shuffle( { clientId, as = Container } ) {
);
const { replaceBlocks } = useDispatch( blockEditorStore );
const sameCategoryPatternsWithSingleWrapper = useMemo( () => {
if (
! categories ||
categories.length === 0 ||
! patterns ||
patterns.length === 0
) {
if ( categories.length === 0 || ! patterns || patterns.length === 0 ) {
return EMPTY_ARRAY;
}
return patterns.filter( ( pattern ) => {
Expand Down

0 comments on commit bdaad2f

Please sign in to comment.