Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to use this to query the shadow DOM for SVGs? #13

Closed
jrnail23 opened this issue Oct 27, 2022 · 4 comments
Closed

Is it possible to use this to query the shadow DOM for SVGs? #13

jrnail23 opened this issue Oct 27, 2022 · 4 comments

Comments

@jrnail23
Copy link

When using <use> in SVG, elements referenced by use are rendered in a shadow DOM.
I've tried following the approach outlined here to query the shadow DOM via React Testing Library, where it waits for the existence of a host element's shadowRoot property, but in my testing, host.shadowRoot never appears.

Is it possible to get to SVG use elements' shadow DOM descendants with this library?

@KonnorRogers
Copy link
Owner

@jrnail23 honestly...I haven't tried it, but if it works like regular shadow roots on web components, I don't see why it wouldn't.

@jrnail23
Copy link
Author

Thanks for replying, @KonnorRogers. I learned this the hard way, so I'll save any future knowledge seekers hours of pain and frustration: SVGs don't work the same as regular shadow roots. A least not in Chromium, that is.

I've even tried monkey patching Element.prototype.attachShadow, as I've seen mentioned elsewhere, but that doesn't work because SVG use elements use a special "user agent" shadow DOM, and that's pretty well locked down for security reasons.

The one possibility I can see is if you're using jsdom, and if jsdom/jsdom#2128 is ever resolved (fully supporting SVG in jsdom), then maybe monkey patching attachShadow might work.

@KonnorRogers
Copy link
Owner

@jrnail23 i haven't had a chance to test it yet, but best guess is the shadowRoots are closed (most WCs use open shadowRoots) shadow-dom-testing-library doesn't touch closed shadow roots.

@jrnail23
Copy link
Author

That's the thing, it's not even a closed shadow root, it's some kind in internal-only private implementation. If it was just a closed shadowRoot, monkey patching attachShadow to always use an open shadowRoot would've worked. 🤷🏻‍♂️

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

No branches or pull requests

2 participants