Problem/Motivation

CKEditor breaks when you are uploading an image but try to save image upload dialog before the image has finished uploading. This happened in both 8.9.x and 9.1.x as well.

Steps to reproduce

- Install fresh new Drupal
- Go to new article creation page
- Click the "image upload icon"
- When the image upload dialog box appears, upload a large sized image that takes many seconds to upload
- While the image is still being uploaded, hit "save" on the dialog box
- Wait until the ajax request for the image upload is completed
- After the image upload xhr request has finished, it should break the underlying CKEditor
- Demo: https://www.loom.com/share/2c8559820a274f11a4bd31cbfbb9625f

What behavior were you expecting?

- CKEditor should keep working
- Error should be visible as now

What happened instead?

- CKEditor disappeared once image upload xhr was completed

Comments

gupta324 created an issue. See original summary.

lihsus’s picture

Issue summary: View changes
codersukanta’s picture

StatusFileSize
new3.71 KB

I have gone through the issue and found that the code snipped from function detach(context, settings, trigger) in core/modules/editor/js/editor.js is causing the issue.

   editors.each(function () {
        var $this = $(this);
        var activeFormatID = $this.val();
        var field = findFieldForFormatSelector($this);

        if (field && activeFormatID in settings.editor.formats) {
         <strong> Drupal.editorDetach(field, settings.editor.formats[activeFormatID], trigger);</strong>
        }
      });

Where I can see the whole #documents value is passed as a context argument.

Basically the argument context is replaced by #document if the context value passed to Drupal.detachBehaviors is empty in drupal.js.

I have tried to fix it but I am bit doubtful whether removing context = context || document; will break anything else or not.

Please review and suggest.

codersukanta’s picture

Status: Active » Needs review

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

abhijith s’s picture

Patch #3 failed to apply in 9.2.x

Checking patch core/misc/active-link.es6.js...
error: while searching for:
      selectors = selectors.map(current => current + querySelector);

      // Query the DOM.
      const activeLinks = context.querySelectorAll(selectors.join(','));
      const il = activeLinks.length;
      for (let i = 0; i < il; i++) {
        activeLinks[i].classList.add('is-active');
      }
    },
    detach(context, settings, trigger) {
      if (trigger === 'unload') {
        const activeLinks = context.querySelectorAll(
          '[data-drupal-link-system-path].is-active',
        );
        const il = activeLinks.length;
        for (let i = 0; i < il; i++) {
          activeLinks[i].classList.remove('is-active');
        }
      }
    },

error: patch failed: core/misc/active-link.es6.js:51
error: core/misc/active-link.es6.js: patch does not apply
Checking patch core/misc/active-link.js...
Checking patch core/misc/drupal.es6.js...
error: while searching for:
   * @see Drupal.attachBehaviors
   */
  Drupal.detachBehaviors = function(context, settings, trigger) {
    context = context || document;
    settings = settings || drupalSettings;
    trigger = trigger || 'unload';
    const behaviors = Drupal.behaviors;

error: patch failed: core/misc/drupal.es6.js:206
error: core/misc/drupal.es6.js: patch does not apply
Checking patch core/misc/drupal.js...
abhijith s’s picture

Status: Needs review » Needs work
anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new3.72 KB

Re-rolled #3 for 9.2.x

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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.

gauravvvv’s picture

StatusFileSize
new3.69 KB
new861 bytes

Re-rolled patch #8, for drupal9.4. Attached interdiff for same.

ranjith_kumar_k_u’s picture

StatusFileSize
new3.7 KB
new755 bytes

Fixed CS error.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Project: Drupal core » CKEditor 4 - WYSIWYG HTML editor
Version: 9.5.x-dev » 1.0.x-dev
Component: ckeditor.module » Code

CKEditor has been removed from core, CKEditor 4 is removed from Drupal Core in 10.0.0

leeomara’s picture

StatusFileSize
new3.72 KB

I wasn't able to get the patch from #12 to apply on Drupal 9.5 (would fail to patch core/misc/active-link.js). I suspect the whitespace changes from https://git.drupalcode.org/project/drupal/-/commit/77e12397f5dd5e0a49ed1... are the issue.

I've attempted to re-roll the patch from #12 against the Drupal core 9.5.x branch. This patch does apply for me on 9.5.9, though I'm a novice at this, so please check my work.