Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix destroyed view causing errors on dispatchTransaction #3799

Merged
merged 1 commit into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
49 changes: 49 additions & 0 deletions demos/src/Experiments/DestroyingEditor/Vue/index.vue
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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