How to pass shadowroot to codemirror from parent component

I apologize if this does not belong here.

I am trying to insert a codemirror 6 component inside Ionic react framework’s IonContent, but it completely messes with the codemirror styles because of the shadowdom used by IonContent.
Codemirror allows us to pass a root property where I can pass the IonContent shadow root, but I am not sure how I can get the ref for the parent IonContent.

const ICRef = useRef<HTMLIonContentElement>(null);
return (
<IonContent ref={ICRef}>
        <CodeMirrorEditor editorRoot={ ICRef.current.shadowRoot }/>
 </IonContent>
)
`

But I get error -

react-dom.development.js:23275 Uncaught TypeError: Cannot read properties of null (reading ‘shadowRoot’)

It seems like the shadowdom of IonContent is not yet part of the browser dom when CodeMirrorEditor is being rendered.

I already tried asking in the ionic forum, but no luck there. Therefore I wanted to ask here if anyone in the community has dealt with this before. Any pointers would be appreciated. Thanks.

I have this code that I think should work (but isn’t):

console.log(document.querySelector(“ion-content”)?.shadowRoot); // this is displaying the shadowRoot in dev console

const view = new EditorView({
  state,
  parent: editorRef.current,
  root: document.querySelector("ion-content")?.shadowRoot,
});

I am getting the component with shadowroot and passing it to the root which according to the docs should accept the shadowRoot I passed. However I still dont see proper styling yet.

My styles look exactly like this previous post with similar issue.

Let me know if this is not the correct way to pass shadowRoot to root property in view.

I found a clean solution to my issue.
Instead of passing IonContent ref to CodeMirrorEditor to mount codemirror component inside the shadowdom of IonContent, I created a shadowdom for codemirror itself which will keep all codemirror styles self-contained and wont interfere with Ionic’s styles. With this solution I don’t need to pass root to EditorView and it auto detect’s parent shadow dom.

Hope this helps anyone else with similar issue.