Skip to content

Commit

Permalink
Add skip serialization checks for link colors and block gap
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronrobertshaw committed Feb 4, 2022
1 parent 6591acd commit 5969167
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 7 additions & 0 deletions lib/block-supports/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ function gutenberg_render_elements_support( $block_content, $block ) {
return $block_content;
}

$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
$skip_link_color_serialization = gutenberg_skip_color_serialization( $block_type, 'link' );

if ( $skip_link_color_serialization ) {
return $block_content;
}

$link_color = null;
if ( ! empty( $block['attrs'] ) ) {
$link_color = _wp_array_get( $block['attrs'], array( 'style', 'elements', 'link', 'color', 'text' ), null );
Expand Down
15 changes: 12 additions & 3 deletions packages/block-editor/src/hooks/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,23 @@ export const withBlockControls = createHigherOrderComponent(
*/
const withElementsStyles = createHigherOrderComponent(
( BlockListBlock ) => ( props ) => {
const elements = props.attributes.style?.elements;

const blockElementsContainerIdentifier = `wp-elements-${ useInstanceId(
BlockListBlock
) }`;

const skipSerialization = shouldSkipSerialization(
props.name,
COLOR_SUPPORT_KEY,
'link'
);

const elements = skipSerialization
? omit( props.attributes.style?.elements, [ 'link' ] )
: props.attributes.style?.elements;

const styles = compileElementsStyles(
blockElementsContainerIdentifier,
props.attributes.style?.elements
elements
);
const element = useContext( BlockList.__unstableElementContext );

Expand Down

0 comments on commit 5969167

Please sign in to comment.