Problem/Motivation

#3201820: Manually test that CKE 5 can be used in off-canvas added a CSS reset which makes CKEditor functional in off-canvas. It seems like the solution includes duplicating all CSS loaded on the page. This seems like a lot of work just for making CKEditor work in off-canvas.

Proposed resolution

Decide if we could duplicate only to a partial set of CSS.

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-3248469

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

lauriii created an issue. See original summary.

wim leers’s picture

wim leers’s picture

Project: CKEditor 5 » Drupal core
Version: 1.0.x-dev » 9.3.x-dev
Component: Code » ckeditor5.module

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nod_’s picture

I think the "formal" solution will be possible with CSS cascade layers (see https://www.w3.org/2021/10/TPAC/demos/css-architecture.html and https://www.bram.us/2021/09/15/the-future-of-css-cascade-layers-css-at-l...)

If layers are available, it also mean no shadow dom necessary for things like #2195695: Admin UIs on the front-end are difficult to theme

wim leers’s picture

TIL cascade layers 😮

Not yet widely available though: https://caniuse.com/css-cascade-layers. Only next versions of Chrome, Firefox and Safari, i.e. 0.1% of today's browser usage 😬

nod_’s picture

In the current code the styles reset result change depending on aggregation being activated or not.

When CSS aggregation is ON, there are 0 rules ignored.

When CSS aggregation is OFF, 237 rules from those css files are ignored:

/core/misc/dialog/off-canvas.reset.css
/core/misc/dialog/off-canvas.base.css
/core/misc/dialog/off-canvas.css
/core/misc/dialog/off-canvas.theme.css
/core/misc/dialog/off-canvas.motion.css
/core/misc/dialog/off-canvas.button.css
/core/misc/dialog/off-canvas.form.css
/core/misc/dialog/off-canvas.table.css
/core/misc/dialog/off-canvas.details.css
/core/misc/dialog/off-canvas.tabledrag.css
/core/misc/dialog/off-canvas.dropbutton.css
/core/misc/dialog/off-canvas.layout.css
wim leers’s picture

I … am not sure I fully understand that. Are you saying you found a bug in HEAD?

nod_’s picture

Status: Active » Needs review

I guess, but it's not really important since the extra 200 rules generated will never match anything it turns #drupal-off-canvas * into #drupal-off-canvas [data-drupal-ck-style-fence] #drupal-off-canvas *.

Got a better solution using donut selectors: https://css-tricks.com/weekly-platform-news-focus-rings-donut-scope-ditc...

wim leers’s picture

Issue tags: +CSS, +JavaScript

You keep throwing new terms at me — donut selector this time 🤪

Also: wow, that looks super interesting.

I looked at the MR, and I think @bnjmnm would be a far better reviewer than I possibly could be. He has recent/prior experience in this area, I don't. To me, what jumps out, are coding standards nitpicks (incomplete JS docblocks).

nod_’s picture

Category: Task » Bug report

Also previous code seems like it doesn't work for rules inside media queries or rtl styles (that have [dir=rtl] #drupal-off-canvas for example)

wim leers’s picture

Priority: Normal » Major

That seems like a pretty significant bug.

Which begs the question … are we missing test coverage? 😬 (That sounds like no fun to write test coverage for, and I'm not sure it's worth it, but I have no choice but to ask.)

lauriii’s picture

StatusFileSize
new9.16 KB

I'm wondering if we should work on this here, but here's an example of something that should work. The link in this image should be rendered as blue according to CKEditor CSS. However, it is overridden by the off-canvas reset.

This is already broken but it's broken differently than after the patch. I'm wondering if we'd prefer to work on this here or should it be separate issue? I'm not sure what would be a better use case to test this.

nod_’s picture

For the tests it's the css that will be annoying to write. Should be easy enough overall though.

i do think we should at least find the cause of those issues and add a few comment in the code in this issue, even if we don't solve everything.

longwave’s picture

Does the "donut scope" selector work in IE11? We had issues with complex :not() before, see #2958588: Off-canvas style resets are overriding styles (especially SVGs) resulting in display issues and https://caniuse.com/css-not-sel-list

If it doesn't, this will have to be Drupal 10 only.

nod_’s picture

good question, not sure if [attr] * is considered a selector list (probably i'd say).

As far as core support goes, it's experimental in 9.4 so we might get away with it? no issue for D10 though, that's good. Can't be a generic solution but can be suitable for CKE depending on the answer to getting away with it in experimental

lauriii’s picture

We have to get CKEditor 5 stable in Drupal 9.4.0 to provide replacement for CKEditor 4 before Drupal 10 ships. However, since CKEditor 5 is not supporting IE 11 at all, we could ignore that aspect.

nod_’s picture

So during testing we can see that the previous code was working and it worked because of the increased specificity of the cke selectors

it turned .cke.cke-content into #drupal-off-canvas [data-drupal-ck-style-fence] .cke.cke-content making that rule apply above all the others. It also turns @media screen, print {} into #drupal-off-canvas [data-drupal-ck-style-fence] @media screen, #drupal-off-canvas [data-drupal-ck-style-fence] print {}, the rule is invalid and gets ignored so no harm. We could avoid the unnecessary work though.

With the patch the styles are not applied and there is nothing to override. It doesn't break media queries or nested media, supports declarations.

I don't have a failing test though.

nod_’s picture

Tests work locally with chrome 97 and in core we have chrome 87, which doesn't support the selector: https://caniuse.com/css-not-sel-list

wim leers’s picture

in core we have chrome 87

We should update core. Chrome 87 is from November 2020: https://developer.chrome.com/blog/new-in-chrome-87/.

Per https://caniuse.com/usage-table, a tiny fraction uses Chrome 87.

Also, per core/package.json:

  "browserslist": [
    "last 2 Chrome major versions",
    …

But, important to ask: which is the first version of Chrome that supports this selector?

nod_’s picture

version 88 :D

wim leers’s picture

That seems … reasonable :D

wim leers’s picture

Status: Needs review » Needs work

I think we need a follow-up issue that is postponed on #3258114: Upgrade Chromedriver (thanks for that!) to bring back the extra tests?

nod_’s picture

Status: Needs work » Needs review
wim leers’s picture

👍

I don't think I'm eligible to RTBC this, so keeping at Needs review — I've done all I can to push this one forward 😊

nod_’s picture

Added more comments. I'm really not sure how best to explain it :/ let me know if that helps.

lauriii’s picture

Issue summary: View changes
Status: Needs review » Needs work
StatusFileSize
new76.22 KB

It seems like the insert before and after styles would be broken by this change:

nod_’s picture

Status: Needs work » Needs review

one more thing that the script does, duplicate all .ck* css rules and prefix them with #drupal-off-canvas [data-drupal-ck-style-fence].

Before

.ck-content .table > figcaption {}
[dir="ltr"] .ck.ck-input-color .ck.ck-input-color__remove-color {}

After

.ck-content .table > figcaption, 
#drupal-off-canvas [data-drupal-ck-style-fence] .ck-content .table > figcaption {}

[dir="ltr"] .ck.ck-input-color .ck.ck-input-color__remove-color, 
[dir="ltr"] #drupal-off-canvas [data-drupal-ck-style-fence] .ck.ck-input-color .ck.ck-input-color__remove-color {}
lauriii’s picture

Status: Needs review » Reviewed & tested by the community

Made minor improvements to the docs. Other than that this is now working as expected and this is still an optimized version of the previous script since this doesn't require duplicating all CSS from the page.

wim leers’s picture

2 random fails in media tests — re-testing.

lauriii’s picture

StatusFileSize
new13.09 KB

Here's Drupal 10 patch of the MR.

bnjmnm made their first commit to this issue’s fork.

bnjmnm’s picture

Status: Reviewed & tested by the community » Needs work

Back to NW for docs-related things and to confirm one still-open @lauriii thread is addressed. Overall a very nice solution.

lauriii’s picture

Status: Needs work » Reviewed & tested by the community

I improved some of the documentation and confirmed that my feedback was addressed.

bnjmnm’s picture

Changes look good. Could we get a Drupal 10 patch of the current MR?

lauriii’s picture

StatusFileSize
new13.44 KB

  • bnjmnm committed b36a180 on 10.0.x
    Issue #3248469 by nod_, lauriii, Wim Leers, longwave: Research if the...
bnjmnm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 10.0.x, waiting for rebase to pass to merge MR to 9.4.x. Very elegant optimization!

  • bnjmnm committed 7a2f38e on 9.4.x authored by nod_
    Issue #3248469 by nod_, lauriii, Wim Leers, longwave: Research if the...
bnjmnm’s picture

bnjmnm’s picture

Version: 9.4.x-dev » 9.3.x-dev
Status: Fixed » Reviewed & tested by the community

This is probably a good candidate for 9.3 as CKEDitor 5 is experimental and the change is non disruptive. Will check with @lauriii before making it official, though.

wim leers’s picture

+1

  • bnjmnm committed 5291181 on 9.3.x authored by nod_
    Issue #3248469 by nod_, lauriii, Wim Leers, longwave: Research if the...
bnjmnm’s picture

Status: Reviewed & tested by the community » Fixed

Cherry picked to 9.3.x

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

murphyw’s picture

Issue tags: -JavaScript +JavaScript
StatusFileSize
new866 bytes