From ca2923d3edb50ad12861a55cd7f42f5e9677b3c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Fri, 19 Feb 2021 16:53:10 +0100 Subject: [PATCH] Try: skip serialization in the block supports mechanism (#29142) --- lib/block-supports/colors.php | 9 +++++++++ packages/block-editor/src/hooks/color.js | 18 +++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/block-supports/colors.php b/lib/block-supports/colors.php index e652f578393877..d1d0b4655fdfdf 100644 --- a/lib/block-supports/colors.php +++ b/lib/block-supports/colors.php @@ -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 ); diff --git a/packages/block-editor/src/hooks/color.js b/packages/block-editor/src/hooks/color.js index 5490e045fbc056..d8821b16713f39 100644 --- a/packages/block-editor/src/hooks/color.js +++ b/packages/block-editor/src/hooks/color.js @@ -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; @@ -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; } @@ -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; @@ -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 ; }