Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
fix crash on WP 5.8
Browse files Browse the repository at this point in the history
  • Loading branch information
gigitux committed Jan 7, 2022
1 parent 4bcdc58 commit 18642e6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
20 changes: 11 additions & 9 deletions assets/js/atomic/blocks/product-elements/title/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
BLOCK_DESCRIPTION as description,
} from './constants';
import { Save } from './save';
import { hasSpacingStyleSupport } from '../../../../utils/global-style';

const blockConfig: BlockConfiguration = {
...sharedConfig,
Expand All @@ -36,15 +37,16 @@ const blockConfig: BlockConfiguration = {
__experimentalFontFamily: true,
},
} ),
...( isFeaturePluginBuild() && {
color: {
text: true,
background: true,
link: false,
gradients: true,
__experimentalSkipSerialization: true,
},
} ),
...( isFeaturePluginBuild() &&
hasSpacingStyleSupport() && {
color: {
text: true,
background: true,
link: false,
gradients: true,
__experimentalSkipSerialization: true,
},
} ),
...( isFeaturePluginBuild() && {
spacing: {
margin: true,
Expand Down
3 changes: 2 additions & 1 deletion assets/js/hooks/style-attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
*/
import { isFeaturePluginBuild } from '../settings/blocks/feature-flags';
import { isString, isObject } from '../types/type-guards';
import { hasSpacingStyleSupport } from '../utils/global-style';

type WithClass = {
className: string;
Expand All @@ -34,7 +35,7 @@ const parseStyle = ( style: unknown ): Record< string, unknown > => {
};

export const useSpacingProps = ( attributes: unknown ): WithStyle => {
if ( ! isFeaturePluginBuild() ) {
if ( ! isFeaturePluginBuild() || ! hasSpacingStyleSupport() ) {
return {
style: {},
};
Expand Down
8 changes: 8 additions & 0 deletions assets/js/utils/global-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/* eslint-disable @wordpress/no-unsafe-wp-apis */
/**
* External dependencies
*/
import { __experimentalGetSpacingClassesAndStyles } from '@wordpress/block-editor';

export const hasSpacingStyleSupport = () =>
typeof __experimentalGetSpacingClassesAndStyles === 'function';

0 comments on commit 18642e6

Please sign in to comment.