Skip to content

Commit 0fb7c57

Browse files
authored
fix: put back mounting system (#2183)
1 parent 01924f6 commit 0fb7c57

File tree

2 files changed

+2
-28
lines changed

2 files changed

+2
-28
lines changed

packages/core/src/editor/BlockNoteEditor.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ it("onMount and onUnmount", async () => {
120120
expect(unmounted).toBe(false);
121121
editor.unmount();
122122
// expect the unmount event to not have been triggered yet, since it waits 2 ticks
123-
expect(unmounted).toBe(false);
123+
// expect(unmounted).toBe(false);
124124
// wait 3 ticks to ensure the unmount event is triggered
125125
await new Promise((resolve) => setTimeout(resolve, 3));
126126
expect(mounted).toBe(true);

packages/core/src/editor/BlockNoteEditor.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,40 +1054,14 @@ export class BlockNoteEditor<
10541054
* @warning Not needed to call manually when using React, use BlockNoteView to take care of mounting
10551055
*/
10561056
public mount = (element: HTMLElement) => {
1057-
if (
1058-
// If the editor is scheduled for destruction, and
1059-
this.scheduledDestructionTimeout &&
1060-
// If the editor is being remounted to the same element as the one which is scheduled for destruction,
1061-
// then just cancel the destruction timeout
1062-
this.prosemirrorView.dom === element
1063-
) {
1064-
clearTimeout(this.scheduledDestructionTimeout);
1065-
this.scheduledDestructionTimeout = undefined;
1066-
return;
1067-
}
1068-
10691057
this._tiptapEditor.mount({ mount: element });
10701058
};
10711059

1072-
/**
1073-
* Timeout to schedule the {@link unmount}ing of the editor.
1074-
*/
1075-
private scheduledDestructionTimeout:
1076-
| ReturnType<typeof setTimeout>
1077-
| undefined = undefined;
1078-
10791060
/**
10801061
* Unmount the editor from the DOM element it is bound to
10811062
*/
10821063
public unmount = () => {
1083-
// Due to how React's StrictMode works, it will `unmount` & `mount` the component twice in development mode.
1084-
// This can result in the editor being unmounted mid-rendering the content of node views.
1085-
// 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).
1086-
// So, we wait two ticks to see if the component is still meant to be unmounted, and if not, we actually unmount the editor.
1087-
this.scheduledDestructionTimeout = setTimeout(() => {
1088-
this._tiptapEditor.unmount();
1089-
this.scheduledDestructionTimeout = undefined;
1090-
}, 1);
1064+
this._tiptapEditor.unmount();
10911065
};
10921066

10931067
/**

0 commit comments

Comments
 (0)