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

Theme JSON: remove unused vars in layout class #59938

Merged
merged 2 commits into from
Mar 18, 2024

Conversation

ramonjd
Copy link
Member

@ramonjd ramonjd commented Mar 18, 2024

What?

Removing some unused vars in the Theme JSON class.

Noticed while working on #42084

Why?

$has_block_gap_support is only used once
$block_gap_value is immediately overwritten in the subsequent if block

Testing Instructions

Tests should pass.

On the frontend, there should be no regressions: the block gap value should be correctly output where the ✅ is:

:where(.wp-site-blocks) > * { margin-block-start: ✅ ; margin-block-end: 0; } and body { --wp--style--block-gap: ✅; }

$has_block_gap_support is only used once
@ramonjd ramonjd added the [Type] Code Quality Issues or PRs that relate to code quality label Mar 18, 2024
@ramonjd ramonjd self-assigned this Mar 18, 2024
@@ -2729,9 +2729,7 @@ public function get_root_layout_rules( $selector, $block_metadata ) {
$css .= '.wp-site-blocks > .alignright { float: right; margin-left: 2em; }';
$css .= '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';

$block_gap_value = $this->theme_json['styles']['spacing']['blockGap'] ?? '0.5em';
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm still seeing a fallback in the JS

https://github.com/WordPress/gutenberg/blob/trunk/packages/block-editor/src/components/global-styles/use-global-styles-output.js#L479-480

Should the fallback of '0.5em' be used in the if statement if static::get_property_value returns empty?

Copy link
Contributor

Choose a reason for hiding this comment

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

Good question! A couple of considerations:

  • Core's lib/theme.json includes a styles.spacing.blockGap value of 24px, so in practice, was the 0.5em value ever being output? I'm curious if the 0.5em default spacing was ever being displayed visually for anyone 🤔
  • I think the 0.5em fallback was originally intended for flex layouts so that on classic themes where there might not be any blockGap value, things like Buttons spacing would still get a visually pleasing default value. In the case of root layout rules, that might not be necessary?

Copy link

github-actions bot commented Mar 18, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

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.

Good catch! ✨

✅ Smoke tested that root layout block spacing rules are still output when settings.spacing.blockGap is either true or false
✅ They are not output when blockGap is set to null
✅ Styles are output correctly, and the previous fallback value was never being used anyway

LGTM, just left a note about whether it's worth adding a one-line comment to flag that blockGap outputs in true and false but not null.

lib/class-wp-theme-json-gutenberg.php Show resolved Hide resolved
@andrewserong andrewserong added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Mar 18, 2024
@ramonjd ramonjd enabled auto-merge (squash) March 18, 2024 03:48
@ramonjd ramonjd merged commit 72b9ffa into trunk Mar 18, 2024
56 checks passed
@ramonjd ramonjd deleted the update/remove-unused-var-theme-json-layout branch March 18, 2024 04:20
@github-actions github-actions bot added this to the Gutenberg 18.0 milestone Mar 18, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Mar 27, 2024
Remove unused vars:
- $block_gap_value is immediately overwritten in the if block
- $has_block_gap_support is only used once

Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants