I’m trying to create a Codemirror instance with a parent element inside the Shadow Dom. This works perfectly on Chrome but for some reason, it fails on Firefox with the error-
“TypeError: root.adoptedStyleSheets.indexOf is not a function”.
I’ve tried passing the root property in the EditorView config but gives me the same error.
const editor = new EditorView({
parent: editorContainer.current,
root: props.root,
state
})
I’ve also tried deleting the node_modules folder and package.json and re-installing all the packages but no luck.
I see a normal array, with an indexOf method, in the adoptedStyleSheets property of shadow root objects in Firefox. You might want to do some debugging on your side to make sure a proper shadow root is being passed in.
The instanceof Array check may be failing because it’s an instance of the Array type from another frame. Do you maybe have code loaded that messes with Array.prototype?
In any case, I can create an editor in a shadow root on Firefox (127) just fine. You’ll have to figure out what’s going wrong in your setup. I don’t think I can say a lot about that.
I’m making an extension. I did some more testing and this problem only arises in injected content scripts in Firefox. In normal pages, it works as expected.
is it possible to use Codemirror v6 without stylesheets?
Maybe you could set up your bundler to replace style-mod, and have it put a <style> tag in each instance. It’s pretty short so you could include a patched version in your project without too much extra space.