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

Custom css variables in theme.json have different keys in 5.9 #39155

Closed
Clorith opened this issue Mar 2, 2022 · 8 comments
Closed

Custom css variables in theme.json have different keys in 5.9 #39155

Clorith opened this issue Mar 2, 2022 · 8 comments
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json

Comments

@Clorith
Copy link
Member

Clorith commented Mar 2, 2022

Description

This is a migration of the reported issue from https://core.trac.wordpress.org/ticket/54953 :

Noticed that custom css variables generated by theme.json can have different output in WP5.9 compared to how they were in 5.8. Seems like 5.9 adds an extra - when numbers are included in the key.

{
  "settings": {
    "custom": {
      "m16": "1rem"
    }
  }
}

The example above will in 5.8 create a variable called: --wp--custom--m16 but in 5.9 it will be --wp--custom--m-16.
I'm not sure if the change was a bug fix or unintended change. We have a plugin that allows themes to change som style using custom variables and this bug makes it hard to support both 5.8 and 5.9

Step-by-step reproduction instructions

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 5.9

Please confirm that you have searched existing issues in the repo.

Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

Yes

@Mamaduka
Copy link
Member

Mamaduka commented Mar 2, 2022

Thanks for reporting the issue.

If I remember correctly, these changes were required to get parity between JS/PHP kebab case - #36875.

@Mamaduka Mamaduka added the Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json label Mar 2, 2022
@skorasaurus skorasaurus added the CSS Styling Related to editor and front end styles, CSS-specific issues. label Mar 2, 2022
@skorasaurus
Copy link
Member

Thanks for reporting; this was an intentional change as reported at #31629 and fixed in #35751

@Clorith
Copy link
Member Author

Clorith commented Mar 2, 2022

So this is an intentional change that isn't going to change back then, am I reading that right? As this is a breaking change in styling behavior between 5.8 and 5.9 in terms of theme.json compatibility, we need to be very clear if that's the case.

@ZebulanStanphill ZebulanStanphill added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label Mar 4, 2022
@Clorith
Copy link
Member Author

Clorith commented Mar 8, 2022

Following up here, isn't would it not make sense to use them theme.json versioning to denote changes in behavior like this as well? (I'm thinking out loud trying to find solutions here).

I know it generally relates to available features, but I would say that different behavior of how the defined values are treated also falls within the realm of what could be considered versioned behavior 🤔

@annezazu
Copy link
Contributor

annezazu commented Mar 9, 2022

To follow back up here on next steps, working with @oandregal to get an update to https://make.wordpress.org/core/2022/01/08/updates-for-settings-styles-and-theme-json/ in light of this change. There will be a comment noting the change and the post itself will be updated, since this is an intentional change.

As for thinking about versioning, I'm afraid I can't speak to how viable that might be as an option. Appreciate you thinking through ways forward though <3

@oandregal
Copy link
Member

Yeah, this is a bug in 5.8 that we fixed in 5.9. Here's a potential text to add in the devnote:

Fix for CSS Custom Property names that contain numbers

In 5.9 we fixed a bug by which the frontend and the editors would render different CSS Custom Properties. Take this example:

{
    "settings": {
        "color": {
            "palette": [
                {
                    "slug": "white2black",
                    "color": "value",
                    "name": "White to Black"
                }
            ]
        },
        "custom": {
            "white2black": "value"
        }
    }
}

The expected result is that the engine generates the following properties (note how white2black is converted into white-2-black):

body {
  --wp--preset--color--white-2-black: "value";
  --wp--custom--white-2-black: "value";
}

In 5.8 the code generated for the frontend had a bug by which it wouldn't explode the numbers.

@annezazu
Copy link
Contributor

^ I added this into the dev note and added a changelog to note the update. Thank you!

@oandregal
Copy link
Member

I don't seem to be able to close the track ticket https://core.trac.wordpress.org/ticket/54953 Sharing here in case anyone is able to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CSS Styling Related to editor and front end styles, CSS-specific issues. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json
Projects
None yet
Development

No branches or pull requests

6 participants