From c32c436c21b9be29833205d45761fc391dd11c9e Mon Sep 17 00:00:00 2001 From: mgsy Date: Thu, 16 Jan 2025 13:26:27 +0100 Subject: [PATCH] Fix: Prevent removing CDN assets while page has an active editor instance. --- admin/src/components/CKEditorProvider/index.jsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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; }