Skip to content

Commit 3d30a2d

Browse files
authored
Fix: Prevent removing CDN assets while page has an active editor instance.
1 parent 5a3276c commit 3d30a2d

File tree

1 file changed

+12
-2
lines changed
  • admin/src/components/CKEditorProvider

1 file changed

+12
-2
lines changed

admin/src/components/CKEditorProvider/index.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,18 @@ const CKEditorProvider = ( {
1515
useEffect( () => {
1616
return () => {
1717
const assets = document.querySelectorAll( '[data-injected-by="ckeditor-integration"]' );
18-
19-
assets.forEach( asset => asset.remove() );
18+
const editables = document.querySelectorAll( '.ck-editor__editable_inline ' );
19+
20+
// Editors might be nested in repeated components, which are collapsable.
21+
// In this case, expanding another component will collapse the previous one,
22+
// and for a short period of time there will be two active instances. After the first instance is
23+
// collapsed, CDN assets will be removed, which will break the second instance.
24+
// To prevent that, let's check whether there is an active editor on the page, before removing assets.
25+
//
26+
// See: https://github.com/ckeditor/strapi-plugin-ckeditor/issues/143
27+
if ( !editables.length ) {
28+
assets.forEach( asset => asset.remove() );
29+
}
2030

2131
window.CKEDITOR_VERSION = null;
2232
}

0 commit comments

Comments
 (0)