Skip to content

Commit bda6f30

Browse files
Fixed update listeners being called before the editor was initialized (#265)
1 parent e14ad0b commit bda6f30

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

packages/core/src/BlockNoteEditor.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
149149
public readonly _tiptapEditor: TiptapEditor & { contentComponent: any };
150150
public blockCache = new WeakMap<Node, Block<BSchema>>();
151151
public readonly schema: BSchema;
152+
private ready = false;
152153

153154
public get domElement() {
154155
return this._tiptapEditor.view.dom as HTMLDivElement;
@@ -204,11 +205,24 @@ export class BlockNoteEditor<BSchema extends BlockSchema = DefaultBlockSchema> {
204205
newOptions.onEditorReady?.(this);
205206
newOptions.initialContent &&
206207
this.replaceBlocks(this.topLevelBlocks, newOptions.initialContent);
208+
this.ready = true;
207209
},
208210
onUpdate: () => {
211+
// This seems to be necessary due to a bug in TipTap:
212+
// https://github.com/ueberdosis/tiptap/issues/2583
213+
if (!this.ready) {
214+
return;
215+
}
216+
209217
newOptions.onEditorContentChange?.(this);
210218
},
211219
onSelectionUpdate: () => {
220+
// This seems to be necessary due to a bug in TipTap:
221+
// https://github.com/ueberdosis/tiptap/issues/2583
222+
if (!this.ready) {
223+
return;
224+
}
225+
212226
newOptions.onTextCursorPositionChange?.(this);
213227
},
214228
editable: options.editable === undefined ? true : options.editable,

0 commit comments

Comments
 (0)