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

Ensure root selector (body) is not wrapped in :root :where() #7061

Closed

Conversation

talldan
Copy link
Contributor

@talldan talldan commented Jul 19, 2024

Trac ticket: https://core.trac.wordpress.org/ticket/61704
Gutenberg issue: WordPress/gutenberg#63712
Gutenberg PR: WordPress/gutenberg#63726

What?

In WordPress 6.6, there was a general effort to lower and level specificity, but a couple of selectors seem to have mistakenly had their specificity raised.

The styles associated with the body are an example. In 6.5 these styles used the simple body selector. In 6.6 the selector is :root :where(body), an increase in specificity.

Why?

These changes may cause some problems for themes, especially the typography styles in the body, which will cascade.

How?

Reverts the selector back to body

Note that unlike the gutenberg PR, the core backport only affects the frontend styles. The editor styles will be fixed by updating the packages from gutenberg.

props to @aaronrobertshaw for pointing me to the fix

Testing Instructions

  1. Open the site editor
  2. Click the editor area to open the editor
  3. Click 'View site' to view the frontend
  4. Insect the body element's styles
  5. Using the browser dev tools, check that the styles are like 'expected' snippet below, with a simple body selector and not a :root :where(body) selector.

Expected:

body {
    --wp--style--root--padding-top: 115px;
    --wp--style--root--padding-right: var(--wp--preset--spacing--50);
    --wp--style--root--padding-bottom: 115px;
    --wp--style--root--padding-left: var(--wp--preset--spacing--50);
    color: var(--wp--preset--color--contrast);
    background-color: var(--wp--preset--color--base);
    font-family: var(--wp--preset--font-family--body);
    font-size: var(--wp--preset--font-size--medium);
    font-style: normal;
    font-weight: 400;
    line-height: 1.55;
}

Before:

:root :where(body) {
    --wp--style--root--padding-top: 115px;
    --wp--style--root--padding-right: var(--wp--preset--spacing--50);
    --wp--style--root--padding-bottom: 115px;
    --wp--style--root--padding-left: var(--wp--preset--spacing--50);
    color: var(--wp--preset--color--contrast);
    background-color: var(--wp--preset--color--base);
    font-family: var(--wp--preset--font-family--body);
    font-size: var(--wp--preset--font-size--medium);
    font-style: normal;
    font-weight: 400;
    line-height: 1.55;
}

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.

@talldan talldan added the bug label Jul 19, 2024
@talldan talldan self-assigned this Jul 19, 2024
Copy link

github-actions bot commented Jul 19, 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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props talldanwp, andrewserong, aaronrobertshaw, mukesh27, hellofromtonya.

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

Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

This is testing nicely for me, with the styles for the root selector now being applied to body instead of :root :where(body) 👍. Tested with a couple of different block and classic themes.

The code change also looks good and simple. I think this will be a good fix to get in for 6.6.1. LGTM!

Copy link

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

Thanks @talldan 👍

This is testing as per WordPress/gutenberg#63726.

Before After
Screenshot 2024-07-19 at 4 06 52 PM Screenshot 2024-07-19 at 4 04 12 PM

Before we get this comitted, I think we will need to add a @since 6.6.1 comment as well as @ticket 61704 comments to all the affected tests.

src/wp-includes/class-wp-theme-json.php Show resolved Hide resolved
@talldan
Copy link
Contributor Author

talldan commented Jul 19, 2024

Thanks for spotting that. Linty things should be all fixed in the last two commits 👍

@aaronrobertshaw
Copy link

Thanks the @since and @ticket comments LGTM 👍

@talldan talldan force-pushed the fix/body-selector-specificity branch from 8a39a76 to 4f7001f Compare July 24, 2024 08:27
Comment on lines +2738 to +2742
* @since 6.6.1 Avoid applying `:root :where()` wrapper to top-level element-only selectors.
* @since 6.6.2 Avoid applying `:root :where()` wrapper to root selectors.
Copy link
Contributor

Choose a reason for hiding this comment

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

These 2 @since shouldn't be necessary, as they are both bugfixes. @since is added for changes in functionality, function parameter(s), return types, filters, etc.

The commit history will provide the context of the bugfix changes.

Suggested change
* @since 6.6.1 Avoid applying `:root :where()` wrapper to top-level element-only selectors.
* @since 6.6.2 Avoid applying `:root :where()` wrapper to root selectors.

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.

  • Tested before and after on trunk and the 6.6 branch (see Test Report) - can reproduce and this patch resolves it ✅

  • Double checked changes with its Gutenberg PR - confirmed its a clean merge of PHP changes ✅

LGTM for commit ✅

@talldan talldan force-pushed the fix/body-selector-specificity branch from 16de2a2 to 97b197a Compare August 6, 2024 08:07
@talldan
Copy link
Contributor Author

talldan commented Aug 6, 2024

Committed in r58856

@talldan talldan closed this Aug 6, 2024
@talldan talldan deleted the fix/body-selector-specificity branch August 6, 2024 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants