Skip to content

Commit

Permalink
Block Editor: Optimize useAvailableAlignments performance (#46655)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Dec 20, 2022
1 parent 86a1c19 commit cd7a7c7
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useLayout } from '../block-list/layout';
import { store as blockEditorStore } from '../../store';
import { getLayoutType } from '../../layouts';

const EMPTY_ARRAY = [];
const DEFAULT_CONTROLS = [ 'none', 'left', 'center', 'right', 'wide', 'full' ];
const WIDE_CONTROLS = [ 'wide', 'full' ];

Expand Down Expand Up @@ -40,14 +41,14 @@ export default function useAvailableAlignments( controls = DEFAULT_CONTROLS ) {
// While we treat `none` as an alignment, we shouldn't return it if no
// other alignments exist.
if ( alignments.length === 1 && alignments[ 0 ].name === 'none' ) {
return [];
return EMPTY_ARRAY;
}
return alignments;
}

// Starting here, it's the fallback for themes not supporting the layout config.
if ( layoutType.name !== 'default' && layoutType.name !== 'constrained' ) {
return [];
return EMPTY_ARRAY;
}
const { alignments: availableAlignments = DEFAULT_CONTROLS } = layout;
const enabledControls = controls
Expand All @@ -66,7 +67,7 @@ export default function useAvailableAlignments( controls = DEFAULT_CONTROLS ) {
enabledControls.length === 1 &&
enabledControls[ 0 ].name === 'none'
) {
return [];
return EMPTY_ARRAY;
}

return enabledControls;
Expand Down

1 comment on commit cd7a7c7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3739752391
📝 Reported issues:

Please sign in to comment.