fix(react): if using a deps array, destroy the previous instance

This commit is contained in:
Nick the Sick 2024-07-26 13:34:23 +02:00
parent b012471755
commit 42dc27aa4b
No known key found for this signature in database
GPG Key ID: F575992F156E5BCC
2 changed files with 9 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/react": patch
---
Fix, if using a deps array destroy the previous instance to avoid ghost instances

View File

@ -106,6 +106,10 @@ export function useEditor(
// for ssr, this is the first time the editor is created
setEditor(editorInstance)
} else if (Array.isArray(deps) && deps.length) {
// We need to destroy the editor instance and re-initialize it
// when the deps array changes
editorInstance.destroy()
// the deps array is used to re-initialize the editor instance
editorInstance = new Editor(options)