Skip to content

Commit

Permalink
fix(core): fix destroyed view causing errors on dispatchTransaction (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch committed Feb 28, 2023
1 parent 26a1d96 commit 3c07ca0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
Empty file.
49 changes: 49 additions & 0 deletions demos/src/Experiments/DestroyingEditor/Vue/index.vue
@@ -0,0 +1,49 @@
<template>
<div v-if="editor">
<button @click="() => editor.chain().toggleBold().focus().run()">Make bold</button>
<button @click="() => editor.destroy()">Destroy editor</button>
</div>
<div v-if="editor">
<editor-content :editor="editor" />
</div>
</template>

<script>
import StarterKit from '@tiptap/starter-kit'
import { Editor, EditorContent } from '@tiptap/vue-3'
export default {
components: {
EditorContent,
},
data() {
return {
editor: null,
}
},
mounted() {
this.editor = new Editor({
extensions: [
StarterKit,
],
content: `
<p>Try destroying the editor</p>
`,
})
},
beforeUnmount() {
this.editor.destroy()
},
}
</script>

<style lang="scss">
.ProseMirror {
> * + * {
margin-top: 0.75em;
}
}
</style>
6 changes: 6 additions & 0 deletions packages/core/src/Editor.ts
Expand Up @@ -320,6 +320,12 @@ export class Editor extends EventEmitter<EditorEvents> {
* @param transaction An editor state transaction
*/
private dispatchTransaction(transaction: Transaction): void {
// if the editor / the view of the editor was destroyed
// the transaction should not be dispatched as there is no view anymore.
if (this.view.isDestroyed) {
return
}

if (this.isCapturingTransaction) {
if (!this.capturedTransaction) {
this.capturedTransaction = transaction
Expand Down

0 comments on commit 3c07ca0

Please sign in to comment.