-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
test: Add support for querying shadow DOM #21233
base: main
Are you sure you want to change the base?
Conversation
PFE uses lit, so it makes sense to just use that for the main application as well. Web components are pretty much React built into the web platform, and lit adds some convenience around that. This is mostly a demo -- for real Cockpit pages, PF Elements is still missing too many components. Install query-selector-shadow-dom to enable testlib's shiny new support for traversing selectors through shadow DOMs from cockpit-project/cockpit#21233
Nope, it's fine. It was just a packaging bug (forgot to include the new npm module into the tarball) |
PFE uses lit, so it makes sense to just use that for the main application as well. Web components are pretty much React built into the web platform, and lit adds some convenience around that. This is mostly a demo -- for real Cockpit pages, PF Elements is still missing too many components. Install query-selector-shadow-dom to enable testlib's shiny new support for traversing selectors through shadow DOMs from cockpit-project/cockpit#21233
PFE uses lit, so it makes sense to just use that for the main application as well. Web components are pretty much React built into the web platform, and lit adds some convenience around that. This is mostly a demo -- for real Cockpit pages, PF Elements is still missing too many components. Install query-selector-shadow-dom to enable testlib's shiny new support for traversing selectors through shadow DOMs from cockpit-project/cockpit#21233
PFE uses lit, so it makes sense to just use that for the main application as well. Web components are pretty much React built into the web platform, and lit adds some convenience around that. This is mostly a demo -- for real Cockpit pages, PF Elements is still missing too many components. Install query-selector-shadow-dom to enable testlib's shiny new support for traversing selectors through shadow DOMs from cockpit-project/cockpit#21233
PFE uses lit, so it makes sense to just use that for the main application as well. Web components are pretty much React built into the web platform, and lit adds some convenience around that. This is mostly a demo -- for real Cockpit pages, PF Elements is still missing too many components. Install query-selector-shadow-dom to enable testlib's shiny new support for traversing selectors through shadow DOMs from cockpit-project/cockpit#21233
4fadac0
to
f11e9e8
Compare
Add a `querySelectorAll()` variant which can transparently pierce and traverse shadow DOMs without having to know their structure (i.e. doing selectors piece-wise and iterating on their `.shadowRoot` attribute). As this is more expensive than standard querySelector()`, only use it if the page actually contains any shadow root. This makes it a lot more convenient to write tests for pages which use web components, like https://patternflyelements.org.
f11e9e8
to
0b38c3f
Compare
The previous commit f11e9e8 always used this "deep" querySelector, and it worked. But I figure it'll be slower, so I reworked this to detect the presence of shadow DOMs, and only use the deep one if there are any. I adjusted cockpit-project/starter-kit#1028 to pull in this new version. |
/* Detect if we have any shadow DOM */ | ||
window.__haveShadowDom = function() { | ||
if (window.__haveShadowDomResult === undefined) | ||
window.__haveShadowDomResult = Array.from(document.querySelectorAll('*')).filter(el => el.shadowRoot).length > 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems pretty expensive? Likely it is more performance to write:
for (int x = 0 ; i < querySelector('*').length; i++ )
if (el.shadowRoot)
return true;
Alternatively:
let has_shadow_dom = false
document.querySelectorAll('*').forEach(element => {if (element.shadowRoot) { has_shadow_dom = true ;break; }})
Alternatively document.body.contains()
would I suppose "work" but requires you to run it every time.
Add a
querySelectorAll()
variant which can transparently pierce and traverse shadow DOMs without having to know their structure (i.e. doing selectors piece-wise and iterating on their.shadowRoot
attribute).As this is more expensive than standard querySelector()`, only use it if the page actually contains any shadow root.
This makes it a lot more convenient to write tests for pages which use web components, like https://patternflyelements.org.
cockpit-project/starter-kit#1028 makes use of that.
TODO: