Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
We have enabled CKEditor 5 on some of our websites and the CLS score of the websites dropped drastically.
Upon inspecting, CKEditor 4 set fixed width and height attributes of the images, reducing the content layout shift drastically.
Looking at CKE5, it seems most images don't get dimensions set at all, while some only get width set.
Proposed resolution
Make CKE5 also generate width and height HTML tags: https://github.com/ckeditor/ckeditor5/issues/5154.
Comments
Comment #2
cilefen CreditAttribution: cilefen commentedComment #3
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedComment #4
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedThis may be related to those CKEditor issues:
Comment #5
Wim LeersDiscussed this, #3336445: [drupalImage] Caption images filter incompatible with CKEditor 5 image resizing and #3336446: EditorFileReference should compute a px <img height> if a % <img width> is specified, even though % <img width> is not allowed in HTML5 in detail with Piotrek from CKEditor 5.
He acknowledges this is a long-standing problem, but it's extremely difficult to change this, because it'd cause a support nightmare (unlike Drupal, CKEditor does not have a way to store state about the system, so keeping existing sites on the old behavior and new sites on the new behavior, to allow existing sites to opt in to the new behavior).
We analyzed together how it worked in CKEditor 4, and there indeed A) images always get
width
andheight
in pixels and B) the image resizing changes that width and height, C) resetting to the original uses the loaded image to re-compute thewidth
andheight
.The path forward for this is unclear, but it is being worked on this quarter. Crucially, there was a very good reason to change from the px-based behavior in CKEditor 4 to the absence of px by default and presence of %-width only upon resizing … but that reason was not documented. So the CKEditor 5 team needs to do research to figure out a way forward.
P.S.: enable the
editor_file_reference
aka filter, that will generate the necessarywidth
andheight
… although that is currently broken in some cases due to a recent regression: #3336446: EditorFileReference should compute a px <img height> if a % <img width> is specified, even though % <img width> is not allowed in HTML5.Comment #6
Wim LeersUpstream issue: https://github.com/ckeditor/ckeditor5/issues/5154.
Comment #8
Wim LeersDiscussed this with @Reinmar from CKEditor 5!
This bug has also been frequently reported by other CKEditor 5 users; it's already scheduled to be fixed in the coming months! 👍
However, it is a very complex undertaking for CKEditor 5 to modify this behavior: there are significant backwards compatibility implications for them.
Comment #10
Wim LeersUpdate from @witeksocha: he's started investigating both the bugs the Drupal community reported as well as all related aspects. So there'll be news on this topic soon-ish probably 😊
Comment #11
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedProgress on this can be monitored here: https://github.com/ckeditor/ckeditor5/issues/14146
Comment #12
Wim LeersFYI: the related CKEditor 4 issue for Drupal core: #2092871: width and height attributes are empty when inserting an image.
In last week's meeting with the CKEditor 5 developers, I was told that this is ready to be merged upstream (visible in https://github.com/ckeditor/ckeditor5/issues/14146 because it says "10/10 tasks done" 👍), but it will NOT ship in the September release.
They're aiming to make the September release a minor/patch release with no major breaking changes. Fixing this bug upstream is effectively a major breaking change for most of CKEditor 5's integrators, but not for Drupal.
That's why this will ship in the October release 👍
Comment #13
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedCKEditor fixed the issue https://github.com/ckeditor/ckeditor5/issues/14146 and https://github.com/ckeditor/ckeditor5/issues/5154
Comment #14
KlemenDEV CreditAttribution: KlemenDEV as a volunteer and at Pylo commentedComment #15
Wim LeersThe test coverage changes in #3393557: [upstream] Update CKEditor 5 to 40.0.0 prove that the update to CKEditor 5 v40.0.0 fixes this. I will mark this as soon as #3393557 lands.
Comment #16
Wim Leers#3393557: [upstream] Update CKEditor 5 to 40.0.0 landed. 🚢