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

It's not clear how a style sheet's CSS rules are obtained#2997

Open
domenic opened this issue Sep 3, 2017 · 11 comments
Open

It's not clear how a style sheet's CSS rules are obtained #2997

domenic opened this issue Sep 3, 2017 · 11 comments
Labels
clarification Standard could be clearer topic: style

Comments

@domenic
Copy link
Member

domenic commented Sep 3, 2017

For both <style> and <link>, the "Create a CSS style sheet" algorithm is called with the CSS rules "left uninitialized". Neither of them seem to pass off the source text to the CSS specification.

<style> defines the concept of "style data", but never seems to indicate how this gets wired up to create CSS rules. <link> doesn't even do that.

Is this taken care of behind the scenes in some way by CSS? If so, we should add a note. If not, we've got a pretty glaring spec hole.

I guess at some point someone should call the algorithms in https://drafts.csswg.org/css-syntax/ ? /cc @tabatkins @SimonSapin

@domenic domenic added the clarification Standard could be clearer label Sep 3, 2017
@annevk
Copy link
Member

annevk commented Sep 3, 2017

Another thing I'd like to see clarified is whether CSS rules can be added incrementally or whether they need to be there all at once atomically (from the moment you can observe the stylesheet itself).

@domenic
Copy link
Member Author

domenic commented Sep 3, 2017

@guest271314 sure, but nothing in the HTML spec says to actually apply that procedure to the source text.

As for links, I'm specifically talking about stylesheet links here, which have the same problem.

(Replying to deleted post.)

@domenic
Copy link
Member Author

domenic commented Sep 3, 2017

Off-topic

@guest271314, I'd like to keep this issue focused on the issue identified in the OP. If you have additional suggestions or questions, please ask them elsewhere. Instead you seem to be discussing a lot of other stuff that is only barely related by virtue of having to do with style sheets. Please take comments which are not directly related to the issue discussed in the OP elsewhere. (If you are confused about the issue in the OP, feel free to ask in IRC or by email and I can further explain.)

When I'm back at my computer I'll edit both our posts to hide this off-topic stuff behind a <details>.

@tabatkins
Copy link
Collaborator

Another thing I'd like to see clarified is whether CSS rules can be added incrementally or whether they need to be there all at once atomically (from the moment you can observe the stylesheet itself).

To the best of my knowledge, webcompat requires stylesheets to appear to be parsed atomically - if you can see the stylesheet, it needs to contain all of its rules fully parsed. (And you need to be able to see the stylesheet if you can see the style/link element.) @bzbarsky has said things to this effect, iirc, in reference to conditional stylesheet loading (<link media>).

@annevk
Copy link
Member

annevk commented Sep 4, 2017

See also #696.

domenic added a commit that referenced this issue Sep 8, 2017
* De-genericizes <style> and <link rel="stylesheet"> to only deal with
  CSS. Fixes #2995.
* Makes type="" on <style> "obsolete but conforming", since it is always
  redundant.
* Makes type="(a JS MIME type)" on <script> obsolete but conforming as
  well. Previously we had a "should" requirement but had not recorded it
  in the centralized obsolete-but-conforming section that collects such
  requirements.
* Makes <style> operate on child text content. Fixes #2996.
* Adds pointers to #2997.
* Makes it clearer that parameters are not allowed in the content type
  value for script or style. Fixes #3022.
domenic added a commit that referenced this issue Sep 8, 2017
* De-genericizes <style> and <link rel="stylesheet"> to only deal with
  CSS. Fixes #2995.
* Makes type="" on <style> "obsolete but conforming", since it is always
  redundant.
* Makes type="(a JS MIME type)" on <script> obsolete but conforming as
  well. Previously we had a "should" requirement but had not recorded it
  in the centralized obsolete-but-conforming section that collects such
  requirements.
* Makes <style> operate on child text content. Fixes #2996.
* Replaces the conformance requirement (noted in the source as
  "temporary") prohibiting unmatched comment-like syntax inside <style>
  with a conformance requirement to be valid CSS.
* Adds pointers to #2997.
* Makes it clearer that parameters are not allowed in the content type
  value for script or style. Fixes #3022.
annevk pushed a commit that referenced this issue Sep 14, 2017
* De-genericizes <style> and <link rel="stylesheet"> to only deal with
  CSS. Fixes #2995.
* Makes type="" on <style> "obsolete but conforming", since it is always
  redundant.
* Makes type="(a JS MIME type)" on <script> obsolete but conforming as
  well. Previously we had a "should" requirement but had not recorded it
  in the centralized obsolete-but-conforming section that collects such
  requirements.
* Makes <style> operate on child text content. Fixes #2996.
* Replaces the conformance requirement (noted in the source as
  "temporary") prohibiting unmatched comment-like syntax inside <style>
  with a conformance requirement to be valid CSS.
* Adds pointers to #2997.
* Makes it clearer that parameters are not allowed in the content type
  value for script or style. Fixes #3022.
@SimonSapin
Copy link
Contributor

Yes, I think HTML still needs to define how the input stream (in Unicode code points) or the input byte stream is constructed, for consumption by CSS Syntax.

https://html.spec.whatwg.org/multipage/semantics.html#the-style-element defines:

The child text content of a style element must be that of a conformant style sheet.

This sort of implies that the (Unicode) input stream is the child text content, but it’s not quite a proper definition.

By the way I was surprise that child nodes would be used, rather than descendant nodes. But the test case below shows that this is what’s implemented. (The difference is only testable in XHTML or with DOM manipulation, since the HTML parser treats <style> specially.)

http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=5787

<iframe src='data:application/xhtml+xml,
  <html xmlns="http://www.w3.org/1999/xhtml">
    <style>
      .p1 { color: green }
      /*<span> This text node is not a direct child of style, and so not part of the stylesheet */
        .p1 { color: red }
      /*</span> The stylesheet resumes here */
      .p2 { color: green }
    </style>
    <p class="p1">One</p>
    <p class="p2">Two</p>
  </html>
'>

alice pushed a commit to alice/html that referenced this issue Jan 8, 2019
* De-genericizes <style> and <link rel="stylesheet"> to only deal with
  CSS. Fixes whatwg#2995.
* Makes type="" on <style> "obsolete but conforming", since it is always
  redundant.
* Makes type="(a JS MIME type)" on <script> obsolete but conforming as
  well. Previously we had a "should" requirement but had not recorded it
  in the centralized obsolete-but-conforming section that collects such
  requirements.
* Makes <style> operate on child text content. Fixes whatwg#2996.
* Replaces the conformance requirement (noted in the source as
  "temporary") prohibiting unmatched comment-like syntax inside <style>
  with a conformance requirement to be valid CSS.
* Adds pointers to whatwg#2997.
* Makes it clearer that parameters are not allowed in the content type
  value for script or style. Fixes whatwg#3022.
@cdoublev
Copy link
Contributor

cdoublev commented Jan 6, 2022

Is parse a CSS stylesheet the missing step to get the cssRules? I'm not sure because it uses parse stylesheet, which creates a stylesheet, then processes it to interpret its style rules and discard invalid at-rules. Is it expected to create then "discard" this stylesheet, before creating a new one?

@domenic
Copy link
Member Author

domenic commented Jan 6, 2022

Yeah, I don't really know the answer. It's not clear whether the CSSOM spec and CSS Syntax spec were designed to integrate with each other :(.

@annevk
Copy link
Member

annevk commented Jan 7, 2022

@whatwg/css ^^

@tabatkins
Copy link
Collaborator

Yeah, I don't really know the answer. It's not clear whether the CSSOM spec and CSS Syntax spec were designed to integrate with each other :(.

They weren't, directly at least. CSSOM came first and has been completely hand-wavey, I wrote Syntax in a hopefully usable fashion, but CSSOM was still too handwavey to really use a precise algo anyway. OM hasn't had an active editor since zcorpan left. :(

@cdoublev
Copy link
Contributor

cdoublev commented Jan 8, 2022

I wrote Syntax in a hopefully usable fashion

I confirm that, thank you Tab. My question above is just the result of the accumulated confusion at the end of my day, because I couldn't fully grasp how to hook things up appropriately, but the next day all makes sense after the expected implementation is found. I will figure out on my own, for sure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clarification Standard could be clearer topic: style
Development

No branches or pull requests

6 participants