Skip to content

Theme JSON: remove unused vars in layout class#59938

Merged
ramonjd merged 2 commits intotrunkfrom
update/remove-unused-var-theme-json-layout
Mar 18, 2024
Merged

Theme JSON: remove unused vars in layout class#59938
ramonjd merged 2 commits intotrunkfrom
update/remove-unused-var-theme-json-layout

Conversation

@ramonjd
Copy link
Copy Markdown
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 requested a review from andrewserong March 18, 2024 01:11
@ramonjd ramonjd self-assigned this Mar 18, 2024
$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
Copy Markdown
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
Copy Markdown
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?

@github-actions
Copy link
Copy Markdown

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
Copy Markdown
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.

@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
@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