Skip to content

Commit

Permalink
fix: prevent bug when editor is destroyed very fast
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed May 28, 2021
1 parent 5858871 commit 939fc3d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/core/src/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/vue-2/src/EditorContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export const EditorContent: Component = {
beforeDestroy(this: EditorContentInterface) {
const { editor } = this

if (!editor) {
return
}

if (!editor.isDestroyed) {
editor.view.setProps({
nodeViews: {},
Expand Down
4 changes: 4 additions & 0 deletions packages/vue-3/src/EditorContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down

0 comments on commit 939fc3d

Please sign in to comment.