Skip to content

Conversation

ggodlewski
Copy link

While using prosemirror inside Custom Element this line fails.
In such case this.prosemirrorView._root is set to ShadowRoot not Document.
Method createRange exists only in Document.

@dmonad dmonad closed this Jul 17, 2025
@dmonad
Copy link
Member

dmonad commented Jul 17, 2025

If you use dom.doc, you are creating a range from the custom element, which use a different range constructor. It is not immediately obvious to me why this would work. I feel that prosemirrorView._root (using the document from the custom element) is the appropriate choice here.

So I assume that your fix simply disables this feature. Could you please verify?

The issue is probably more complex. I'd like to have a reproducible example first and understand why the solution works appropriately in all cases. Please make sure to test that the PR actually works for custom elements.

@dmonad dmonad reopened this Jul 17, 2025
@ggodlewski
Copy link
Author

prosemirrorView._root is not to proper choice because it's either: null, document or shadowRoot.
It is private property of view. Currently it works only because something else accessed root eariler https://github.com/ProseMirror/prosemirror-view/blob/master/src/index.ts#L349

There is no such thing as different range constructor. The only class that implements createRange is Document.
Range is just a class. You can even initiate it with new Range() https://dom.spec.whatwg.org/#dom-document-createrange

The reason I don't use it is because I also use this plugin in nodejs without DOM api, so I use dom.doc which is already there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants