Skip to content

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

Closed

Description

@rakina

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.

Activity

  1. calebdwilliams commented on Aug 30, 2018

    @calebdwilliams

    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.

  2. tabatkins commented on Aug 30, 2018

    @tabatkins
    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?

  3. rakina commented on Aug 30, 2018

    @rakina
    MemberAuthor

    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?

  4. tabatkins commented on Aug 30, 2018

    @tabatkins
    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.

  5. rakina commented on Aug 30, 2018

    @rakina
    MemberAuthor

    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.

  6. rakina commented on Sep 12, 2018

    @rakina
    MemberAuthor

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

  7. rakina commented on Sep 13, 2018

    @rakina
    MemberAuthor

    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.

  8. reopened this on Sep 13, 2018
  9. added
    needs resolution
    on Sep 13, 2018
  10. rakina commented on Dec 10, 2018

    @rakina
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs resolution

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions