Skip to content

Commit c8071d9

Browse files
Add support for skipping serialization of border color
1 parent 4236a62 commit c8071d9

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/block-editor/src/hooks/border-color.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
getColorObjectByColorValue,
1919
} from '../components/colors';
2020
import useEditorFeature from '../components/use-editor-feature';
21-
import { hasBorderFeatureSupport } from './border';
21+
import { hasBorderFeatureSupport, shouldSkipSerialization } from './border';
2222
import { cleanEmptyObject } from './utils';
2323

2424
const EMPTY_ARRAY = [];
@@ -129,7 +129,10 @@ function addAttributes( settings ) {
129129
* @return {Object} Filtered props to apply to save element.
130130
*/
131131
function addSaveProps( props, blockType, attributes ) {
132-
if ( ! hasBorderFeatureSupport( 'color', blockType ) ) {
132+
if (
133+
! hasBorderFeatureSupport( 'color', blockType ) ||
134+
shouldSkipSerialization( blockType )
135+
) {
133136
return props;
134137
}
135138

@@ -154,7 +157,10 @@ function addSaveProps( props, blockType, attributes ) {
154157
* @return {Object} Filtered block settings.
155158
*/
156159
function addEditProps( settings ) {
157-
if ( ! hasBorderFeatureSupport( 'color', settings ) ) {
160+
if (
161+
! hasBorderFeatureSupport( 'color', settings ) ||
162+
shouldSkipSerialization( settings )
163+
) {
158164
return settings;
159165
}
160166

packages/block-editor/src/hooks/border.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,25 @@ export function hasBorderSupport( blockName ) {
6464
*
6565
* @param {string} feature Name of the border feature e.g.`radius`
6666
* @param {string|Object} blockType Block name or block type object.
67-
* @return { boolean } Whether the border feature is supported.
67+
* @return {boolean} Whether the border feature is supported.
6868
*/
6969
export function hasBorderFeatureSupport( feature, blockType ) {
7070
const support = getBlockSupport( blockType, BORDER_SUPPORT_KEY );
7171
return !! ( true === support || ( support && support[ feature ] ) );
7272
}
7373

74+
/**
75+
* Check whether serialization of border classes and styles should be skipped.
76+
*
77+
* @param {string|Object} blockType Block name or block type object.
78+
* @return {boolean} Whether serialization of border properties should occur.
79+
*/
80+
export function shouldSkipSerialization( blockType ) {
81+
const support = getBlockSupport( blockType, BORDER_SUPPORT_KEY );
82+
83+
return support?.__experimentalSkipSerialization;
84+
}
85+
7486
/**
7587
* Determines whether there is any block support for borders e.g. border radius,
7688
* style, width etc.

0 commit comments

Comments
 (0)