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

Observe shadow root on connected callback #308

Merged
merged 2 commits into from
Feb 28, 2023

Conversation

williammartin
Copy link
Contributor

@williammartin williammartin commented Feb 28, 2023

Description

While poking around and learning about catalyst I tried to use dynamic rendering on the shadow DOM for both a parent and a child custom web component. I was able to see the parent attach the child but the contents of the child were not attached to the DOM.

Why tho?

The existing lazyDefine creates a MutationObserver that listens to the entire document, but shadow roots live as a separate isolated node and so when the shadow root of the parent contained child, the import callback held in dynamicElements was not being called.

What's the fix?

We exported a new observe function which will observe for changes on the provided ElementLike. Then in the controller connectedCallback, if there is a shadowRoot, we'll observe it.

CC @keithamus who I paired on this with

@williammartin williammartin marked this pull request as ready for review February 28, 2023 10:20
@williammartin williammartin requested a review from a team as a code owner February 28, 2023 10:20
@@ -89,7 +89,7 @@ class HelloWorldElement extends HTMLElement {
}

attributeChangedCallback() {
render(() => html`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unrelated to the main change, just type errors.

@primer-css
Copy link

👋 Hello and thanks for pinging us! This issue or PR has been added to our inbox and a Design Infrastructure first responder will review it soon.

  • 🎨 If this is a PR that includes a visual change, please make sure to add screenshots in the description or deploy this code to a lab machine with instructions for how to test.
  • If this is a PR that includes changes to an interaction, please include a video recording in the description.
  • ⚠️ If this is urgent, please visit us in #primer on Slack and tag the first responders listed in the channel topic.

@keithamus
Copy link
Member

Great work @williammartin! LGTM 😉

@keithamus keithamus merged commit dc284dc into main Feb 28, 2023
@keithamus keithamus deleted the wm-kc/observe-shadow-root-on-connected-callback branch February 28, 2023 11:28
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

Successfully merging this pull request may close these issues.

3 participants