Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/core/src/editor/BlockNoteEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ export class BlockNoteEditor<
editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
}) => void,
) {
this._eventManager.onMount(callback);
return this._eventManager.onMount(callback);
}

/**
Expand All @@ -1275,7 +1275,7 @@ export class BlockNoteEditor<
editor: BlockNoteEditor<BSchema, ISchema, SSchema>;
}) => void,
) {
this._eventManager.onUnmount(callback);
return this._eventManager.onUnmount(callback);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions packages/react/src/editor/BlockNoteView.tsx
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really prefer not to do this if at all possible. This causes jank for everyone else. I'd prefer something at the read-side (e.g. making the reading of the domElement reactive, or making the component that needs this element on render to remount). But remounting the whole editor is way too much

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, {
ReactNode,
Ref,
useCallback,
useEffect,
useMemo,
useState,
} from "react";
Expand Down Expand Up @@ -192,6 +193,26 @@ function BlockNoteViewComponent<
comments,
]);

// editor.domElement is gated behind TipTap's isInitialized flag, which is
// set in a setTimeout(0) after mount. Force a re-render once it becomes
// available so that all child components (toolbars, menus, etc.) that
// depend on editor.domElement see the real element.
const [, setMounted] = useState(false);
useEffect(() => {
if (editor.domElement) {
return;
}
// We listen to TipTap's "create" event directly because
// editor.onMount() is registered inside the "create" handler in
// EventManager, so it misses the first mount. The "create" event
// fires after isInitialized is set, so editor.domElement is ready.
const handler = () => setMounted(true);
editor._tiptapEditor.on("create", handler);
return () => {
editor._tiptapEditor.off("create", handler);
};
}, [editor]);

return (
<BlockNoteContext.Provider value={blockNoteContext}>
<BlockNoteViewContext.Provider value={blockNoteViewContextValue}>
Expand Down
Loading