Skip to content

Commit

Permalink
Avoid rerenders of the entire BlockInspector when block attributes ch…
Browse files Browse the repository at this point in the history
…ange (#21990)

* Avoid rerenders of the entire BlockInspector when block attributes change

* Return null instead of not returning anything
  • Loading branch information
adamziel authored Apr 30, 2020
1 parent b4f0a07 commit 97caac7
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions packages/block-editor/src/components/block-inspector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const BlockInspector = ( {
selectedBlockName,
showNoBlockSelectedMessage = true,
} ) => {
const slot = useSlot( InspectorAdvancedControls.slotName );

if ( count > 1 ) {
return <MultiSelectionInspector />;
}
Expand All @@ -59,8 +57,6 @@ const BlockInspector = ( {
return null;
}

const hasFills = Boolean( slot.fills && slot.fills.length );

return (
<div className="block-editor-block-inspector">
<BlockCard blockType={ blockType } />
Expand All @@ -80,21 +76,34 @@ const BlockInspector = ( {
) }
<InspectorControls.Slot bubblesVirtually />
<div>
{ hasFills && (
<PanelBody
className="block-editor-block-inspector__advanced"
title={ __( 'Advanced' ) }
initialOpen={ false }
>
<InspectorAdvancedControls.Slot bubblesVirtually />
</PanelBody>
) }
<AdvancedControls
slotName={ InspectorAdvancedControls.slotName }
/>
</div>
<SkipToSelectedBlock key="back" />
</div>
);
};

const AdvancedControls = ( { slotName } ) => {
const slot = useSlot( slotName );
const hasFills = Boolean( slot.fills && slot.fills.length );

if ( ! hasFills ) {
return null;
}

return (
<PanelBody
className="block-editor-block-inspector__advanced"
title={ __( 'Advanced' ) }
initialOpen={ false }
>
<InspectorAdvancedControls.Slot bubblesVirtually />
</PanelBody>
);
};

export default withSelect( ( select ) => {
const {
getSelectedBlockClientId,
Expand Down

0 comments on commit 97caac7

Please sign in to comment.