-
Notifications
You must be signed in to change notification settings - Fork 73
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
Declarative Shadow DOM #335
Comments
My initial reaction to this (although I wasn't involved in the discussions that led to it) is that it makes me pretty nervous for a few reasons, although I haven't thought any of them through deeply:
|
Thanks for the comments, @dbaron. Let me see if I can address at least some of them:
I hope you are correct that this has more-broad applicability than just SSR. Though that clearly (to me at least) is the most-commonly-cited reason for wanting a declarative API for Shadow DOM.
I assume here you are referring to the fact that the template content needs to be duplicated within each shadow root? If so, I do understand this concern, and I alluded to this in the explainer. The biggest problem that I see is that you need some sort of idref-based solution to enable re-using a single template for multiple shadow roots, and that is currently not quite a solved problem. I'm open to suggestions here. It does seem possible to (later) expand this first iteration (where each shadow root needs local template content) to allow a reference to another template. Something like
Hmm, I'm not sure what you mean here. Can you elaborate a bit?
Hopefully encapsulation should be ok. There were several comments on the issue thread about ensuring proper encapsulation, e.g. here, and I think the proposed API captures those. Is there something particular you are concerned about, so we can make sure it gets addressed?
I do agree with you here. We are actually working on a separate proposal for style encapsulation independent of shadow DOM, but that is moving slowly and not ready for prime time. In the meantime, while this proposal does list style encapsulation as something that gets easier to use with declarative Shadow DOM, I would agree that we shouldn't "push" this use case. On the other hand, I wouldn't argue with a developer who "likes" the style encapsulation features of Shadow DOM, and wants to use them, but is precluded for one reason or the other from using Javascript. |
Is whatwg/dom#831 (comment) still a valid concern? |
The question of attribute injection is not fully resolved, I don't think. However, I'm not sure what changes could be made to improve the situation. Note that the comment you reference had an answer from me, here, which was never discussed again on that thread. For completeness, here is the original comment and my response:
I'd be really curious to hear your thoughts on this issue, and ideas for potential mitigations. |
The biggest worry I have here is that since the proposal deals with a small subset of the overall problem space around declarative Shadow DOM, is it possible that we end up having this one syntax where template is used within some element to define Shadow DOM, and then possibly some very different syntax for the case were idrefs are used etc. And if that happens, there is a chance that everyone will use that new syntax (since it it would avoid shortcomings like the repetition), but browser are forced to support both. But this is not very strong concern. And rniwa's whatwg/dom#831 (comment) , especially the part around not knowing when parsing has finished makes the setup rather fragile. |
@smaug----, thanks for the comments!
Thanks for bringing this up. I do see your point. On the flipside, however, I think there is a natural path to supporting both features that can share much of the code. For example, once idrefs are available, one could use something like this: <template shadowroot=open shadowtemplate=#magic-global-id></template> Several things need to be worked out, such as how the magic-global-id works, and what happens if that template is located "after" the reference. But assuming those are figured out, this would just look for the given
Here again, I agree with you. I've also said so on the issue thread. I do think #809 needs to be solved, but I really don't think it needs to be "tied" to this implementation. As mentioned on the 809 thread, there are already numerous reasons to want such a feature, and numerous potential footguns present because 809 isn't solved. I would argue that while this is one more potential footgun, it is fairly easy to avoid by simply placing declarative content before asynchronous |
Some thoughts in no particular order:
|
@hsivonen Thanks for the thoughtful comments! Please see my replies inline...
I agree that this is a concern, and it has been discussed on the issue thread, starting roughly here. I believe (though please point out places where I've missed things!) that I've specified the process in a concrete way so that this can be made interoperable. In particular, I have DOM and HTML PRs that could use a review.
The idea is that yes - the process (shadow root attachment, template contents move, template node delete) happens synchronously just as normal parser-performed node insertion. I believe I've thought of the consequences of that, but as with all such situations, more consideration would be helpful. But I did write a few WPT tests that look at observability of DOM modifications, for example.
Yes, again here I believe I've thought of that - see this WPT test. The TL/DR is that a normal template containing a declarative template will now contain a shadow root inside the template.content. I had to modify the spec for cloning nodes to deal with this, so that the cloned nodes get fresh shadowroots. But again, let me know if you see a corner case I missed or didn't think about. Related to the above, we also modified the spec so that the
Yes, Shadow DOM provides style and JS encapsulation. In the no-JS case, all that is left is style encapsulation. One of the motivations, though admittedly a small one, is to allow CSS developers to use declarative Shadow DOM for "pure" style encapsulation. However, as stated in the explainer, the primary motivation for this feature is to allow full Web Components users (who also expect the JS encapsulation) to use Server Side Rendering, which produces an isomorphic representation on the client and server.
I agree with you, generally, but as you know, sometimes you only find out about problems "later". In this case, I believe the work to get to Shadow DOM v1 was long and hard, and I'm guessing it was easier to make it an imperative-only API to start. Now that this is an established standard, implemented in all browsers, we can start to think about the next thing - a declarative version.
I agree that this expansion of the innerHTML "power" might come with additional risks. I'm open to suggestions for how to minimize that while retaining the usefulness of the feature!
So the polyfill here is relatively simple I think. First, feature detection is possible. And if not natively supported, it is relatively straightforward to do a |
Just a quick friendly ping to see if there was any additional input on declarative Shadow DOM? |
Friendly ping on this thread. Declarative Shadow DOM will be discussed next week at TPAC, and Chromium is hoping to ship this feature soon, so we'd love your feedback. |
I think as per the discussion in whatwg/dom#831 and above our position is non-harmful. We are not convinced the feature carries its weight, but the proposal is a reasonable approach given the various constraints. There's also a risk that it might not meet the needs for declarative custom elements as this was largely developed in isolation. Happy to take further feedback for a bit before closing this with a PR. |
Thanks @annevk for this feedback, and for considering this feature non-harmful. I do understand your concern about the feature carrying its weight - perhaps we'll learn more on this from the use counters after it launches. I also agree that this feature has been developed separately from declarative custom elements, and that does pose a risk. Though as I've pointed out previously, the current strawman proposal uses a syntax very similar to this one for the shadow content, so hopefully they will eventually play nicely together. Again, thanks! |
I just wanted to follow up on this request for position, as there has been significant offline discussion about this feature. It is Chromium's position that this feature is ready to go, and all known/discussed issues have been resolved. To quickly summarize the changes and discussions that have happened since I proposed this feature over a year ago:
Based on our perception that this feature is in a good state, and would benefit the platform, Chromium intends to try to get this feature shipped soon. We would love to have the support of Mozilla. |
FWIW, the discussion here refers to the old declarative shadow DOM proposal, which was quite different to the new one. |
Worth pointing out that WebKit has a patch to enable declarative shadow dom by default on all platforms: WebKit/WebKit#7798 Their standards position on this is “support”. |
And worth to note that there isn't even spec yet for declarative shadow DOM. |
I had been assuming, based on this comment (whatwg/dom#831 (comment)) that Mozilla was at least approaching supportive. Could we please re-open this issue and perhaps update the position?
There is certainly an in progress spec PR for DSD: whatwg/html#5465 and whatwg/dom#892 |
We're positive for the new approach. Thanks for raising. I'll submit a PR to update the dashboard entry. |
🎉 Thank you! |
hey all- I'm working on preparing a TPAC report for Declarative Shadow DOM, and I'm trying to get a sense of the current state of DSD. Is there an Intent to Prototype/Ship declared somewhere for firefox that someone could send a link to? I have the bugzilla as far as I know. Is that one the best one? If there are no Intent to prototype/ship declarations, another question would be whether there are any blockers from the spec/proposal perspective that we can call out in TPAC to get resolutions for. Thanks for the help! |
The implementation work should start soon. |
Request for Mozilla Position on an Emerging Web Specification
Other information
A declarative API to allow the creation of #shadowroots using only HTML and no Javascript. This API allows Web Components that use Shadow DOM to also make use of Server-Side Rendering (SSR), to get rendered content onscreen quickly without requiring Javascript for shadow root attachment and population.
Much more detail, including more motivating use cases, can be found in the explainer.
Chrome is particularly interested in shipping this feature. A majority of the proposed spec has been implemented, with WPT tests, behind the DeclarativeShadowDOM feature flag.
Example syntax:
The text was updated successfully, but these errors were encountered: