From 14687c038f77d54a7959e957c25070d3fbff6462 Mon Sep 17 00:00:00 2001 From: Marin Atanasov Date: Mon, 19 Dec 2022 16:10:34 +0200 Subject: [PATCH] Block Editor: Optimize useAvailableAlignments performance --- .../block-alignment-control/use-available-alignments.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/block-editor/src/components/block-alignment-control/use-available-alignments.js b/packages/block-editor/src/components/block-alignment-control/use-available-alignments.js index ba6f885a09cd55..ab6213b4389282 100644 --- a/packages/block-editor/src/components/block-alignment-control/use-available-alignments.js +++ b/packages/block-editor/src/components/block-alignment-control/use-available-alignments.js @@ -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' ]; @@ -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 @@ -66,7 +67,7 @@ export default function useAvailableAlignments( controls = DEFAULT_CONTROLS ) { enabledControls.length === 1 && enabledControls[ 0 ].name === 'none' ) { - return []; + return EMPTY_ARRAY; } return enabledControls;