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

Can we use CSSStyleSheets from <style>/<link> in adoptedStyleSheets? #34

Closed
rakina opened this issue Aug 30, 2018 · 8 comments
Closed
Labels
needs resolution Needs consensus/resolution before shipping

Comments

@rakina
Copy link
Member

rakina commented Aug 30, 2018

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.

@calebdwilliams
Copy link

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.

@tabatkins
Copy link
Contributor

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
Copy link
Member Author

rakina commented 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?

Yeah I guess so. Should we restrict usage to the Document (and any ShadowRoots inside) of its ownerNode then?

@tabatkins
Copy link
Contributor

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
Copy link
Member Author

rakina commented 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 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.

@rakina
Copy link
Member Author

rakina commented Sep 12, 2018

#35 resolves this - We shouldn't be able to use them.

@rakina rakina closed this as completed Sep 12, 2018
@rakina
Copy link
Member Author

rakina commented 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 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.

@rakina
Copy link
Member Author

rakina commented 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.

@rakina rakina closed this as completed Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs resolution Needs consensus/resolution before shipping
Projects
None yet
Development

No branches or pull requests

3 participants