From 3fafdbc384ed076e333c47b6c025de0fa43875de Mon Sep 17 00:00:00 2001 From: mgsy Date: Thu, 16 Jan 2025 13:30:50 +0100 Subject: [PATCH] Fix: Prevent removing CDN assets while page has an active editor instance. --- admin/src/components/CKEditorProvider/index.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/admin/src/components/CKEditorProvider/index.js b/admin/src/components/CKEditorProvider/index.js index 7466704..1a582bb 100644 --- a/admin/src/components/CKEditorProvider/index.js +++ b/admin/src/components/CKEditorProvider/index.js @@ -17,8 +17,18 @@ const CKEditorProvider = ( { useEffect( () => { return () => { const assets = document.querySelectorAll( '[data-injected-by="ckeditor-integration"]' ); + const editables = document.querySelectorAll( '.ck-editor__editable_inline ' ); - assets.forEach( asset => asset.remove() ); + // 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; }