Make WordPress Core

Opened 6 months ago

Closed 5 months ago

Last modified 5 months ago

#65265 closed defect (bug) (fixed)

Fix inconsistencies in global styles feature selectors

Reported by: isabel_brison Owned by: isabel_brison
Priority: normal Milestone: 7.1
Component: Editor Version:
Severity: normal Keywords: gutenberg-merge has-patch has-unit-tests
Cc: Focuses:

Description

The fixes from ​https://github.com/WordPress/gutenberg/pull/78276 should be included in core.

Change History (12)

This ticket was mentioned in ​PR #11857 on ​WordPress/wordpress-develop by ​@isabel_brison.


6 months ago
#1

  • Keywords has-patch has-unit-tests added

Trac ticket: https://core.trac.wordpress.org/ticket/65265

## Use of AI Tools

copied from ​https://github.com/WordPress/gutenberg/pull/78276 with codex/gpt 5.5

#2 @audrasjb
6 months ago

Removing trunk version as this is not going to be shipped with WP 7.0 but in the next releases.

#3 @desrosj
6 months ago

  • Version trunk

Removing trunk.

@isabel_brison is this something you'd advocate for including in 7.0.1?

#4 @isabel_brison
6 months ago

@desrosj not necessarily, given that the issue was already in 6.9 and previous. It only affects style variations of a couple of core blocks so likely nobody noticed it until now!

​@dmsnell commented on ​PR #11857:


5 months ago
#5

@tellthemachines I have pushed updates from my refactor to split_selector_list() from WordPress/Gutenberg#79499. I _have not_ updated the rest of this PR, and I noted some @since tags still show 7.0.0.

This will pair with #12306, which I think will break without it (this is due to tests being written which depend on earlier parsing errors, which this PR will now fix).

​@isabel_brison commented on ​PR #11857:


5 months ago
#6

@dmsnell thanks for the update, but relevant PHP tests are now failing due to a discrepancy in spacing between comma-separated selectors. Could you update your changes to reinstate the missing space? (Or otherwise update the test strings; but reinstating the space would be more consistent with how we treat those selectors elsewhere)

​@dmsnell commented on ​PR #11857:


5 months ago
#7

reinstating the space would be more consistent with how we treat those selectors elsewhere

@tellthemachines I wrestled with this in the update, because I expected downstream code to expect that each component would start with the actual selector. in three out of the six cases where that’s happening, the call-sites are calling trim() manually, and incorrectly.

we can change it back, but I think it might be less risky if we removed that burden from every caller, particularly because of the demonstrated mismatch between the default trim() characters and those that CSS defines.

either way I will follow up, but what are your thoughts here?

reinstating the space would be more consistent with how we treat those selectors elsewhere

there’s another inconsistency regardless of the spaces which is what to do with things like comments. I left them in here because there was nothing hinting that this method would remove them, but I was trying to follow through with the idea that this breaks CSS selector string into separate strings where each is its own selector, as much as that’s possible without defining these other cases.

​@isabel_brison commented on ​PR #11857:


5 months ago
#8

the call-sites are calling trim() manually, and incorrectly.

trim() is usually added in places where an extra space might cause breakage to ensure there are no extra spaces. If the characters we're trimming are incorrect we should probably fix them. Unless we're sure that with these changes the strings won't need trimming?

(I haven't dug deeply into this btw, my comment was based on comparing test strings where there are spaces around most comma-separated selectors)

I think it's fine to just update the tests if you're confident this is a better solution.

​@dmsnell commented on ​PR #11857:


5 months ago
#9

Unless we're sure that with these changes the strings won't need trimming?

If we declare it at the split_selectors_list() method then we can guarantee it; otherwise it will remain a burden for the callees, and also a burden to know which characters to trim.

I’ll update the tests, as I think that will work out more along the lines of peoples’ expectations. Like I noted, there are still inconsistencies due to the mismatch between the mental model of the method “split selectors” and the fact that there may be more than selectors in a CSS selector string.

---

In the process I found what appears to be code that 100% could never work as expected from wordpress/gutenberg#58051 and am trying to understand and address it.

​@isabel_brison commented on ​PR #11857:


5 months ago
#10

Thanks for the updates @dmsnell! This won't be fully testable in the core dev env until the editor files are synced to include ​https://github.com/WordPress/gutenberg/pull/79210. But the equivalent changes in Gutenberg are testing well fwiw.

Regarding your observation about comments, I hadn't seen it as an issue because this function isn't used for processing arbitrary CSS, but is only applied on strings that come from block or theme.json-shaped data, which is very unlikely to contain comments. We do know that we _don't_ want comments in selectors 😅 so if there's a chance they could end up in there, it would be worth ensuring they're removed, but I don't think that's something we need to be concerned about right now.

#11 @isabel_brison
5 months ago

  • Owner set to isabel_brison
  • Resolution → fixed
  • Status new → closed

In 62607:

Editor: fix inconsistencies in global styles feature selectors.

Corrects feature selector output for block style variations in global styles.

Props isabel_brison, dmsnell, talldanwp, audrasjb, desrosj.
Fixes #65265.

​@dmsnell commented on ​PR #11857:


5 months ago
#12

Thanks for merging @tellthemachines — I think I already noted this but I only examined the selector-splitting part and did not attempt to review the rest of the code or update anything.

Really appreciate your efforts; I’ll get the Gutenberg updates merged promptly so everything runs in harmony.

Note: See TracTickets for help on using tickets.