Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance: reduce block support hook calls further with isMatch #62684

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions packages/block-editor/src/hooks/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,7 @@ export function setBackgroundStyleDefaults( backgroundStyle ) {
return backgroundStylesWithDefaults;
}

function useBlockProps( { name, style } ) {
if (
! hasBackgroundSupport( name ) ||
! style?.background?.backgroundImage
) {
return;
}

function useBlockProps( { style } ) {
const backgroundStyles = setBackgroundStyleDefaults( style?.background );

if ( ! backgroundStyles ) {
Expand Down Expand Up @@ -184,5 +177,6 @@ export function BackgroundImagePanel( {
export default {
useBlockProps,
attributeKeys: [ 'style' ],
isMatch: ( { style } ) => !! style?.background?.backgroundImage,
hasSupport: hasBackgroundSupport,
};
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/block-bindings.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const BlockBindingsPanel = ( { name, metadata } ) => {
export default {
edit: BlockBindingsPanel,
attributeKeys: [ 'metadata' ],
isMatch: ( { metadata } ) => !! metadata?.bindings,
hasSupport() {
return true;
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/border.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ export default {
useBlockProps,
addSaveProps,
attributeKeys: [ 'borderColor', 'style' ],
isMatch: ( { style, borderColor } ) => !! ( style?.border || borderColor ),
hasSupport( name ) {
return hasBorderSupport( name, 'color' );
},
Expand Down
8 changes: 8 additions & 0 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ export default {
useBlockProps,
addSaveProps,
attributeKeys: [ 'backgroundColor', 'textColor', 'gradient', 'style' ],
isMatch: ( { style, backgroundColor, textColor, gradient } ) =>
!! (
backgroundColor ||
textColor ||
gradient ||
style?.color ||
style?.elements
),
hasSupport: hasColorSupport,
};

Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/dimensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export function hasDimensionsSupport( blockName, feature = 'any' ) {
export default {
useBlockProps,
attributeKeys: [ 'minHeight', 'style' ],
isMatch: ( { style, minHeight } ) => !! ( minHeight || style?.dimensions ),
hasSupport( name ) {
return hasDimensionsSupport( name, 'aspectRatio' );
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/duotone.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ export default {
edit: DuotonePanelPure,
useBlockProps,
attributeKeys: [ 'style' ],
isMatch: ( { style } ) => !! style?.color?.duotone,
hasSupport( name ) {
return hasBlockSupport( name, 'filter.duotone' );
},
Expand Down
2 changes: 2 additions & 0 deletions packages/block-editor/src/hooks/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ export default {
useBlockProps,
addSaveProps,
attributeKeys: [ 'fontSize', 'style' ],
isMatch: ( { style, fontSize } ) =>
!! ( style?.typography?.fontSize || fontSize ),
hasSupport( name ) {
return hasBlockSupport( name, FONT_SIZE_SUPPORT_KEY );
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/layout-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ export default {
useBlockProps: useBlockPropsChildLayoutStyles,
edit: ChildLayoutControlsPure,
attributeKeys: [ 'style' ],
isMatch: ( { style } ) => !! style?.layout,
hasSupport() {
return true;
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ export default {
},
useBlockProps,
attributeKeys: [ 'style' ],
isMatch: ( { style } ) => !! style?.position,
hasSupport( name ) {
return hasBlockSupport( name, POSITION_SUPPORT_KEY );
},
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/hooks/text-align.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export default {
useBlockProps,
addSaveProps: addAssignedTextAlign,
attributeKeys: [ 'style' ],
isMatch: ( { style } ) => !! style?.typography?.textAlign,
hasSupport( name ) {
return hasBlockSupport( name, TEXT_ALIGN_SUPPORT_KEY, false );
},
Expand Down
Loading