From 939fc3d93ab67d54b7fe67b64c423290b3a40df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 28 May 2021 12:14:12 +0200 Subject: [PATCH] fix: prevent bug when editor is destroyed very fast --- packages/core/src/Editor.ts | 5 ++++- packages/vue-2/src/EditorContent.ts | 4 ++++ packages/vue-3/src/EditorContent.ts | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/core/src/Editor.ts b/packages/core/src/Editor.ts index 988ec3ec..fc15f69d 100644 --- a/packages/core/src/Editor.ts +++ b/packages/core/src/Editor.ts @@ -87,10 +87,13 @@ export class Editor extends EventEmitter { this.on('destroy', this.options.onDestroy) window.setTimeout(() => { + if (this.isDestroyed) { + return + } + this.commands.focus(this.options.autofocus) this.emit('create', { editor: this }) }, 0) - } /** diff --git a/packages/vue-2/src/EditorContent.ts b/packages/vue-2/src/EditorContent.ts index e8f6db77..21144fb0 100644 --- a/packages/vue-2/src/EditorContent.ts +++ b/packages/vue-2/src/EditorContent.ts @@ -48,6 +48,10 @@ export const EditorContent: Component = { beforeDestroy(this: EditorContentInterface) { const { editor } = this + if (!editor) { + return + } + if (!editor.isDestroyed) { editor.view.setProps({ nodeViews: {}, diff --git a/packages/vue-3/src/EditorContent.ts b/packages/vue-3/src/EditorContent.ts index 7bce4e99..88f8367e 100644 --- a/packages/vue-3/src/EditorContent.ts +++ b/packages/vue-3/src/EditorContent.ts @@ -56,6 +56,10 @@ export const EditorContent = defineComponent({ onBeforeUnmount(() => { const editor = props.editor + if (!editor) { + return + } + // destroy nodeviews before vue removes dom element if (!editor.isDestroyed) { editor.view.setProps({