Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent removing CDN assets while page has an active editor instance (v5) #144

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions admin/src/components/CKEditorProvider/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading