You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can we use CSSStyleSheets from <style>/<link> in adoptedStyleSheets? #34
If so, in which DocumentOrShadowRoots can it be used? This is related to #23 and #15, where we want to restrict usage to one Document (and any shadow trees inside it) where the CSSStyleSheet is created.
Could we add an inert attribute or something similar to those elements alongside a name or id? That could potentially place them inside the document’s style sheet list as inert and allow them to be consumed later.
Yeah, I think it should work. Same reason as having no restriction on cloning - there's already nothing wrong with using the same stylesheet object in multiple .adoptedStylesheets lists, or multiple custom elements, so why would it be weird to reuse one parsed by the document?
Yeah, I think it should work. Same reason as having no restriction on cloning - there's already nothing wrong with using the same stylesheet object in multiple .adoptedStylesheets lists, or multiple custom elements, so why would it be weird to reuse one parsed by the document?
Yeah I guess so. Should we restrict usage to the Document (and any ShadowRoots inside) of its ownerNode then?
Oh wait, that does bring up some interesting points - I think some parts of style resolution depend on the ownerNode (or its document), like URLs? Maybe it is better to disallow "connected" stylesheets from being reused, so they have a 1-1 correspondence with their defining elements. You can always clone it into an independent sheet and just use the clone instead.
Adopting it shouldn't be a problem I think as long it's still in the same document tree as it will keep the same ownerNode and location (I think? Maybe wrong). But I guess there might be some unwanted weirdness if the ownerNode is moved, the Document is changed, or something like that, so I agree if we disallow it.
I thought about this again and I can see this might be a problem with WICG/webcomponents#468. Our behavior of allowing/disallowing non-constructed stylesheet on both adoptedStyleSheets and customElements.define({ style: sheet }) should be consistent, and if we don't allow it then that means custom element default style is tied with constructable stylesheets.
Let me separate this into cases of adding non-constructed stylesheets:
Adding a non-constructed stylesheet that is connected (has ownerNode and location)
We just need to check if ownerNode is in the same document tree as where adoptedStyleSheets is.
Adding a non-constructed stylesheet that is not connected
Not possible to get stylesheet that is not connected per w3c/csswg-drafts#3096 (CMIIW)
A stylesheet that has been added to adoptedStyleSheets become disconnected
I think the current behavior of stylesheets that become disconnected is that we delete them? (again, CMIIW). We have two choices, whether to update that behavior so that if it's still inside some adoptedStyleSheets then we don't delete them (but I guess we also need to check if the adoptedStyleSheets is still connected?), or we delete them also from every adoptedStyleSheets it is part of.
A stylesheet that has been added to adoptedStyleSheets got reconnected
The ownerNode is changed. I'm not sure if location changes, but if it does, do @imports use the new URL then? If so then we need to update the adoptedStyleSheets as well, and possibly remove it if the ownerNode is now in a different document tree.
Closing this for now, if someone is interested in this, I'll reopen, but for now we won't allow usage of non-constructed stylesheet in adoptedStyleSheets.
Activity
calebdwilliams commentedon Aug 30, 2018
Could we add an
inertattribute or something similar to those elements alongside a name or id? That could potentially place them inside the document’s style sheet list as inert and allow them to be consumed later.tabatkins commentedon Aug 30, 2018
Yeah, I think it should work. Same reason as having no restriction on cloning - there's already nothing wrong with using the same stylesheet object in multiple .adoptedStylesheets lists, or multiple custom elements, so why would it be weird to reuse one parsed by the document?
rakina commentedon Aug 30, 2018
Yeah I guess so. Should we restrict usage to the
Document(and anyShadowRoots inside) of itsownerNodethen?tabatkins commentedon Aug 30, 2018
Oh wait, that does bring up some interesting points - I think some parts of style resolution depend on the ownerNode (or its document), like URLs? Maybe it is better to disallow "connected" stylesheets from being reused, so they have a 1-1 correspondence with their defining elements. You can always clone it into an independent sheet and just use the clone instead.
rakina commentedon Aug 30, 2018
Adopting it shouldn't be a problem I think as long it's still in the same document tree as it will keep the same
ownerNodeandlocation(I think? Maybe wrong). But I guess there might be some unwanted weirdness if the ownerNode is moved, the Document is changed, or something like that, so I agree if we disallow it.rakina commentedon Sep 12, 2018
#35 resolves this - We shouldn't be able to use them.
rakina commentedon Sep 13, 2018
I thought about this again and I can see this might be a problem with WICG/webcomponents#468. Our behavior of allowing/disallowing non-constructed stylesheet on both
adoptedStyleSheetsandcustomElements.define({ style: sheet })should be consistent, and if we don't allow it then that means custom element default style is tied with constructable stylesheets.Let me separate this into cases of adding non-constructed stylesheets:
Adding a non-constructed stylesheet that is connected (has
ownerNodeandlocation)We just need to check if
ownerNodeis in the same document tree as whereadoptedStyleSheetsis.Adding a non-constructed stylesheet that is not connected
Not possible to get stylesheet that is not connected per w3c/csswg-drafts#3096 (CMIIW)
A stylesheet that has been added to adoptedStyleSheets become disconnected
I think the current behavior of stylesheets that become disconnected is that we delete them? (again, CMIIW). We have two choices, whether to update that behavior so that if it's still inside some
adoptedStyleSheetsthen we don't delete them (but I guess we also need to check if theadoptedStyleSheetsis still connected?), or we delete them also from everyadoptedStyleSheetsit is part of.A stylesheet that has been added to adoptedStyleSheets got reconnected
The
ownerNodeis changed. I'm not sure iflocationchanges, but if it does, do@imports use the new URL then? If so then we need to update theadoptedStyleSheetsas well, and possibly remove it if theownerNodeis now in a different document tree.rakina commentedon Dec 10, 2018
Closing this for now, if someone is interested in this, I'll reopen, but for now we won't allow usage of non-constructed stylesheet in
adoptedStyleSheets.