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

ShadowRoot.styleSheets should return an empty StyleSheetList if the shadow root is not connected #526

Open
hayatoito opened this issue Jun 24, 2016 · 13 comments

Comments

@hayatoito
Copy link
Contributor

hayatoito commented Jun 24, 2016

It looks that the current spec has an unintentional bug in ShadowRoot.styleSheets. To return a meaningful StyleSheetList, UA has to parse (the contents of) style elements even if the shadow root is not in a shadow-including document.

That is inconsistent with the current Web, I think. Processing a style element should be delayed until the style element is connected to a document.

The spec should clarify that it is okay to return an empty StyleSheetList if the shadow root is not in a shadow-including document.

@hayatoito
Copy link
Contributor Author

I will file an issue to HTML Standard too.

@rniwa
Copy link
Collaborator

rniwa commented Jun 24, 2016

This was intentional per discussion on #56.

@rniwa rniwa reopened this Jun 24, 2016
@rniwa rniwa added the v1 label Jun 24, 2016
@rniwa
Copy link
Collaborator

rniwa commented Jun 24, 2016

@annevk @travisleithead

@hayatoito
Copy link
Contributor Author

hayatoito commented Jun 27, 2016

Ops. I did not realize that we had a discussion. It looks I had actually closed the issue without thinking crefully. :(
Also I found this: whatwg/html#1194

It looks this is an intentional change.

However, I think we should revert this whatwg/html#1199

The reason is :
I am afraid that most UAs can not return StyleSheetList for disconnected shadow trees because each item of the list should be CSSStyleRule, which has a property rules
which should be CSSRuleList. We can not return CSSRuleList because we have not parsed the contents of stylesheets yet. That's an important optimization. At least, Blink is not constructing CSSRuleList for style elements in disconnected trees.

I am not sure how other UAs are doing. But it would make sense to skip this process, as an optimization, I think.

If my understanding is wrong, please correct me.

@rniwa
Copy link
Collaborator

rniwa commented Jun 27, 2016

The behavior here is that stylesheets would continue to not load while it's detached from a tree. And load it once it's inserted into either a shadow tree or a document tree. This is consistent with how a view-less document work as depicted in #56 (comment).

I would be strongly opposed to changing the behavior here. Please initiate a call for consensus if you'd like to change the behavior.

@hayatoito
Copy link
Contributor Author

I am confused... It sounds that I and you have the same opinion.

The behavior here is that stylesheets would continue to not load while it's detached from a tree. And load it once it's inserted into either a shadow tree or a document tree. This is quite consistent with how a view-less document work as depicted in #56 (comment).

Yeah, that is exactly what I am proposing here.

@hayatoito
Copy link
Contributor Author

hayatoito commented Jun 27, 2016

Oh. I understand.

  • Your opinion is: The style should be loaded when it is inserted into a shadow tree, even if the shadow tree is not connected to a document.

Could you tell us what's the benefit of this behavior?

  • My opinion is: The style should be loaded if and only if it is connected to a document.

@rniwa
Copy link
Collaborator

rniwa commented Jun 27, 2016

Right, this is because a window-less document would still load stylesheets. Since ShadowRoot and Document both have styleSheets, it's inconsistent for styleSheets on ShadowRoot to behave differently based on whether it's connected to a document or not. That's just some arbitrary restriction that merits nothing.

@hayatoito
Copy link
Contributor Author

Thanks. Now I think I understand your opinion exactly.
I, however, still think my opinion is more engine friendly. How are WebKit doing here? Do you have any plan?

Note that I am not saying that window-less document should not load style sheets. It's in a shadow-including document, I think. So it should load stylesheets. I think we are in the same boat regarding this,

@rniwa
Copy link
Collaborator

rniwa commented Jun 27, 2016

I don't understand what "engine friendly" even means. Given browser engines have the capability to load stylesheets per document, I see no reason they can't do the same per shadow root basis. As for WebKit's behavior, we don't currently support styleSheets on ShadowRoot.

@hayatoito hayatoito changed the title ShadowRoot.styleSheets should return an empty StyleSheetList if the shadow root is not in a shadow-including document ShadowRoot.styleSheets should return an empty StyleSheetList if the shadow root is not connected Jul 11, 2016
@rniwa
Copy link
Collaborator

rniwa commented Apr 25, 2019

I'm pretty sure we resolved this by saying styleSheets is empty until we connect it to a document.

This needs to be spec'ed in https://drafts.csswg.org/cssom/#extensions-to-the-document-or-shadow-root-interface

@rniwa
Copy link
Collaborator

rniwa commented Apr 25, 2019

This is basically whatwg/html#4547

@emilio
Copy link

emilio commented Apr 25, 2019

And w3c/csswg-drafts#3096

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

No branches or pull requests

4 participants