Skip to content

Commit

Permalink
Fix: Prevent removing CDN assets while page has an active editor inst…
Browse files Browse the repository at this point in the history
…ance.
  • Loading branch information
Mgsy authored Jan 20, 2025
1 parent bbe30ba commit bfcaba0
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion admin/src/components/CKEditorProvider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit bfcaba0

Please sign in to comment.