At the moment, in a reasonably complex prosemirror-setup, we’re getting a very intermittent error – Cannot read property 'nodeType' of undefined
. It’s thrown as a result of dom not being defined here. I logged an issue to describe this, but I thought I’d better post here, as it was pointed out that this is likely our problem, not Prosemirror’s!
After adding additional logging, we have more information about what’s going on. We added the following line to prosemirror-view just after the line linked above:
if (!dom) {
throw new TypeError(("Tried to construct WidgetViewDesc with spec " + (JSON.stringify(widget.type.spec)) + ", but toDOM was falsy (should be (() => Element)|Element)"))
}
The error messages coming back are thus:
Tried to construct WidgetViewDesc with spec {"type":"DECORATION_MATCH","id":"8136e48c-cb39-44f1-8468-8177b15dd4b0","categoryId":"Typography","inclusiveStart":false,"inclusiveEnd":false}, but toDOM was falsy (should be (() => Element)|Element)
This is very odd – the decoration spec in question is added to an inline decoration, not a widget decoration, here. As far as I can tell there’s no dom
property on an inline node, and so prosemirror-view tries to access something that isn’t there. It feels like an inline decoration has gotten somewhere it shouldn’t.
Stepping through the way PM renders decorations with a debugger, it looks like the relevant code to distinguish between inline and widget decos is here, where iterDeco
calls onWidget
for widget decos and onNode
when it encounters a node – but the logic for how this distinction is made beyond this is very complicated to me at present.
No. 1 candidate for me at the moment is something mutating some property, possibly decoration related, that it shouldn’t. I’ve got to admit I’m quite stumped! I’ll continue to debug, but if anyone’s encountered a similar problem before, or knows much about these internals, any advice would be very much appreciated.