From 296b6b69a6a9ba41064643d5bdac69e88196593c Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Tue, 18 Nov 2025 19:33:08 +0100 Subject: [PATCH 1/2] fix: put back mounting system --- packages/core/src/editor/BlockNoteEditor.ts | 28 +-------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/packages/core/src/editor/BlockNoteEditor.ts b/packages/core/src/editor/BlockNoteEditor.ts index 2292cf2fb9..66f33cc65d 100644 --- a/packages/core/src/editor/BlockNoteEditor.ts +++ b/packages/core/src/editor/BlockNoteEditor.ts @@ -1054,40 +1054,14 @@ export class BlockNoteEditor< * @warning Not needed to call manually when using React, use BlockNoteView to take care of mounting */ public mount = (element: HTMLElement) => { - if ( - // If the editor is scheduled for destruction, and - this.scheduledDestructionTimeout && - // If the editor is being remounted to the same element as the one which is scheduled for destruction, - // then just cancel the destruction timeout - this.prosemirrorView.dom === element - ) { - clearTimeout(this.scheduledDestructionTimeout); - this.scheduledDestructionTimeout = undefined; - return; - } - this._tiptapEditor.mount({ mount: element }); }; - /** - * Timeout to schedule the {@link unmount}ing of the editor. - */ - private scheduledDestructionTimeout: - | ReturnType - | undefined = undefined; - /** * Unmount the editor from the DOM element it is bound to */ public unmount = () => { - // Due to how React's StrictMode works, it will `unmount` & `mount` the component twice in development mode. - // This can result in the editor being unmounted mid-rendering the content of node views. - // 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). - // So, we wait two ticks to see if the component is still meant to be unmounted, and if not, we actually unmount the editor. - this.scheduledDestructionTimeout = setTimeout(() => { - this._tiptapEditor.unmount(); - this.scheduledDestructionTimeout = undefined; - }, 1); + this._tiptapEditor.unmount(); }; /** From 009cb604565b1348591048dc374763b4308e3880 Mon Sep 17 00:00:00 2001 From: Nick the Sick Date: Tue, 18 Nov 2025 19:34:55 +0100 Subject: [PATCH 2/2] test: update test for build --- packages/core/src/editor/BlockNoteEditor.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/editor/BlockNoteEditor.test.ts b/packages/core/src/editor/BlockNoteEditor.test.ts index db62dafb76..90c7cbcf4c 100644 --- a/packages/core/src/editor/BlockNoteEditor.test.ts +++ b/packages/core/src/editor/BlockNoteEditor.test.ts @@ -120,7 +120,7 @@ it("onMount and onUnmount", async () => { expect(unmounted).toBe(false); editor.unmount(); // expect the unmount event to not have been triggered yet, since it waits 2 ticks - expect(unmounted).toBe(false); + // expect(unmounted).toBe(false); // wait 3 ticks to ensure the unmount event is triggered await new Promise((resolve) => setTimeout(resolve, 3)); expect(mounted).toBe(true);