#105014CKEditor `contentsCss`: Selectors with `:has()` and `:where()` are not properly prefixed
Description
Steps to reproduce:
1. Create and apply an RTE configuration with contentsCss.
2. In the referenced CSS file, declare CSS using :has and or :where selectors.
3. Edit content in the backend, and inspect with the browser devtools. Selectors with :has and :where will not be applied. They seem to be missing in the constructed CSS.
Example:
ul li:has(& > p.text-center) {
color: red;
}
Then, in the editor, create a list and center it. The list item will not be colored red. The devtools web inspector will not show any sign of these selectors.
Note that this isn’t a nesting standard incompatibility. This does not work either:
ul li:has(> p.text-center) {
color: red;
}
Note that neither :has() nor :where() selectors work, but pseudo-classes like ::before do.
According to AST explorer, css-tree, the package used to preprocess editor CSS content, parses the :has selector just fine: https://astexplorer.net/#/gist/244e2fb4da940df52bf0f4b94277db44/8f51276c0fcd8ce562da7cc695fb33d0b2fbef1a
Reviews 2
History 59
-
Garvin Hicking commented 09/17/24, 20:55
-
Garvin Hicking commented and changed subject
CKEditor `contentsCss`: Selectors with `:has()` and `:where()` are not applied to editor content.CKEditor `contentsCss`: Selectors with `:has()` and `:where()` are not properly prefixed 09/18/24, 14:33I’ve debugged this in part. Indeed the prefixing is executed for me, though.
It turns this:
ul li:has(& > p.text-center) { color: red; }into this:
#data_tt_content__2685__bodytext_ckeditor5 .ck-content ul li:has(#data_tt_content__2685__bodytext_ckeditor5 .ck-content &>p.text-center){ color:red }note that the prefixer also applies all the `has()` parts with the prefix, too. And of course the `ul li` cannot contain a
p.text-centerinside of it, wrapping the prefixed part again.Probably the AST walker of
Build/Sources/TypeScript/rte_ckeditor/css-prefixer.tsin methodcssPrefixerhas to be adapted to recognize if it’s inside context of a PseudoClassSelector and skip application. My tries to implement this failed though. -
Gerrit Code Review pushed patch set 1 for main to change 86305 status
NewUnder Review 09/25/24, 06:12 -
Benjamin Franzke commented 09/25/24, 06:13
The nesting selector
&– https://developer.mozilla.org/en-US/docs/Web/CSS/Nesting_selector – is not meant to be used within:has(), that code actually does not work, even without the css-prefixer.But you are right, the css-prefixer must not prefix nested selectors and I pushed a patch to address that: https://review.typo3.org/c/Packages/TYPO3.CMS/+/86305
Edit: That means you should actually use:
ul li:has(> p.text-center) { color: red; } -
Gerrit Code Review pushed patch set 2 for main to change 86305 09/25/24, 06:23
-
Gerrit Code Review pushed patch set 3 for main to change 86305 09/25/24, 07:21
-
Gerrit Code Review pushed patch set 1 for 12.4 to change 86332 09/25/24, 09:57
-
Benjamin Franzke commented and changed status
Under ReviewResolved done0 %100 % 09/25/24, 10:05Applied in changeset commit:e60a4ad2244eb5a5ab317f63a1caa74d47a34b27.
-
Benni Mack changed status
ResolvedClosed 10/15/24, 09:05
Relevant place for this might be: https://github.com/TYPO3/typo3/blob/main/Build/Sources/TypeScript/rte_ckeditor/css-prefixer.ts#L6C1-L6C7