Skip to content

Commit

Permalink
Try: skip serialization in the block supports mechanism (#29142)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Feb 19, 2021
1 parent 30343c5 commit ca2923d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/block-supports/colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ function gutenberg_register_colors_support( $block_type ) {
*/
function gutenberg_apply_colors_support( $block_type, $block_attributes ) {
$color_support = gutenberg_experimental_get( $block_type->supports, array( 'color' ), false );

if (
is_array( $color_support ) &&
array_key_exists( '__experimentalSkipSerialization', $color_support ) &&
$color_support['__experimentalSkipSerialization']
) {
return array();
}

$has_text_colors_support = true === $color_support || ( is_array( $color_support ) && gutenberg_experimental_get( $color_support, array( 'text' ), true ) );
$has_background_colors_support = true === $color_support || ( is_array( $color_support ) && gutenberg_experimental_get( $color_support, array( 'background' ), true ) );
$has_link_colors_support = gutenberg_experimental_get( $color_support, array( 'link' ), false );
Expand Down
18 changes: 15 additions & 3 deletions packages/block-editor/src/hooks/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ const hasColorSupport = ( blockType ) => {
);
};

const shouldSkipSerialization = ( blockType ) => {
const colorSupport = getBlockSupport( blockType, COLOR_SUPPORT_KEY );

return colorSupport?.__experimentalSkipSerialization;
};

const hasLinkColorSupport = ( blockType ) => {
if ( Platform.OS !== 'web' ) {
return false;
Expand Down Expand Up @@ -124,7 +130,10 @@ function addAttributes( settings ) {
* @return {Object} Filtered props applied to save element
*/
export function addSaveProps( props, blockType, attributes ) {
if ( ! hasColorSupport( blockType ) ) {
if (
! hasColorSupport( blockType ) ||
shouldSkipSerialization( blockType )
) {
return props;
}

Expand Down Expand Up @@ -169,7 +178,10 @@ export function addSaveProps( props, blockType, attributes ) {
* @return {Object} Filtered block settings
*/
export function addEditProps( settings ) {
if ( ! hasColorSupport( settings ) ) {
if (
! hasColorSupport( settings ) ||
shouldSkipSerialization( settings )
) {
return settings;
}
const existingGetEditWrapperProps = settings.getEditWrapperProps;
Expand Down Expand Up @@ -375,7 +387,7 @@ export const withColorPaletteStyles = createHigherOrderComponent(
const { name, attributes } = props;
const { backgroundColor, textColor } = attributes;
const colors = useEditorFeature( 'color.palette' ) || EMPTY_ARRAY;
if ( ! hasColorSupport( name ) ) {
if ( ! hasColorSupport( name ) || shouldSkipSerialization( name ) ) {
return <BlockListBlock { ...props } />;
}

Expand Down

0 comments on commit ca2923d

Please sign in to comment.