-
Notifications
You must be signed in to change notification settings - Fork 378
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
Should <link rel="stylesheet"> work inside shadow DOM? #530
Comments
Also see #526 |
|
I don't think restricting link element to the document tree makes much sense. We should allow it in shadow trees. |
On my second thought, I do recall a discussion about not allowing loading of external scripts and stylesheets to discourage people from loading the same styles/scripts multiple times in a single page. |
We already decided to allow scripts. I'm fine with allowing this as well. Presumably long-term this will mostly be done through an API. |
On the other hand, it might be wise to not allow stylesheets or scripts to be loaded in shadow tree until that we figure out what we want to do with the new thing though. Otherwise, we may end up tying ourselves to some undesirable constraints. |
As @annevk already pointed out, in long-term we would use constructable stylesheets Just for historical reference, some discussions related to this: |
It seems like the argument against is that UAs are able to optimize Is that completely true? Even if the response has appropriate long-lived caching headers? I guess on initial page load with an umprimed cache it would probably still make a bunch of requests, which is bad? |
Yeah, I think UA can optimize it in theory, but such an optimization is not guaranteed by the spec. As far as I remember, that was a concern from web developers. Thus, we want to provide a standard way where such an optimization is strongly guaranteed. |
Hmm. I don't find that compelling, because as a web developer it seems like the same argument applies to multiple Maybe it is an issue of degree of badness? Multi-parsing is not as bad as multi-fetching? In general any asymmetry between |
Yeah, and given |
Thanks. I do not have a strong opinion on this issue, historically. :) |
It is definitely intuitive that |
Can we agree that If we can agree on that, I will send "Intent to implement and ship: Allow |
Yes, and if it is disconnected then connected into another shadow tree then the styling should move there too. |
I don't understand why we want to restrict to the connected shadow trees. What's the rationale? Given |
Also see the issue #526. |
I thought the conversation was about |
No, a connected restriction here makes no sense... I don't understand why it's being discussed. |
That is, I think this should be governed by the normal rules for stylesheet links, with "in a document" replaced by "connected" to allow it to work inside shadow trees, and not worrying about its root's connected status, or the element being disconnected, or somehow "moving styles" whatever that means... or anything like that at all. This seems fairly simple... We should just spec it. |
What should happen if the |
This is all covered by the CSS scoping spec. |
Gotcha, so I assume exactly the same as with But, |
I meant, if the |
Please read the above link I gave, mentally replacing "in a document" with "connected". (You may also want to re-read the definition of connected, as the way you're using it doesn't seem to match any existing definition.) |
From earlier,
It's not clear what parts of Maybe it should just do everything it already does now (nothing different), and waiting to apply styles until it is connected, because only then can the we possibly know to scope style to a shadow tree. |
I think it's pretty clear, between HTML and CSS Scoping. If you disagree, I'd suggest waiting until we get a spec finished and then you can investigate in more detail. |
Well, for document, yes. What we're discussing is what we're gonna do with shadow DOM, so there is no intention whatsoever. We're defining what that intended behavior would be here. |
Well, we already made the decision for a few of those (notably scripts), to just change "in a document" to "connected". In no case have we decided to start loading resources when the resource's shadow-including root is not a document. It seems important, for example, that if you wrap a script or link or image or... in a shadow tree, it doesn't suddenly start making resource fetches. E.g. a custom element wrapping an image (like x-gif) should behave just like an image and not perform fetches until the custom element becomes connected (and thus the img in its shadow DOM becomes connected). |
I agree with @domenic. I don't think "in a document" should become "in a document" or "whose root is a shadow root" generally. "Connected" makes sense. |
Hmm, making to work when not connected? that sounds very surprising. Would be super weird if creating a random (not in document) DOM subtree and link in it, wouldn't load the stylesheet, but then using that same subtree, on some element in it do el.shadowRoot.innerHTML = "<link rel=stylesheet href=..>"; would actually load the stylesheet. So, yes, we need connected-ness here. |
Okay, let's go with "connected" then. |
Sorry if I’m misunderstanding something, but I think that only loading when connected could cause unexpected behavior if someone tries to inspect the computed styles of the elements inside the shadow tree. |
@Zambonifofex could you elaborate? |
Well, if I have the following stylesheet being linked: button
{
color: rgb(12, 34, 56);
} …and console.log(window.getComputedStyle(but).color); (by the way, sorry if I’m using wrong terminology) |
Why would you expect that? It's not true for node trees today. Why would you expect the result to be different when the disconnected node tree is rooted at a shadow root, instead of being rooted at e.g. a |
I guess I feel that way because shadow roots limit the scope of the stylesheet just like documents do. I’d expect the same if the link is inside a document that isn’t being displayed to the user (i.e. one created by |
Ah, no, stylesheets are not fetched in such documents. (See whatwg/html#1516 and http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4299) |
@domenic then I guess it makes more sense to require “connectedness” to fetch stylesheets. Still, that’s not what I’d expect at all. |
That sounds perfect. |
+1 for the current conclusion. Thank you, folks. I am totally fine: |
I will try to spec this as soon as someone (cough, @annevk) reviews whatwg/html#1516 |
Hello! I have a couple of issues described in this SO question regarding FOUC and measurement of elements while a stylesheet being loaded, is anyone here willing to share some thoughts about it? |
Based on this thread, it seems using |
Right now it uses "in a document", meaning we are not sure whether it should be "in a document tree" or "connected": https://html.spec.whatwg.org/multipage/semantics.html#link-type-stylesheet:concept-link-obtain
I think we should allow this (i.e. switch to "connected"). If we allow
<style>
, why not<link>
?The text was updated successfully, but these errors were encountered: