-
Notifications
You must be signed in to change notification settings - Fork 1
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
query and queryAll don't work in the shadow dom #2
Comments
@semmel thank you very much for pointing this out and really sorry for the delay. And you are right. I will update the |
Despite the nice refactoring and inclusion of shadow dom for query I still encounter some problems. Fortunately all can be solved quite easy with osagai:
`<button class="btn" id="onlyButton">Click me</button>
${state === "loading" ? "Loading..." : ""}
${state === "loaded"
? `<ul class="list">
${items.map(item => `<li>${item.name}</li>`).join("")}
</ul>`
: ""
}` This however does not work well when morphdom receives the target as html string. (Try this dom in the example to see it break.) The solution is to specify the target as document fragment instead of a string: const templateElement = document.createElement("template");
templateElement.innerHTML = templateHTML;
morphdom(
element.__shadowDom__,
templateElement.content
); At first this seems to work when patching It seems morphdom continuously receives bug fixes, so why not either
Well imo |
Thank you @semmel for finding this out. I added support for multi child on shadow dom on the latest version (0.3.5) and update morphdom with latest version. The reason osagai has a "forked" version of morphdom is because we need to add a check to not consider the diffing for custom elements tags. This is because the way the diff works on morphdom, the constructor of the custom element is executed every time we made the diff (this is true only for elements that doesn't use shadow dom). But this is not expected on osagai word, since we could add event listeners or async calls in the constructor. And yes, |
@HenriqueLimas, I very much appreciate the work you put in fixing and testing my issue with the multi-child shadow-dom elements! It's really great to see the development of this valuable library (great testing and nice functional API surface) 💫
I did not know that osagai already does this. Great! But of course as you say it's necessary for this library. Regarding |
Unfortunately I've found that this causes osagai to ignore child web components with Shadow DOM Slots. Such web components not only update via attributes, but also via Light DOM which is kind of an external child of the web component. With the untweaked As a demo I created a (rather playful) example with such a Light DOM template for the host web component ( <my-garage>
<my-car ${car.isEngineRunning ? 'isrunning' : ''}><span>${car.picture}</span></my-car>
</my-garage> See this working Codepen example with Morphdom as custom renderer and really no extra work. This codepen uses the same code with If my observations are correct, in my case with Shadow Dom web components the inlined version of |
in
lib/define.js
:Although it's easy to just
element.shadowRoot.querySelector(sel)
, I might be missing something here? It seems to me that shadow dom is one of the key benefits of web components.Also just out of curiosity, why do
query
andqueryAll
return Promises? It's not that I could not handle it, but I don't find any indicator why this is necessary.Btw. I really appreciate the osagai's functional approach - it makes all that class noise go away 😄. Also like to compliment you on the beautiful documentation - it really shines 🌻 !
The text was updated successfully, but these errors were encountered: