Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Ran in to an issue where I was getting a JavaScript error stating the CKEditor instance already exists. This patch fixes the issue by destroying the instance if it already exists before trying to replace it.
Comment | File | Size | Author |
---|---|---|---|
#4 | 0001-1663462-by-dczepierga-Destroy-existing-instance-when.patch | 1.21 KB | dczepierga |
ckeditor-instance-already-exists.diff | 253 bytes | greenSkin | |
Comments
Comment #1
mkesicki CreditAttribution: mkesicki commentedThank you for your patch. We will check this as soon as possible.
Please be patient.
Comment #2
dczepierga CreditAttribution: dczepierga commented@greenSkin, could u write how to reproduce this?
Greetings
Comment #3
greenSkin CreditAttribution: greenSkin commentedThe steps to reproduce can be a little tricky as it is AJAX related. Basically you load the page either with the textarea loaded on page load or via an AJAX callback; no problems, everything works fine. The issue comes when you remove that textarea and replace it with the same one. The CKEditor doesn't know it was replaced so when the behaviors tries to initialize the new editor it errors that it already exists.
The simplest of fix is what the patch attempts, to destroy any pre-existing editor before trying to initialize it again.
Hope that helps. :)
Comment #4
dczepierga CreditAttribution: dczepierga commented@greenSkin, could u try review my patch? It will be better to destroy CKEditor by textarea_id - if it will be more CKEditor instances in one page u will destroy last one replaced - not selected in that moment...
Greetings
Comment #5
greenSkin CreditAttribution: greenSkin commented@dczepierga: Yes, that works wonderfully. Thank you!
Comment #6
dczepierga CreditAttribution: dczepierga commentedChanges commited to GIT (diff)
Thx for help and review patch.
Greetings
Comment #8
mkesicki CreditAttribution: mkesicki commentedComment #9
alsammanKhaled CreditAttribution: alsammanKhaled commentedI am not sure if this is related or not but i am using drupal 9 and i am having a smiliar issue. when i add my ckeditor using js and remove the old one it would give this error "ckeditor.js?v=4.17.1:350 Uncaught TypeError: Cannot read properties of null (reading 'unselectable')"
when inspecting the element the ckeditor is not rendered. however without js it would render everything. I end up with a textfield element that is empty whe i use my js. is this related to here or should i make an issue or search somethinge different? any guidance is appreciated.