Problem/Motivation

Hi,
My site was working perfectly well with Drupal 10.3 and CKEditor 5
After updating the site to Drupal 10.4 the entire site still works fine but when I edit existing content the CKEditor Wysiwyg editor no longer loads. The error in the console is: (Also attached a screenshot)

Uncaught TypeError: Cannot read properties of undefined (reading 'attach')
at Object.editorAttach (editor.js?v=10.4.0:304:37)
at editor.js?v=10.4.0:228:18
at Array.forEach ()
at Object.attach (editor.js?v=10.4.0:211:52)
at drupal.js?v=10.4.0:166:24
at Array.forEach ()
at Drupal.attachBehaviors (drupal.js?v=10.4.0:162:34)
at big_pipe.js?v=10.4.0:153:10
at big_pipe.js?v=10.4.0:184:3

When I add new content the editor is loaded initially but when I want to edit that content or other content the editor does not load.

I have uninstalled the CKEDitor and re-installed and reassigned it to the text format. Did not help
I cleared my cache in case javascript files were cached. Did not help.

So I'm stuck and hope someone can help.

#3294720: The attachBehaviors() for document is only called after Big Pipe chunks are processed
#3467860: Ensure consistent ordering when calculating library asset order

Steps to reproduce

Given that a Drupal 10 site was installed with the minimal profile ( not the standard profile )
And later on the BigPipe and CKEditor5, Tour modules were installed
Then the wight of the BigPipe JavaScript library will affect the CKEditor 5, Tour, Maybe other modules.

Big Pipe is attempting to attach behaviors too early, and it’s affecting the Tour module as well.

Proposed resolution

  • Find a better way to Attach behaviors in Big Pipe
  • Add header: true to the drupal/big_pipe library.
  • Switch to use a custom domReady in the BigPipe script to let work as Drupal init to Attach behaviors early, if possible without errors
  • Suggestion for further improvement: Have advanced config settings for BigPipe:
    • Limit to selected themes - Example: only load in the front-end themes.
    • Limit by user role - Example: only autonomous users.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3496329

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

robbnl created an issue. See original summary.

rajab natshah’s picture

Facing the same issue

cilefen’s picture

Category: Support request » Bug report
Priority: Normal » Major

Are any CKEditor plugin modules installed on affected sites?

rajab natshah’s picture

When I disable the BigPipe module, the issue disappears.

catch’s picture

I can't reproduce this with the standard profile (ckeditor5 and big_pipe installed).

Can you try the following:

1. See if you can reproduce it on a clean install of Drupal 10.4 with only core.

2. As @cilefen says check if you have any ckeditor plugin modules installed and if so let us know which ones.

The most likely cause of this is #3467860: Ensure consistent ordering when calculating library asset order interacting badly with a (usually incorrect) contrib library definition. So a third step would be checking contrib library definitions to see if they specify weight for any files.

robbnl’s picture

Hi,
Thanks for the responses. I don't have time the next few days to check this on a fresh install of 10.4.
What I can say is that for me also if I uninstall the bigpipe module I no longer have this problem and I can again use the editor.

I do not have any extra CKeditor plugins installed on this site

rajab natshah’s picture

#3294720: The attachBehaviors() for document is only called after Big Pipe chunks are processed
#3467860: Ensure consistent ordering when calculating library asset order

Big Pipe is attempting to attach behaviors too early, and it’s affecting the Tour module as well.

  // Attach behaviors early, if possible.
  Drupal.attachBehaviors(document);

rajab natshah’s picture

Having a look at the logic in drupal.init.js file

// Allow other JavaScript libraries to use $.
if (window.jQuery) {
  jQuery.noConflict();
}

// Class indicating that JS is enabled; used for styling purpose.
document.documentElement.className += ' js';

// JavaScript should be made compatible with libraries other than jQuery by
// wrapping it in an anonymous closure.
(function (Drupal, drupalSettings) {
  /**
   * Calls callback when document ready.
   *
   * @param {function} callback
   *   The function to be called on document ready.
   */
  const domReady = (callback) => {
    const listener = () => {
      callback();
      document.removeEventListener('DOMContentLoaded', listener);
    };
    if (document.readyState !== 'loading') {
      setTimeout(callback, 0);
    } else {
      document.addEventListener('DOMContentLoaded', listener);
    }
  };

  // Attach all behaviors.
  domReady(() => {
    Drupal.attachBehaviors(document, drupalSettings);
  });
})(Drupal, window.drupalSettings);

Defines a behavior to be run during attach and detach phases.
Attaches all registered behaviors to a page element.
in the drupal.js file

  Drupal.attachBehaviors = function (context, settings) {
    context = context || document;
    settings = settings || drupalSettings;
    const behaviors = Drupal.behaviors;
    // Execute all of them.
    Object.keys(behaviors || {}).forEach((i) => {
      if (typeof behaviors[i].attach === 'function') {
        // Don't stop the execution of behaviors in case of an error.
        try {
          behaviors[i].attach(context, settings);
        } catch (e) {
          Drupal.throwError(e);
        }
      }
    });
  };
rajab natshah’s picture

Title: CKEditor stops loading on existing content after Drupal update to 10.4 » CKEditor 5 and Tour stopped loading on existing content after updating Drupal to 10.4
rajab natshah’s picture

Given that a Drupal 10 site was installed with the minimal profile ( not the standard profile )
And later on the BigPipe and CKEditor5, Tour modules were installed
Then the wight of the BigPipe JavaScript library will affect the CKEditor 5, Tour, Maybe other modules.

rajab natshah’s picture

Issue summary: View changes
Status: Active » Needs work
rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

Title: CKEditor 5 and Tour stopped loading on existing content after updating Drupal to 10.4 » Fix not loading CKEditor 5 and Tour on existing content after Drupal 10.4 update
Issue summary: View changes
rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

Assigned: Unassigned » rajab natshah
Status: Needs work » Active

rajab natshah changed the visibility of the branch 3496329-fix-10-4-x to hidden.

rajab natshah’s picture

Assigned: rajab natshah » Unassigned
Status: Active » Needs review

rajab natshah’s picture

Issue summary: View changes
rajab natshah’s picture

Attached a static drupal-core--2024-12-31--3496329--mr-10753.patch file for the 10.4.x to this point from MR10753.
To be used with the Composer Patches

smustgrave’s picture

Version: 10.4.x-dev » 11.x-dev
Status: Needs review » Needs work

Possible to get a test case showing the issue.

rajab natshah’s picture

Faced another issue when adding header: true to the drupal/big_pipe library.
The status message no longer appears on the site.

rajab natshah’s picture

Component: ckeditor5.module » big_pipe.module
rajab natshah’s picture

Issue summary: View changes

Switched to use a custom domReady in the BigPipe script to let work as Drupal init to Attach behaviors early, if possible without errors

rajab natshah’s picture

Title: Fix not loading CKEditor 5 and Tour on existing content after Drupal 10.4 update » Fix not loading CKEditor 5 and Tour with BigPipe enabled after Drupal 10.4 update
rajab natshah’s picture

Title: Fix not loading CKEditor 5 and Tour with BigPipe enabled after Drupal 10.4 update » Fix not loading CKEditor 5 and Tour with BigPipe enabled after Drupal 10.4 update
rajab natshah’s picture

rajab natshah’s picture

rajab natshah’s picture

Ops, uploaded the wrong static file name.

rajab natshah’s picture

rajab natshah’s picture

Attached a static drupal-core--2025-01-02--3496329-32--mr-10753.patch file for the 10.4.x to this point from MR10753.
To be used with Composer Patches

rajab natshah’s picture

Issue summary: View changes
jaroslav červený’s picture

catch’s picture

mr.pomelov’s picture

Drupal 10.4.1. Patch #33 work for me

ericdsd’s picture

Patch #33 works perfectly on core 10.4.5, is there still a reason to to keep Needs work status?

catch’s picture

header: true means that big pipe will load a large amount of render blocking javascript, is that absolutely necessary to the fix here?

Ideally would come with test coverage but it might not be possible to reproduce consistently in a test?

jstoller’s picture

I experienced this issue when using ACE Code Editor along with CKEditor5 on Drupal 11.2.2, and MR !10754 fixes it.

arnabcse2013’s picture

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

Thank you @Rajab for the MR.

Infact in my opinion I agree with @catch to not use the "header: true" as that will use a huge amount of render for javascript. This way we are just forcing the script to load in the header just to satisfy(May be a temp solution).

FYI, the "collapsible_dnd" module is also impacted and it is not rendering the "draggable collapser" correctly.
https://www.drupal.org/project/collapsible_dnd/issues/3497645 -> The above patch from @Rajab for D10.4.x fixes the issue but creates additional errors in big_pipe.js in console and also stops showing the drupal msgs (I will try to some screenshots here).

I am working to find some solution and will update in both the places.

catch’s picture

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

Changes always go into the development branch first.

cb_govcms’s picture

Have also experienced this where Big Pipe is affecting the loading of libraries in Claro: #3506870: Tabledrag misalignment and "Show row weights" link

rajab natshah’s picture

Version: 11.x-dev » main
pixelpreview@gmail.com’s picture

Thanks patch #33 works for drupal 10.6.7 too :)