Skip to content

Commit

Permalink
Merge 859e380 into 982b37d
Browse files Browse the repository at this point in the history
  • Loading branch information
corymharper committed Nov 10, 2022
2 parents 982b37d + 859e380 commit 7822fa2
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/ckeditor.jsx
Expand Up @@ -18,6 +18,14 @@ export default class CKEditor extends React.Component {
constructor( props ) {
super( props );

/**
* While cleanup from unmounting is in progress, contains a promise that resolves when cleanup is complete.
* Otherwise it contains null.
*
* @type {Promise|null}
*/
this.cleanupInProgress = null;

// After mounting the editor, the variable will contain a reference to the created editor.
// @see: https://ckeditor.com/docs/ckeditor5/latest/api/module_core_editor_editor-Editor.html
this.domContainer = React.createRef();
Expand Down Expand Up @@ -115,7 +123,13 @@ export default class CKEditor extends React.Component {
* @returns {Promise}
*/
async componentWillUnmount() {
await this._destroyEditor();
this.cleanupInProgress = new Promise( resolve => {
this._destroyEditor().then( () => {
resolve();
} );
} ).then( () => {
this.cleanupInProgress = null;
} );
}

/**
Expand All @@ -136,6 +150,10 @@ export default class CKEditor extends React.Component {
* @returns {Promise}
*/
async _initializeEditor() {
if ( this.cleanupInProgress ) {
await this.cleanupInProgress;
}

if ( this.watchdog ) {
return;
}
Expand Down

0 comments on commit 7822fa2

Please sign in to comment.