I'm using Backdrop v1.30.0 with CKEditor 5 Version: 44.1.0. All has been swell so far. Suddenly, changes I have made in the editor are not preserved after saving (other changes to other fields are saved). Additionally, nothing happens now if I hit the 'source' button. Earlier today, the word 'source' for the toolbar button was inexplicably replaced with 'expand.' When I clicked it, it changed to 'collapse,' but did not do anything and still did not switch to viewing the source. What might be causing CKEditor to misbehave? What can be done to fix it?

Comments

This may be a Javascript error (the fact that the source button doesn't work may be an indication of this). Can you check the browser's console after opening the edit form and after clicking Source, to see if there are any errors there?

Thanks. I don't spend much time in the console. Yes, there is an error message.

Upon loading the edit page:

js_haOE-8z_9l1RB9MIOEXtzZzmkzmhlCWLVrLD75ALoJ0.js:1827 The CKEditor instance could not be initialized.
(anonymous) @ js_haOE-8z_9l1RB9MIOEXtzZzmkzmhlCWLVrLD75ALoJ0.js:1827

js_haOE-8z_9l1RB9MIOEXtzZzmkzmhlCWLVrLD75ALoJ0.js:1828 CKEditorError: Cannot read properties of undefined (reading 'toString')
Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#erro... read properties of undefined (reading 'toString')
   at _getResizedWidthHeight (js_haOE-8z_9l1RB9MIOEXtzZzmkzmhlCWLVrLD75ALoJ0.js:461:24)
   at Ut.converter (js_haOE-8z_9l1RB9MIOEXtzZzmkzmhlCWLVrLD75ALoJ0.js:650:37)
   at Ut.fire (ckeditor5-dll.js?v=1.30.0:5:726731)
   at Ut._testAndFire (ckeditor5-dll.js?v=1.30.0:5:311810)
   at Ut._testAndFireAddAttributes (ckeditor5-dll.js?v=1.30.0:5:312023)
   at Object.convertAttributes (ckeditor5-dll.js?v=1.30.0:5:312329)
   at Ut.<anonymous> (ckeditor5-dll.js?v=1.30.0:5:342505)
   at Ut.fire (ckeditor5-dll.js?v=1.30.0:5:726731)
   at Ut._testAndFire (ckeditor5-dll.js?v=1.30.0:5:311810)
   at Ut._convertInsert (ckeditor5-dll.js?v=1.30.0:5:309903)
(anonymous) @ js_haOE-8z_9l1RB9MIOEXtzZzmkzmhlCWLVrLD75ALoJ0.js:1828

And upon clicking the source button, there are more error messages.

I used the new Chrome AI console 'understand this error' helper which provided the text in this document. It did give me a hint it might be something to do with an image. I am dealing with content that is being imported from a Drupal7 site and the issue does not affect other content.

It was the image. I deleted it and the problem went away. Whew. 

I'm experiencing the exact same issue. I have no idea what's causing the CKEditor to fail but my developper console is full of the same error messages that Chrys reported.

Essentially the changes no longer save and the "source" button no longer works. 

  • The CKEditor instance could not be initialized.
  • CKEditorError: Cannot read properties of undefined (reading 'toString')
    Read more: https://ckeditor.com/docs/ckeditor5/latest/support/error-codes.html#erro... read properties of undefined (reading 'toString')
       at _getResizedWidthHeight (js_HJeu4Otun4Y7IKkBjyXAShwISMO_5UTP6QMQVNIYIo8.js:461:24)
       at oo.converter (js_HJeu4Otun4Y7IKkBjyXAShwISMO_5UTP6QMQVNIYIo8.js:650:37)
       at oo.fire (ckeditor5-dll.js?v=1.31.0:5:775753)
       at oo._testAndFire (ckeditor5-dll.js?v=1.31.0:5:362895)
       at oo._testAndFireAddAttributes (ckeditor5-dll.js?v=1.31.0:5:363108)
       at Object.convertAttributes (ckeditor5-dll.js?v=1.31.0:5:363414)
       at oo.<anonymous> (ckeditor5-dll.js?v=1.31.0:5:393309)
       at oo.fire (ckeditor5-dll.js?v=1.31.0:5:775753)
       at oo._testAndFire (ckeditor5-dll.js?v=1.31.0:5:362895)
       at oo._convertInsert (ckeditor5-dll.js?v=1.31.0:5:360988)

I note from https://github.com/backdrop/backdrop-issues/issues/6904 that "DLL builds are sunsetting", which makes me wonder if there's a correlation there.

On top of that I'm having issues with the tarteaucitron library which means the GDPR Cookies module no longer works. It's giving me a 403 ERR_ABORTED error however the init_tarteaucitron doesn't display a permissions error but obviously since it relies on the main library it doesn't work either. I mention it here because both seem to be JavaScript errors so there's a chance they may be related somehow.

I note that the latest Backdrop core update included an update to the CKEditor so something there must have triggered an error. 

@chrys I'm curious if the image you were having an issue with contained a space in its name. I know it was over 6 months ago now so you might not remember but for my issue, the only thing I can think of that an HTML validator points out is the fact that I have a lot of links to documents which have a lot of spaces in their file name. 

This wasn't an issue with TinyMCE when the site was running Drupal but it seems CKEditor 5 doesn't like that for whatever reason.

Unless there's a magic settings tweak somewhere which would help?

This issue with CKEditor misbehaving, where changes don't save and the source button is broken, is almost always caused by a JavaScript error. A conflict with another script, a corrupted CKEditor file, or a misconfiguration can break the editor's functionality. The inexplicable text change from 'source' to 'expand' is a strong indicator of a script failing to load or execute properly. To fix this, first, clear both your browser and Backdrop caches. If the problem persists, check your browser's developer console for any red error messages; this is the most reliable way to pinpoint the exact cause. If you find a JavaScript error, it may point to a specific file or module causing the conflict. A full reinstallation of https://frlmodapk.com and the CKEditor library is often the final solution, as it ensures all files are fresh and uncorrupted.

I mean, yes it is a JavaScript error, see the error message in my post from 05 August above. And believe me, I've cleared my caches so often, they were squeaky clean

The problem is, it's only affecting one page. Other pages on the website work fine as far as I can tell (at least there's no JS error in the browser console). The problem is, I've reviewed the source code for that page and cannot see any empty src, href, alt or any other html tag attribute. All tags are closed properly and the code passes html validation so I'm confused as per what is causing the error now.

Now since CKEditor is embedded in Backdrop core now, I'm not sure how it would have gotten corrupted in the first place and if I replace it with the source from CKEditor directly, who's to say it won't get overridden again on the next Backdrop update?

jeanloup_sasa, it looks like the error is not happening in CKEditor itself, but in JS function _getResizedWidthHeight(), which is part of the backdrop-image.js file, a CKE plugin provided by Backdrop to deal with image resizing. That function in the plugin was modified 2 years ago.

This leads me to believe that your problem is not Javascript, but the actual body field you are trying to modify. The problem seems to be related with either null, undefined, or faulty value for either height, width, or the parameter resizeWidth that the function receives.

It's impossible to know which of the 3 parameters is fault, since the error you pasted did not contain a line number for the originating error (only for the rest of the call stack).

My suggestion to you is for you to get the HTML code for the Body field directly, and inspect if there is an issue with an image width or height.  You can do that by enabling Devel, and running something like the following:

dpm(node_load(NID));

Replace NID by the node ID of the problematic content. Then find the "body" field and expand it to show its content. Copy and paste here if you wish.

If the page is public, it would be helpful for you to post the full URL so I can take a look and check if I see a malformed image tag somewhere. 

Ultimately, you may need to recreate that page from scratch. This may be a bug, but from your information it's unclear where or why it's happening.

 

 

Yes the page is public, you can view it at https://www.sasa.gov.uk/covid-19-guidance/seasonal-agricultural-workers. The relevant code if you view the source is between lines 123 and line 385.

I've reviewed all instances of "width" and "height" in that section of code and nothing immediately jumps at me. Some widths are set relatively (100%), others absolutely (150px) but I wouldn't have thought this would cause an issue.

I could try to delete pictures one at a time but givenchanges aren't being saved, I'm not sure that would work. If I disable the CKEditor I can work with the source directly but given it doesn't like any code formatting, it's a bit challenging to try anything.

In the end I will likely have to rebuild the page from scratch on our dev environment and hopefully the culprit will become more obvious.

Jeanloup, I was able to reproduce the issue here. It looks like the Backdrop's image plugin cannot handle the image's width value when it's inside a style attribute in the image.

You must have pasted the HTML img code directly into source. That  created the problem. Now you can't really do any editing through the UI.

There are two alternatives. You can view the Source of the page as is, copy the chunk for each node's body, and manually remove the width: 100%;, then recreate the pages manually.

You could also edit the database directly, but that's a bit trickier. You'd need to look for table field_data_body, then find the node ID under the column entity_id then get the value of body_value for that particular row, remove all the width: 100% or witdth: 150px; (which also causes problems), and  then save the row. 

In the end, this may be a bug: JS errors as soon as I paste an <img> element that contains width within the style attributed as Source, and then switch to the WYSIWYG.

You may want to open an issue.

You're correct, most of that page was edited outside the editor but I believe there was no issue when that page ran in Drupal 7 with TinyMCE. I'm not sure why this causes an issue with CKEditor.

Would that be an issue to raise with CKEditor themselves or Backdrop?

Thanks for looking into it. I'll convert the style="width: 100%;" to just width="100%". Hopefully it'll be happier with that. I also have it defined in <div>s but I'll just edit the <img> first and we'll see if it's happy after that.

TinyMCE is a completely different animal. You can use that instead of CKEditor in BAckdrop. TinyMCE is a contrib module actively maintained.

I might try that first then, that might save me some time. Thanks

Ok switching to TinyMCE worked. I think we'll just stick to that for the time being then.

Now to figure out what's happening with tarteaucitron.js... different issue

And yes, you could disable CKEDitor temporarily, edit those nodes, remove the width definitions, save, and then enable CKEditor.

You can try deleting any images in the page one by one, saving the node, and reopening to find the faulty image.