Re: QSA, the problem with ":scope", and naming

On Thu, Oct 20, 2011 at 2:13 AM, Lachlan Hunt <lachlan.hunt@lachy.id.au> wrote:
> On 2011-10-20 07:52, Jonas Sicking wrote:
>>
>> I'm not sure I understand what you are proposing here. Are you saying that
>>
>> <div>
>> <style scoped>
>> :scope {
>>   background: green;
>> }
>> </style>
>> </div>
>>
>> should set the background of the<div>  green? This does seem intuitive
>> I agree, but it might also lead to strange behavior since the
>> rendering of the<div>  will change once the stylesheet is parsed. In
>> other words, it's very easy to get flash-of-unstyled-content behavior.
>
> In the majority of cases, that's a very easy problem for authors to avoid by
> always putting <style scoped> as the first child of the element.  Since a
> <div> is invisible in most cases without any content or other styles, any
> change in rendering from invisible to visible wouldn't be any different from
> normal incremental rendering.

You'd also get the same effect since earlier siblings of the <style
scoped> would be affected, right?

I.e. in the following markup, both <span>s would be blue and the <div>
would be green.
<div>
<span>text here</span>
<style scoped>
:scope span { background: green }
:scope { background: red }
</style>
<span>more text here</span>
</div>

Another problem though is one of performance. Allowing <style>
elements which are "later" in the DOM affect earlier nodes means that
you have to walk significantly more nodes to look for which sheet
could apply. You'll have to both look at the elements children, as
well as all following siblings.

If <style scoped> elements only affect nodes which are later in DOM
order, it's much easier to keep a list of all currently applying
<style scoped> elements as you walk through the DOM tree.

However it's possible that this can be optimized satisfactory. But
it's something that we need implementation feedback on.

/ Jonas

Received on Thursday, 20 October 2011 09:36:15 UTC