You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/core/src/editor/BlockNoteEditor.ts
+28-3Lines changed: 28 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1035,15 +1035,40 @@ export class BlockNoteEditor<
1035
1035
* @warning Not needed to call manually when using React, use BlockNoteView to take care of mounting
1036
1036
*/
1037
1037
publicmount=(element: HTMLElement)=>{
1038
-
// TODO: Fix typing for this in a TipTap PR
1039
-
this._tiptapEditor.mount({mount: element}asany);
1038
+
if(
1039
+
// If the editor is scheduled for destruction, and
1040
+
this.scheduledDestructionTimeout&&
1041
+
// If the editor is being remounted to the same element as the one which is scheduled for destruction,
1042
+
// then just cancel the destruction timeout
1043
+
this.prosemirrorView.dom===element
1044
+
){
1045
+
clearTimeout(this.scheduledDestructionTimeout);
1046
+
this.scheduledDestructionTimeout=undefined;
1047
+
return;
1048
+
}
1049
+
1050
+
this._tiptapEditor.mount({mount: element});
1040
1051
};
1041
1052
1053
+
/**
1054
+
* Timeout to schedule the {@link unmount}ing of the editor.
1055
+
*/
1056
+
privatescheduledDestructionTimeout:
1057
+
|ReturnType<typeofsetTimeout>
1058
+
|undefined=undefined;
1059
+
1042
1060
/**
1043
1061
* Unmount the editor from the DOM element it is bound to
1044
1062
*/
1045
1063
publicunmount=()=>{
1046
-
this._tiptapEditor.unmount();
1064
+
// Due to how React's StrictMode works, it will `unmount` & `mount` the component twice in development mode.
1065
+
// This can result in the editor being unmounted mid-rendering the content of node views.
1066
+
// 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).
1067
+
// So, we wait two ticks to see if the component is still meant to be unmounted, and if not, we actually unmount the editor.
0 commit comments