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

KlemenDEV created an issue. See original summary.

cilefen’s picture

Version: 9.4.x-dev » 9.5.x-dev
KlemenDEV’s picture

Title: CKEditor 5 breaks website CLS » CKEditor 5 breaks website CLS (no image width and height attributes)
KlemenDEV’s picture

Wim Leers’s picture

Title: CKEditor 5 breaks website CLS (no image width and height attributes) » [upstream] CKEditor 5 breaks website CLS (no image width and height attributes)
Priority: Normal » Major
Issue tags: +Needs upstream bugfix, +front-end performance
Related issues: +#3336445: [drupalImage] Caption images filter incompatible with CKEditor 5 image resizing, +#3336446: EditorFileReference should compute a px <img height> if a % <img width> is specified, even though % <img width> is not allowed in HTML5

Discussed 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 and height in pixels and B) the image resizing changes that width and height, C) resetting to the original uses the loaded image to re-compute the width and height.

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 Track images uploaded via a Text Editor filter, that will generate the necessary width and height … 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.

Wim Leers’s picture

Wim Leers credited Reinmar.

Wim Leers’s picture

Discussed 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.

Wim Leers’s picture

Update 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 😊

KlemenDEV’s picture

Progress on this can be monitored here: https://github.com/ckeditor/ckeditor5/issues/14146

Wim Leers’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Active » Postponed
Parent issue: » #3340578: [meta] [upstream] Prioritized CKEditor 5 upstream blockers
Related issues: +#2092871: width and height attributes are empty when inserting an image

FYI: 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 👍

KlemenDEV’s picture

KlemenDEV’s picture

Status: Postponed » Needs work
Wim Leers’s picture

Status: Needs work » Postponed

The 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 Fixed as soon as #3393557 lands.

Wim Leers’s picture

Status: Postponed » Fixed

Status: Fixed » Closed (fixed)

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