-
-
Notifications
You must be signed in to change notification settings - Fork 410
Fix widget styling issues by using shadow DOM #3065
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
base: master
Are you sure you want to change the base?
Conversation
| let widgetFrame = document.createElement('iframe'); | ||
| let shadowHost = document.createElement("div"); | ||
| let shadowRoot = shadowHost.attachShadow({ mode: "closed" }); | ||
| shadowRoot.appendChild(widgetFrame); |
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.
I could replace the iframe with the shadowHost, but didn't see a benefit to doing that in the spirit of minimizing change. Let me know if you think I should.
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.
There is probably no point to keeping the iframe but there is also no harm in it? And we do need some way to select the correct placeholder in tests, but we could use the placeholder's text or className or something else inside the shadow root to do it instead. I don't have a preference either way, but maybe testing against widgets will present reasons for removing the iframe?
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.
Sounds good. I'll leave it as is for now.
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.
Thank you! This round of feedback is about testing updates. I still have to test against real-world widget examples.
tests/selenium/widgets_test.py
Outdated
| ), widgetsJson) | ||
|
|
||
| def switch_to_shadow_host_frame(self, selector): | ||
| shadow_host = self.find_el_by_css("div.widget-shadow-host") |
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.
Rather than exposing an identifier for tests, let's loop over all the divs and look for one with a shadow host that contains the iframe we want. (The line above assumes the first matching div will be the one we want, which seems to work at the moment but may not in the future.)
Something like,
def switch_to_placeholder_frame(self, selector):
for el in self.driver.find_elements(By.CSS_SELECTOR, "div"):
try:
shadow_root = el.shadow_root
except NoSuchShadowRootException:
continue
iframe = shadow_root.find_element(By.CSS_SELECTOR, selector)
self.driver.switch_to.frame(iframe)
return
raise NoSuchElementException("Failed to find placeholder frame")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.
That works, thank you!
…dow root must be open for Selenium access
02e4cc9 to
ca9d736
Compare
Closed shadow roots interfere with testing, and possibly accessibility: https://jschof.dev/posts/2024/4/web-components-and-you-7/. We don't need to prevent the placeholder from being accessed by outside JS to prevent the known UI bugs
As it adds unwanted space below the placeholder on livestream.eff.org
7390807 to
42ee2b4
Compare
|
Is there anything we can do for cases like https://www.twz.com/sea/ukraine-situation-report-russian-navy-creating-new-drone-regiments-in-wake-of-enemy-successes where our placeholder is newly hidden because it no longer overrides anything with a lower z-index? Using shadow DOM isolates placeholder styles from page styles, which is great. Our z-index no longer working is less great though. While it's nice to no longer overlap navbars, I think it's a poor tradeoff if it means our placeholders can now be more easily hidden by site error messages. |
Address widget replacement overlapping with content by ensuring that the parent node height is at least as large as the min height of the widget