Affected Packages
core, react
Version(s)
latest
Bug Description
When a custom atom node meets these conditions
atom: true
- Uses
ReactNodeViewRenderer for its node view
- Has a
renderHTML that returns a string (text node, not an element)
- Exists in the initial document at parse time (via
parseHTML rules or content)
ProseMirror crashes with this error
TypeError: dom.hasAttribute is not a function during EditorView construction.
Codesandbox Repro
It's not clear to me if this is a TipTap or a ProseMirror issue, but I was able to workaround it. The error fires when the component mounts, and when it unmounts.
- Mount - There's an empty object getting returned when the editor is unavailable, which happens here:
|
return {} as unknown as ProseMirrorNodeView |
- Unmount - When it unmounts, again there's no view for it to use:
|
editor.view.setProps({ |
|
nodeViews: {}, |
|
}) |
Looking at it from the ProseMirror side, maybe this is an issue with NodeViewDesc.create not handling the case where dom could be a text node.
Here's how I worked around the errors for now.
Before
addNodeView() {
return ReactNodeViewRenderer(TemplateTagNodeView);
}
After
// Wrap `ReactNodeViewRenderer` to fix TypeError on mount
addNodeView() {
const reactRenderer = ReactNodeViewRenderer(TemplateTagNodeView);
return (props, ...rest) => {
const spec = reactRenderer(props, ...rest);
if (!spec.dom) {
const placeholder = document.createElement('span');
return { dom: placeholder };
}
return spec;
};
},
addProseMirrorPlugins() {
return [
// Keep a placeholder element to fix TypeError on unmount
new Plugin({
props: {
nodeViews: {
[this.name]: (node: ProseMirrorNode) => {
const dom = document.createElement('span');
dom.textContent = node.attrs.value;
return { dom };
},
},
},
}),
];
},
Browser Used
Chrome
Code Example URL
https://codesandbox.io/p/sandbox/interesting-ully-826d7l?file=%2Fpackage.json%3A9%2C6-9%2C19
Expected Behavior
No type error should be thrown.
Additional Context (Optional)
No response
Dependency Updates
Affected Packages
core, react
Version(s)
latest
Bug Description
When a custom atom node meets these conditions
atom: trueReactNodeViewRendererfor its node viewrenderHTMLthat returns a string (text node, not an element)parseHTMLrules or content)ProseMirror crashes with this error
Codesandbox Repro
It's not clear to me if this is a TipTap or a ProseMirror issue, but I was able to workaround it. The error fires when the component mounts, and when it unmounts.
tiptap/packages/react/src/ReactNodeViewRenderer.tsx
Line 382 in 18f9afe
tiptap/packages/react/src/EditorContent.tsx
Lines 168 to 170 in 18f9afe
Looking at it from the ProseMirror side, maybe this is an issue with
NodeViewDesc.createnot handling the case wheredomcould be a text node.Here's how I worked around the errors for now.
Before
After
Browser Used
Chrome
Code Example URL
https://codesandbox.io/p/sandbox/interesting-ully-826d7l?file=%2Fpackage.json%3A9%2C6-9%2C19
Expected Behavior
No type error should be thrown.
Additional Context (Optional)
No response
Dependency Updates