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: Don't output rules that 'unset' properties #48351

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

scruffian
Copy link
Contributor

What?

If a theme sets a Duotone filter, users might want to override this by setting the filter to "unset" (see #48255). This is important to allow users to turn off duotone for specific blocks.

When unset is selected, this is saved to the database:

{"styles":{"blocks":{"core\/image":{"filter":{"duotone":"unset"}}}},"isGlobalStylesUserThemeJSON":true,"version":2}

Which generates the following CSS:

.wp-block-image img, .wp-block-image .components-placeholder{filter: unset;}

It would be better if we didn't generate any CSS for the block if the global styles changed to unset.

Why?

Outputting redundant code is bad for performance.

How?

If a declaration has a value of unset then don't output it. I'm not sure if this is the best place to achieve this. We can do something specific for Duotone in #48255 but once Duotone is treated like all other styles then we won't be able to (which is the goal).

Testing Instructions

  1. Switch to a theme that has a default Duotone (TT3 style variations have them)
  2. Open Global Styles and disable the Duotone for that block (see Duotone: Add Global Styles controls for blocks that support duotone #48255 for details)
  3. Check that the block in the frontend doesn't have an filters applied in the CSS.

@scruffian scruffian added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Feb 23, 2023
@scruffian scruffian self-assigned this Feb 23, 2023
@@ -1488,6 +1488,9 @@ protected static function to_ruleset( $selector, $declarations ) {
$declaration_block = array_reduce(
$declarations,
static function ( $carry, $element ) {
if ( 'unset' === $element['value'] ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also do this in the editor? I see the unset there

@MaggieCabrera
Copy link
Contributor

I think this idea could work, but I'm interested to hear the opinions of other people who have more experience with global styles. I haven't found other instances where we need to "unset" anything in global styles, but that doesn't mean we won't need to in the future.

@draganescu
Copy link
Contributor

I think we should close this because this commit 5c564fe is better and makes it easier for us to test things.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants