diff --git a/packages/block-editor/src/hooks/layout.js b/packages/block-editor/src/hooks/layout.js index 0497edf74eea13..de09f424995b6b 100644 --- a/packages/block-editor/src/hooks/layout.js +++ b/packages/block-editor/src/hooks/layout.js @@ -35,21 +35,29 @@ const layoutBlockSupportKey = '__experimentalLayout'; /** * Generates the utility classnames for the given block's layout attributes. * - * @param { Object } blockAttributes Block attributes. - * @param { string } blockName Block name. + * @param {Object} blockAttributes Block attributes. + * @param {string} blockName Block name. + * @param {Object} globalLayoutSettings Global layout settings. * * @return { Array } Array of CSS classname strings. */ -export function useLayoutClasses( blockAttributes = {}, blockName ) { +export function useLayoutClasses( + blockAttributes = {}, + blockName, + globalLayoutSettings +) { const rootPaddingAlignment = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); return getSettings().__experimentalFeatures ?.useRootPaddingAwareAlignments; }, [] ); - const globalLayoutSettings = useSetting( 'layout' ) || {}; const { layout } = blockAttributes; + if ( ! hasBlockSupport( blockName, layoutBlockSupportKey ) ) { + return []; + } + const { default: defaultBlockLayout } = getBlockSupport( blockName, layoutBlockSupportKey ) || {}; const usedLayout = @@ -372,9 +380,11 @@ export const withLayoutStyles = createHigherOrderComponent( layout?.inherit || layout?.contentSize || layout?.wideSize ? { ...layout, type: 'constrained' } : layout || defaultBlockLayout || {}; - const layoutClasses = hasLayoutBlockSupport - ? useLayoutClasses( attributes, name ) - : null; + const layoutClasses = useLayoutClasses( + attributes, + name, + defaultThemeLayout + ); // Higher specificity to override defaults from theme.json. const selector = `.wp-container-${ id }.wp-container-${ id }`; const blockGapSupport = useSetting( 'spacing.blockGap' ); diff --git a/packages/edit-post/src/components/visual-editor/index.js b/packages/edit-post/src/components/visual-editor/index.js index 973d28a5ec9d36..d8883e6c752a81 100644 --- a/packages/edit-post/src/components/visual-editor/index.js +++ b/packages/edit-post/src/components/visual-editor/index.js @@ -259,7 +259,8 @@ export default function VisualEditor( { styles } ) { const postContentLayoutClasses = useLayoutClasses( newestPostContentAttributes, - 'core/post-content' + 'core/post-content', + globalLayoutSettings ); const blockListLayoutClass = classnames(