Skip to content

Commit 3731ac9

Browse files
committed
fix(editor): resolve an unmounting of an editor instance, clobbering a newly mounted editor instance
1 parent d192b37 commit 3731ac9

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/core/src/editor/BlockNoteEditor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,18 @@ export class BlockNoteEditor<
10851085
// To avoid this, we only ever schedule the `unmount`ing of the editor when we've seen whether React "meant" to actually unmount the editor (i.e. not calling mount one tick later).
10861086
// So, we wait two ticks to see if the component is still meant to be unmounted, and if not, we actually unmount the editor.
10871087
this.scheduledDestructionTimeout = setTimeout(() => {
1088+
if (
1089+
this._tiptapEditor.isInitialized &&
1090+
// when tiptap creates a view it stores a reference to the tiptap editor which created it
1091+
"editor" in this._tiptapEditor.view.dom &&
1092+
// If the editor it has exists
1093+
this._tiptapEditor.view.dom.editor &&
1094+
// And, is not the current editor, it means that another editor has mounted over our instance
1095+
this._tiptapEditor.view.dom.editor !== this._tiptapEditor
1096+
) {
1097+
// So, we exit since this instance has already been clobbered, and if we were to unmount, we would destroy that instance
1098+
return;
1099+
}
10881100
this._tiptapEditor.unmount();
10891101
this.scheduledDestructionTimeout = undefined;
10901102
}, 1);

0 commit comments

Comments
 (0)