[csswg-drafts] [cssom-1] circular imports and CSSImportRule (#4287)

bathos has just created a new issue for https://github.com/w3c/csswg-drafts:

== [cssom-1] circular imports and CSSImportRule ==
I was curious about how circular and repeated imports behave. I checked the definition of [@import](https://drafts.csswg.org/css-cascade-3/#at-import) in CSS Cascading and Inheritance Level 3.

My understanding from reading that is that all valid import atrules cause the contextual stylesheet to behave as if the referenced sheet’s rules appeared in place of the atrule. I checked Chrome and Firefox and they seemed to confirm this and were happy to deal with circular imports in various odd combos. That makes sense — although I’d found no spec text specifically addressing circularity, it seems implicitly permitted because I think the implementation only needs to ‘insert’ them once, in the ‘furthest-down’ place they’re referenced, in order to achieve the specified behavior. Due to the nature of the cascade, inserting them just once in that position is equivalent to actually importing them in all positions — which, if actually done, would potentially lead to endless recursion.

> When the same style sheet is imported or linked to a document in multiple places, user agents must process (or act as though they do) each link as though the link were to an independent style sheet.

So styling behavior made sense and was consistent, but things got weird when I started peeking at the CSSOM. It appears Chrome and Firefox don’t agree about what should happen to the representations of CSSImportRules when circular imports are involved.

Here is a minimal example, involving just one stylesheet importing itself:

https://rogue-onion.glitch.me/

Neither FF nor Chrome take the approach of actually implementing a circular graph for this in the CSSOM, but they ‘clip’ the graph in different places. In Chrome, the CSSImportRule has `null` as its stylesheet value. In Firefox, the CSSImportRule has a stylesheet value, but it is a unique object reference from the parent stylesheet (which is ostensibly the same one? or is it...) and it has an empty CSSRuleList.

Chrome’s behavior [violated the Web IDL type definition](https://drafts.csswg.org/cssom/#the-cssimportrule-interface) in which CSSImportRule.prototype.styleSheet is not nullable. In fact there’s even a lil callout about this:

> _Note: An @import at-rule always has an associated CSS style sheet._

I can’t find anything that specifies the behavior I observed in Firefox, either, though I also haven’t found anything that definitely contradicts it.

Is the behavior of CSSImportRule when there are circular imports underspecified, or specified in a way that doesn’t match web reality?

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/4287 using your GitHub account

Received on Monday, 9 September 2019 06:37:28 UTC