0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00

Added guards for missing codemirror elements when destroying markdown cards

no issue

- if a markdown card is created and destroyed before the simplemde+codemirror instance is fully initialised we could throw errors due to simplemde calling methods on objects that don't yet exist during teardown
- we also had issues with the `_applyToolbarStyles()` method being called async by event handlers after the component was destroyed
This commit is contained in:
Kevin Ansfield 2022-05-24 13:12:11 +01:00
parent 1ca5b43fcb
commit 94c192041d
2 changed files with 8 additions and 2 deletions

View file

@ -72,7 +72,9 @@ export default class GhSimplemde extends TextArea {
}
willDestroyElement() {
this._editor.toTextArea();
if (this._editor?.codemirror) {
this._editor.toTextArea();
}
delete this._editor;
super.willDestroyElement(...arguments);
}

View file

@ -154,7 +154,11 @@ export default class KoenigCardMarkdown extends Component {
}
_applyToolbarStyles() {
let toolbar = this.element.querySelector('.editor-toolbar');
if (this.isDestroyed || this.isDestroying) {
return;
}
let toolbar = this.element?.querySelector('.editor-toolbar');
if (!toolbar) {
return;