diff --git a/admin/src/components/CKEditorProvider/index.jsx b/admin/src/components/CKEditorProvider/index.jsx index 1e600b3..84b4290 100644 --- a/admin/src/components/CKEditorProvider/index.jsx +++ b/admin/src/components/CKEditorProvider/index.jsx @@ -15,8 +15,18 @@ const CKEditorProvider = ( { useEffect( () => { return () => { const assets = document.querySelectorAll( '[data-injected-by="ckeditor-integration"]' ); - - assets.forEach( asset => asset.remove() ); + const editables = document.querySelectorAll( '.ck-editor__editable_inline ' ); + + // Editors might be nested in repeated components, which are collapsable. + // In this case, expanding another component will collapse the previous one, + // and for a short period of time there will be two active instances. After the first instance is + // collapsed, CDN assets will be removed, which will break the second instance. + // To prevent that, let's check whether there is an active editor on the page, before removing assets. + // + // See: https://github.com/ckeditor/strapi-plugin-ckeditor/issues/143 + if ( !editables.length ) { + assets.forEach( asset => asset.remove() ); + } window.CKEDITOR_VERSION = null; }