Problem/Motivation

When image is resized in CKEditor 4, both height and width attributes are added. The attributes persist if the text format is upgraded to use CKEditor 5. Now if user resizes the image, the width attribute is converted to use percentages. In this process, the height is left untouched which may lead into the image rendering with incorrect proportions in some browsers.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3336446

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

Title: height attribute is not removed when image is resized in CKEditor 5 » [upstream] height attribute is not removed when image is resized in CKEditor 5
Issue summary: View changes
Status: Active » Postponed
Issue tags: +JavaScript, +Needs upstream bugfix

AFAICT that'd be an upstream bug in ckeditor5-image's ImageResize plugin?

https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-ima... indeed seems to have zero handling for height

Yep, https://github.com/ckeditor/ckeditor5/issues/5154 specifically covers this.

wim leers’s picture

Title: [upstream] height attribute is not removed when image is resized in CKEditor 5 » EditorFileReference should compute a px <img height> if a % <img width> is specified, even though % <img width> is not allowed in HTML5
Component: ckeditor5.module » filter.module
Issue summary: View changes
Status: Postponed » Needs review
Issue tags: -JavaScript, -Needs upstream bugfix
Related issues: +#3167034: Leverage the 'loading' html attribute to enable lazy-load by default for images in Drupal core

This is actually caused by \Drupal\editor\Plugin\Filter\EditorFileReference::process(). It blindly computes height and width if either one is not set, by inspecting the referenced file. But … it does not take into account that a % value could be set on either one.

Even though that is technically not valid in HTML 5 (see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Img#attr-width), it was historically allowed so we should cater for that too (https://en.wikipedia.org/wiki/Robustness_principle).

This bug was introduced in #3167034: Leverage the 'loading' html attribute to enable lazy-load by default for images in Drupal core.

wim leers’s picture

StatusFileSize
new1.76 KB
new2.93 KB

The last submitted patch, 4: 3336446-4-test-only-FAIL.patch, failed testing. View results

frega’s picture

Assigned: Unassigned » frega
Status: Needs review » Needs work

Assigning this to me, to reroll patch.

frega’s picture

StatusFileSize
new1.62 KB

Rerolled as MR.

Adjusted `3336446-4-test-only-FAIL.patch` to reflect removal of `loading="lazy"` attributes in this filter (@see https://git.drupalcode.org/project/drupal/-/commit/a266ba6e).

frega’s picture

Assigned: frega » Unassigned
Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: 3336446-7-test-only-FAIL-rerolled.patch, failed testing. View results

frega’s picture

Status: Needs work » Needs review

Setting back to needs review, as the last patch should _fail_ (rerolled test-only patch).

wim leers’s picture

Thanks @frega! (Also: long time no see! Hope you're well! 😊)

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs issue summary update

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Think looks interesting. Could the issue summary be updated with proposed solution and steps to reproduce please. Also this will keep failing as the test only patch was the last uploaded. Actually surprised to see it survived the review bot.

wim leers’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

wim leers’s picture

#3348603: CKEditor 5 resizes images with % width instead of px width (the CKEditor 4 default): breaks image captions *and* is a regression landed. Upon re-editing content with CKEditor 5 and re-saving it, CKEditor 5 will convert the % width to pixels instead.

That makes this a fix for a fairly obscure problem. Except that all resized images created with CKEditor 5 so far on all Drupal >=9.5 sites would definitely benefit from this.

So keeping the same priority.

wmcmillian’s picture

StatusFileSize
new2.72 KB

re-rolled #4 for 10.2.x

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.