There are two givens:
- ProseMirror takes a
document
parameter toserializeNode()
. (It seems to be optional, but I believe it’s required in SSR.) - ProseMirror allows
toDOM()
to return a DOM node (a result ofdocument.createElement()
).
My assumption is that somewhere in the calling context of toDOM()
a document
is always present—whether it was passed explicitly in (1) or be it ProseMirror using a global document
because it runs in a browser.
Thus the question: wouldn’t it make sense to wire it up so that toDOM()
’s body can get a hold of whichever document
ProseMirror obtained during DOM serialization (or, more precisely, the createElement()
that comes with it)? It seems suboptimal that if toDOM()
wants to createElement()
it has to come up with its own way of accessing a document
that was already passed to PM.
Example:
During SSR my build invokes serializeNode()
outside of browser environment. It rolls with (1) and passes it a document stub from JSDOM. JSDOM is a beast I don’t want to lug around at all, but it works (I recall trying some alternatives, but they did not work for PM).
Simultaneously, there are a couple of times where my schema implementation outputs a DOM element in toDOM()
. To make those occasions work, I have to either A) (in SSR) patch through a global document
where I define schema spec, or B) find a creative way of creating schemas on the fly from functions that I pass an explicit document
(either JSDOM in SSR, or a global in browser).
I currently do (A), but it feels wrong.
What I have read:
- https://discuss.prosemirror.net/t/how-to-lookup-document-from-node/800: I don’t know if it’s quite the same, since my request could be addressed without adding access to
document
viaNode
.
Relevant, but not helping: