Skip to content

Commit

Permalink
Make sure that the watchdog instance exists before destroying itself.
Browse files Browse the repository at this point in the history
  • Loading branch information
pomek committed Mar 8, 2021
1 parent 100f285 commit 896b569
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/ckeditor.jsx
Expand Up @@ -74,7 +74,7 @@ export default class CKEditor extends React.Component {

// Destroy the editor before unmouting the component.
componentWillUnmount() {
this._destroyEditor();
return this._destroyEditor();
}

// Render a <div> element which will be replaced by CKEditor.
Expand Down Expand Up @@ -157,10 +157,19 @@ export default class CKEditor extends React.Component {

/**
* Destroys the editor by destroying the watchdog.
*
* @returns {Promise}
*/
_destroyEditor() {
this.watchdog.destroy();
this.watchdog = null;
// It may happen during the tests that the watchdog instance is not assigned before destroying itself. See: #197.
if ( !this.watchdog ) {
return Promise.resolve();
}

return this.watchdog.destroy()
.then( () => {
this.watchdog = null;
} );
}

/**
Expand Down

0 comments on commit 896b569

Please sign in to comment.