@@ -24,7 +24,7 @@ export type BlockNoteTipTapEditorOptions = Partial<
24
24
// @ts -ignore
25
25
export class BlockNoteTipTapEditor extends TiptapEditor {
26
26
private _state : EditorState ;
27
-
27
+ private _creating = false ;
28
28
public static create = (
29
29
options : BlockNoteTipTapEditorOptions ,
30
30
styleSchema : StyleSchema
@@ -151,8 +151,12 @@ export class BlockNoteTipTapEditor extends TiptapEditor {
151
151
* Replace the default `createView` method with a custom one - which we call on mount
152
152
*/
153
153
private createViewAlternative ( ) {
154
+ this . _creating = true ;
154
155
// Without queueMicrotask, custom IC / styles will give a React FlushSync error
155
156
queueMicrotask ( ( ) => {
157
+ if ( ! this . _creating ) {
158
+ return ;
159
+ }
156
160
this . view = new EditorView (
157
161
{ mount : this . options . element as any } , // use mount option so that we reuse the existing element instead of creating a new one
158
162
{
@@ -178,6 +182,7 @@ export class BlockNoteTipTapEditor extends TiptapEditor {
178
182
this . commands . focus ( this . options . autofocus ) ;
179
183
this . emit ( "create" , { editor : this } ) ;
180
184
this . isInitialized = true ;
185
+ this . _creating = false ;
181
186
} ) ;
182
187
}
183
188
@@ -189,6 +194,8 @@ export class BlockNoteTipTapEditor extends TiptapEditor {
189
194
public mount = ( element ?: HTMLElement | null ) => {
190
195
if ( ! element ) {
191
196
this . destroy ( ) ;
197
+ // cancel pending microtask
198
+ this . _creating = false ;
192
199
} else {
193
200
this . options . element = element ;
194
201
// @ts -ignore
0 commit comments