I have created custom element using LitHTML and my own bloc based library for state management. Now I have stumble upon a case where in a element though pretty inside some other elements, returns null for parentNode and parentElement. I can't figure out why?
What are cases in which parentNode and parentElement be null ?

The element
creturned by your query has noparentElement, but it does have aparentNodewhich is ashadowRoot.ShadowRoots don't have a
parentNodeproperty (which is why yourc.parentNode.parentNodecall returnsnull) but you can return the element that theshadowRootis attached by accessing the shadowRootshostproperty (c.parentNode.host).See the docs: ShadowRoot
Or related question: Get shadow root host element