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

Block editor: hooks: early returns for getEditWrapperProps filters #56879

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 6 additions & 0 deletions packages/block-editor/src/hooks/border.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ function addAttributes( settings ) {
* @return {Object} Filtered props to apply to save element.
*/
function addSaveProps( props, blockType, attributes ) {
const { borderColor, style } = attributes;

if ( ! borderColor && ! style?.border?.color ) {
return props;
}

if (
! hasBorderSupport( blockType, 'color' ) ||
shouldSkipSerialization( blockType, BORDER_SUPPORT_KEY, 'color' )
Expand Down
10 changes: 7 additions & 3 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ function addAttributes( settings ) {
* @return {Object} Filtered props applied to save element.
*/
export function addSaveProps( props, blockType, attributes ) {
// I'd have preferred to avoid the "style" attribute usage here
const { backgroundColor, textColor, gradient, style } = attributes;

if ( ! backgroundColor && ! textColor && ! gradient && ! style ) {
return props;
}

if (
! hasColorSupport( blockType ) ||
shouldSkipSerialization( blockType, COLOR_SUPPORT_KEY )
Expand All @@ -142,9 +149,6 @@ export function addSaveProps( props, blockType, attributes ) {

const hasGradient = hasGradientSupport( blockType );

// I'd have preferred to avoid the "style" attribute usage here
const { backgroundColor, textColor, gradient, style } = attributes;

const shouldSerialize = ( feature ) =>
! shouldSkipSerialization( blockType, COLOR_SUPPORT_KEY, feature );

Expand Down
18 changes: 12 additions & 6 deletions packages/block-editor/src/hooks/font-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ function addAttributes( settings ) {
* @return {Object} Filtered props applied to save element.
*/
function addSaveProps( props, blockType, attributes ) {
if ( ! attributes.fontSize ) {
return props;
}

if ( ! hasBlockSupport( blockType, FONT_SIZE_SUPPORT_KEY ) ) {
return props;
}
Expand Down Expand Up @@ -285,6 +289,10 @@ function addEditPropsForFluidCustomFontSizes( blockType ) {

const fontSize = wrapperProps?.style?.fontSize;

if ( ! fontSize ) {
return wrapperProps;
}

// TODO: This sucks! We should be using useSetting( 'typography.fluid' )
// or even useSelect( blockEditorStore ). We can't do either here
// because getEditWrapperProps is a plain JavaScript function called by
Expand All @@ -295,12 +303,10 @@ function addEditPropsForFluidCustomFontSizes( blockType ) {
const fluidTypographySettings = getFluidTypographyOptionsFromSettings(
select( blockEditorStore ).getSettings().__experimentalFeatures
);
const newFontSize = fontSize
? getTypographyFontSizeValue(
{ size: fontSize },
fluidTypographySettings
)
: null;
const newFontSize = getTypographyFontSizeValue(
{ size: fontSize },
fluidTypographySettings
);

if ( newFontSize === null ) {
return wrapperProps;
Expand Down
5 changes: 5 additions & 0 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ export function addSaveProps(
}

let { style } = attributes;

if ( ! style ) {
return props;
}

Object.entries( skipPaths ).forEach( ( [ indicator, path ] ) => {
const skipSerialization =
skipSerializationPathsSaveChecks[ indicator ] ||
Expand Down
Loading