WIP: Contextual Spacing: "Apply Spacing Inside" does not work with mobile-first breakpoints

When using a mobile-first breakpoint configuration, Heading, Paragraph and Fallback Spacing are not applied to custom CSS selectors defined under Theme Styles → Contextual Spacing → Apply Spacing Inside.

Contextual Spacing works correctly for regular WordPress post content. Additional Target Elements also work as expected within custom selectors.

Steps to reproduce

  1. Configure Bricks to use mobile-first breakpoints.
  2. Open Theme Styles → Contextual Spacing.
  3. Set values for Heading, Paragraph and Fallback Spacing at the base breakpoint (Mobile Portrait).
  4. Enter .prose in the Apply Spacing Inside field.
  5. Add a Container element and assign the class prose.
  6. Set the container’s row gap to 0.
  7. Add several Heading and Basic Text elements, using p as the HTML tag for Basic Text.
  8. Inspect the result and the generated CSS in the frontend.

Expected behavior

Heading, Paragraph and Fallback Spacing should be applied within .prose, respecting the configured breakpoint values.

Actual behavior

No corresponding CSS rules are generated for .prose. Rules for Additional Target Elements, however, are generated correctly.

Root cause

I investigated the source code of Bricks and found that the implementation in includes/assets.php, lines 4812–4851, within generate_inline_css_from_element(), retrieves the spacing values without considering breakpoint suffixes:

$heading_spacing = isset( $settings['contextualSpacingHeading'] ) ? $settings['contextualSpacingHeading'] : '';

The same applies to contextualSpacingParagraph and contextualSpacingFallback.

With a mobile-first configuration, however, these settings are stored with the :mobile_portrait suffix, as confirmed by my Theme Style export:

"contextualSpacingHeading:mobile_portrait": "var(--heading-spacing)",
"contextualSpacingParagraph:mobile_portrait": "var(--paragraph-spacing)",
"contextualSpacingFallback:mobile_portrait": "var(--flow-spacing)",
"contextualSpacingApplyTo": ".prose"

As a result, the spacing values are not retrieved and the corresponding CSS rules are not generated.

The CSS generation for custom selectors appears to assume a desktop base breakpoint and does not account for breakpoint-specific values.

Suggested fix

Ensure that Heading, Paragraph and Fallback Spacing are correctly applied to the selectors defined under Apply Spacing Inside, taking the active base breakpoint and breakpoint-specific spacing values into account.

The existing implementation for Additional Target Elements already handles this correctly and could serve as a reference.

Thanks for the detailed report. We reproduced the missing contextual spacing rules for custom wrappers when Mobile Portrait is the base breakpoint. We’ll update this thread once it’s fixed.