Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport Fix spacing property generation in flow layout type #3324

Closed

Conversation

tellthemachines
Copy link
Contributor

Trac ticket: https://core.trac.wordpress.org/ticket/56467

Backports fix to block spacing from WordPress/gutenberg#44446


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link
Contributor

@andrewserong andrewserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for backporting this one @tellthemachines! This is working nicely in my local environment with the following test markup, and running TwentyTwentyTwo theme. Prior to this PR, the custom blockGap spacing for each of these columns is not rendered on the site frontend. With the PR, the CSS variable-based values are output correctly 👍

Test Columns markup
<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"style":{"spacing":{"blockGap":"var:preset|spacing|20"}}} -->
<div class="wp-block-column"><!-- wp:paragraph -->
<p>A paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another paragraph</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"style":{"spacing":{"blockGap":"var:preset|spacing|80"}}} -->
<div class="wp-block-column"><!-- wp:paragraph -->
<p>A paragraph</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Another paragraph</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->

LGTM!

@hellofromtonya hellofromtonya self-assigned this Sep 26, 2022
@hellofromtonya
Copy link
Contributor

Self-assigning for commit review and prep.

@hellofromtonya
Copy link
Contributor

hellofromtonya commented Sep 26, 2022

Test Report

Env:

  • WordPress: current trunk
  • Themes: TT2 and TT3
  • Plugins: none activated
  • Localhost: wp-env
  • OS: macOS
  • Browser: Firefox, Chrome, and Edge

Test Instructions:

  • Step 1: Pull the latest trunk into your local testing environment.
  • Step 2: Deactivate all plugins including Gutenberg.
  • Step 3: Activate TT2 theme.
  • Step 4: Add a new post and paste this code:
Test Columns markup
<!-- wp:group {"style":{"spacing":{"blockGap":"var:preset|spacing|70"}},"backgroundColor":"primary"} -->
<div class="wp-block-group has-primary-background-color has-background"><!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tincidunt ex in eros ultrices hendrerit.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tincidunt ex in eros ultrices hendrerit.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:group -->

<!-- wp:columns -->
<div class="wp-block-columns"><!-- wp:column {"style":{"spacing":{"blockGap":"var:preset|spacing|60"}},"backgroundColor":"primary"} -->
<div class="wp-block-column has-primary-background-color has-background"><!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tincidunt ex in eros ultrices hendrerit.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tincidunt ex in eros ultrices hendrerit.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"style":{"spacing":{"blockGap":"var:preset|spacing|80"}},"backgroundColor":"primary"} -->
<div class="wp-block-column has-primary-background-color has-background"><!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tincidunt ex in eros ultrices hendrerit.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tincidunt ex in eros ultrices hendrerit.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column -->

<!-- wp:column {"style":{"spacing":{"blockGap":"var:preset|spacing|30"}},"backgroundColor":"primary"} -->
<div class="wp-block-column has-primary-background-color has-background"><!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tincidunt ex in eros ultrices hendrerit.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc tincidunt ex in eros ultrices hendrerit.</p>
<!-- /wp:paragraph --></div>
<!-- /wp:column --></div>
<!-- /wp:columns -->
  • Step 5: View the post in the front end.
  • Step 6: Look at the last paragraph's CSS (use your browser's DevTools). Notice the margin-block-start property.
    • Bug: Before applying the patch, the property's value is invalid and crossed out.
    • Expected: The property's value should be valid CSS and take precedence.
  • Step 7: Apply the patch.
  • Step 8: Refresh the post in the front-end.
  • Step 9: Repeat Step 6. This time the CSS should be valid.
  • Step 10: Repeat the above steps with TT3.

Results:

Summary:

  • Confirmed the bug report of invalid CSS ✅ 🐞
  • Confirmed the fix resolves the issue, ie renders valid CSS ✅

Using TT2:

The PHP Code's $gap_value:

  • Before: 'var:preset|spacing|70'
  • After: var(--wp--preset--spacing--70)

Before applying the patch

Screen Shot 2022-09-26 at 7 29 24 AM

.wp-block-group.wp-container-7.wp-block-group.wp-container-7 > * + * {
  margin-block-start: var:preset|spacing|70;
  margin-block-end: 0;
}

Screen Shot 2022-09-26 at 7 51 59 AM

After applying the patch

Screen Shot 2022-09-26 at 7 46 04 AM

Screen Shot 2022-09-26 at 7 49 18 AM

.wp-block-group.wp-container-7.wp-block-group.wp-container-7 > * + * {
  margin-block-start: var(--wp--preset--spacing--70);
  margin-block-end: 0;
}

Using TT3:

The PHP Code's $gap_value:

  • Before: 'var:preset|spacing|70'
  • After: var(--wp--preset--spacing--70)

Before applying the patch

Screen Shot 2022-09-26 at 7 57 23 AM

Screen Shot 2022-09-26 at 7 57 33 AM

.wp-block-group.wp-container-7.wp-block-group.wp-container-7 > * + * {
  margin-block-start: var:preset|spacing|70;
  margin-block-end: 0;
}

After applying the patch

Screen Shot 2022-09-26 at 7 58 59 AM

Screen Shot 2022-09-26 at 7 59 22 AM

.wp-block-group.wp-container-7.wp-block-group.wp-container-7 > * + * {
  margin-block-start: var(--wp--preset--spacing--70);
  margin-block-end: 0;
}

@hellofromtonya
Copy link
Contributor

hellofromtonya commented Sep 26, 2022

Confirmed: This PR does fix the reported bug WordPress/gutenberg#44435

However, there are no tests for this specific expectation. I'll add a dataset to this PR Done 0d6646b

* Tests fail without the fix.
* Tests pass with the fix.
Copy link
Contributor

@hellofromtonya hellofromtonya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Confirmed the bug exists prior to applying this code ✅
  • Confirmed generates valid CSS with this code applied ✅
  • Tests valid the bug (fail before apply the bugfix) and fix (pass after applying the bugfix) ✅

There 3 instances of the same gap value conversion code in this one function. These instances could be consolidated into a static function. However, as there was already 2 instances prior to this PR, refactoring is outside the scope of this PR. Will explore in a separate PR.

This PR is ready for commit. Prepping now.

pento pushed a commit that referenced this pull request Sep 26, 2022
Fixes a bug of invalid CSS value when applying block spacing to a block as reported in [WordPress/gutenberg#44435 Gutenberg issue 44435].

Adds logic to convert preset values (i.e. `$gap_value`) into valid CSS custom properties for the flow ('default') layout type. See the original fix in [#3324 Gutenberg PR 3324].

Also adds a test dataset that fails before the bugfix and passes after the bugix.

Follow-up to [54274].

Props ndiego, isabel_brison, ramonopoly, andrewserong, hellofromTonya.
See #56467.

git-svn-id: https://develop.svn.wordpress.org/trunk@54311 602fd350-edb4-49c9-b593-d223f7449a82
markjaquith pushed a commit to markjaquith/WordPress that referenced this pull request Sep 26, 2022
Fixes a bug of invalid CSS value when applying block spacing to a block as reported in [WordPress/gutenberg#44435 Gutenberg issue 44435].

Adds logic to convert preset values (i.e. `$gap_value`) into valid CSS custom properties for the flow ('default') layout type. See the original fix in [WordPress/wordpress-develop#3324 Gutenberg PR 3324].

Also adds a test dataset that fails before the bugfix and passes after the bugix.

Follow-up to [54274].

Props ndiego, isabel_brison, ramonopoly, andrewserong, hellofromTonya.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54311


git-svn-id: http://core.svn.wordpress.org/trunk@53870 1a063a9b-81f0-0310-95a4-ce76da25c4cd
github-actions bot pushed a commit to platformsh/wordpress-performance that referenced this pull request Sep 26, 2022
Fixes a bug of invalid CSS value when applying block spacing to a block as reported in [WordPress/gutenberg#44435 Gutenberg issue 44435].

Adds logic to convert preset values (i.e. `$gap_value`) into valid CSS custom properties for the flow ('default') layout type. See the original fix in [WordPress/wordpress-develop#3324 Gutenberg PR 3324].

Also adds a test dataset that fails before the bugfix and passes after the bugix.

Follow-up to [54274].

Props ndiego, isabel_brison, ramonopoly, andrewserong, hellofromTonya.
See #56467.
Built from https://develop.svn.wordpress.org/trunk@54311


git-svn-id: https://core.svn.wordpress.org/trunk@53870 1a063a9b-81f0-0310-95a4-ce76da25c4cd
@hellofromtonya
Copy link
Contributor

Merged via changest https://core.trac.wordpress.org/changeset/54311. Thank you everyone for your contributions in identifying and resolving this issue 🎉

ootwch pushed a commit to ootwch/wordpress-develop that referenced this pull request Nov 4, 2022
Fixes a bug of invalid CSS value when applying block spacing to a block as reported in [WordPress/gutenberg#44435 Gutenberg issue 44435].

Adds logic to convert preset values (i.e. `$gap_value`) into valid CSS custom properties for the flow ('default') layout type. See the original fix in [WordPress#3324 Gutenberg PR 3324].

Also adds a test dataset that fails before the bugfix and passes after the bugix.

Follow-up to [54274].

Props ndiego, isabel_brison, ramonopoly, andrewserong, hellofromTonya.
See #56467.

git-svn-id: https://develop.svn.wordpress.org/trunk@54311 602fd350-edb4-49c9-b593-d223f7449a82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

3 participants