Skip to content

Commit

Permalink
Block Editor: Simplify check in 'withBlockControls' styles hook (#53227)
Browse files Browse the repository at this point in the history
* Block Editor: Simplify check in 'withBlockControls' styles hook
* Set the key prop on 'BlockEdit' to avoid accidental remounting
  • Loading branch information
Mamaduka authored Aug 2, 2023
1 parent d71f08d commit dc6bd91
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { addFilter } from '@wordpress/hooks';
import {
getBlockSupport,
hasBlockSupport,
getBlockType,
__EXPERIMENTAL_ELEMENTS as ELEMENTS,
} from '@wordpress/blocks';
import { createHigherOrderComponent, useInstanceId } from '@wordpress/compose';
Expand Down Expand Up @@ -45,8 +44,8 @@ const styleSupportKeys = [
SPACING_SUPPORT_KEY,
];

const hasStyleSupport = ( blockType ) =>
styleSupportKeys.some( ( key ) => hasBlockSupport( blockType, key ) );
const hasStyleSupport = ( nameOrType ) =>
styleSupportKeys.some( ( key ) => hasBlockSupport( nameOrType, key ) );

/**
* Returns the inline styles to add depending on the style object
Expand Down Expand Up @@ -348,9 +347,8 @@ export function addEditProps( settings ) {
*/
export const withBlockControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const blockType = getBlockType( props.name );
if ( ! hasStyleSupport( blockType ) ) {
return <BlockEdit { ...props } />;
if ( ! hasStyleSupport( props.name ) ) {
return <BlockEdit key="edit" { ...props } />;
}

const shouldDisplayControls = useDisplayBlockControls();
Expand All @@ -366,7 +364,7 @@ export const withBlockControls = createHigherOrderComponent(
<DimensionsPanel { ...props } />
</>
) }
<BlockEdit { ...props } />
<BlockEdit key="edit" { ...props } />
</>
);
},
Expand Down

1 comment on commit dc6bd91

@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 in dc6bd91.
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/5734701936
📝 Reported issues:

Please sign in to comment.