tiptap: [Bug]: Bubble Menu crashes React when used in conjunction with the deps argument of useEditor().
Which packages did you experience the bug in?
extension-bubble-menu, react
What Tiptap version are you using?
all are version 2.1.12
What’s the bug you are facing?
The following React code causes DOMException: Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node. when the button labeled “Click me” is pressed. The error does not occur when the BubbleMenu element is omitted. CodeSandbox link
import { BubbleMenu, Editor, EditorContent, useEditor } from "@tiptap/react";
import { StarterKit } from "@tiptap/starter-kit";
import { useState } from "react";
import ReactDOM from "react-dom/client";
export function MyEditor() {
const [thing, setThing] = useState<string | null>(null);
const editor = useEditor({
extensions: [StarterKit],
}, [thing]);
return (
editor && <div>
<EditorContent editor={editor as Editor} />
<BubbleMenu editor={editor}>
<div>
hi
</div>
</BubbleMenu>
<button onClick={() => setThing("a")}>
Click me
</button>
</div>
);
}
const root = ReactDOM.createRoot(document.getElementById("root") as HTMLElement);
root.render(
<MyEditor />
);
What browser are you using?
Chrome
Code example
https://codesandbox.io/s/blissful-wind-jq7d4m
What did you expect to happen?
I expected the same behavior, with or without BubbleMenu, that is to say, for nothing to happen.
Anything to add? (optional)
No response
Did you update your dependencies?
- Yes, I’ve updated my dependencies to use the latest version of all packages.
Are you sponsoring us?
- Yes, I’m a sponsor. 💖
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 18 (5 by maintainers)
This issue is still persisting. When you use dep array in
useEditor(...., [dep])alongside with<BubbleMenu />the Editor crashes with following error:However, I was able to resolve it(sorta) with moving
<BubbleMenu />above<EditorContent />like:In our case we had to move it above a few different components. (I think it had to be above anything consuming the editor instance). This seems really fragile… Could this be re-opened @bdbch?
Saved my life, thank you~
There is no need to import and register
BubbleMenufrom@tiptap/extension-bubble-menuas everything is working with using the BubbleMenu React binding from@tiptap/react(which is using@tiptap/extension-bubble-menuunder the hood).Came here with the same error but with
FloatingMenu. Adding adivas a top element insideEditorProviderfixed the error.For the reference, the error is as follows:
By the way, what seemed to work in my case, was actually ensuring the
<EditorProvider />only has one top level child. I think that’s what fixed it:Works:
Breaks:
Wanted to say I am also seeing this issue. Moving from a
<>to a<div>didn’t seem to help.Noting this in case anyone runs into a similar situation. I was using the Tiptap editor wrapped in my own
Documentcomponent. React reuses DOM elements when their keys do not change so adding something like<Document key={selectedDocumentId} docId={selectedDocumentId} />solved my issueThe
Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.error should be resolved after #5398@svenadlung It looks like to me like the above example is using the react binding. We’re seeing the same issue when using BubbleMenu with React. It’s possible I am misunderstanding something, but why was this closed?