Bug 160864

Summary: Shadow DOM: Toggling class in `.class ::slotted(*)` does not trigger style recalc
Product: WebKit Reporter: Keanu Lee <webkit>
Component: DOMAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: cdumez, commit-queue, koivisto, rniwa, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Safari Technology Preview   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 148695    
Attachments:
Description Flags
patch
rniwa: review+
patch for landing none

Description Keanu Lee 2016-08-15 14:32:52 PDT
Repro: http://jsbin.com/pureji/2/edit?html,output

If I have this style rule:

.class ::slotted(*) {
  background: green;
}

Toggling .class does not cause style recalc.
Comment 1 Ryosuke Niwa 2016-08-15 22:58:29 PDT

*** This bug has been marked as a duplicate of bug 160427 ***
Comment 2 Antti Koivisto 2016-11-11 11:53:53 PST
This is not a dupe.
Comment 3 Antti Koivisto 2016-11-11 12:18:59 PST
Created attachment 294518 [details]
patch
Comment 4 Ryosuke Niwa 2016-11-11 12:32:08 PST
Comment on attachment 294518 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=294518&action=review

> Source/WebCore/css/StyleInvalidationAnalysis.cpp:114
> +        m_didInvalidateHostChildren = true;

It seems like we don't need to set m_didInvalidateHostChildren if the slot isn't in a shadow tree?
Or is this a kind of optimization to avoid checking whether element is in the shadow tree or not?

> Source/WebCore/css/StyleInvalidationAnalysis.cpp:132
> +        if (shouldCheckForSlots)
> +            return CheckDescendants::Yes;

Don't we need to check the descendants of a 2nd, 3rd, etc... slot elements?
i.e. don't we need to check just !m_ruleSet.slottedPseudoElementRules().isEmpty()?
Put it another way, does this work if a single shadow root had multiple slots
each of which had to be invalidated?
Comment 5 Antti Koivisto 2016-11-11 13:02:52 PST
(In reply to comment #4)
> Comment on attachment 294518 [details]
> patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=294518&action=review
> 
> > Source/WebCore/css/StyleInvalidationAnalysis.cpp:114
> > +        m_didInvalidateHostChildren = true;
> 
> It seems like we don't need to set m_didInvalidateHostChildren if the slot
> isn't in a shadow tree?
> Or is this a kind of optimization to avoid checking whether element is in
> the shadow tree or not?

It is used to avoid O(slots*host children) traversal if there are tons of slots/children.

> Don't we need to check the descendants of a 2nd, 3rd, etc... slot elements?
> i.e. don't we need to check just
> !m_ruleSet.slottedPseudoElementRules().isEmpty()?
> Put it another way, does this work if a single shadow root had multiple slots
> each of which had to be invalidated?

It works because we invalidate all host children when we find the first slot. I don't think optimising more is important at this point.
Comment 6 Ryosuke Niwa 2016-11-11 13:08:16 PST
Comment on attachment 294518 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=294518&action=review

>>> Source/WebCore/css/StyleInvalidationAnalysis.cpp:114
>>> +        m_didInvalidateHostChildren = true;
>> 
>> It seems like we don't need to set m_didInvalidateHostChildren if the slot isn't in a shadow tree?
>> Or is this a kind of optimization to avoid checking whether element is in the shadow tree or not?
> 
> It is used to avoid O(slots*host children) traversal if there are tons of slots/children.

Might be worth a comment. Otherwise, someone might come around and *fix* it.

> LayoutTests/fast/shadow-dom/css-scoping-host-and-slotted-context-invalidation.html:81
> +

Can we add a test case with multiple slots in a single shadow tree?
Comment 7 Antti Koivisto 2016-11-11 13:37:13 PST
Created attachment 294528 [details]
patch for landing
Comment 8 WebKit Commit Bot 2016-11-11 14:02:40 PST
Comment on attachment 294528 [details]
patch for landing

Clearing flags on attachment: 294528

Committed r208610: <http://trac.webkit.org/changeset/208610>
Comment 9 WebKit Commit Bot 2016-11-11 14:02:45 PST
All reviewed patches have been landed.  Closing bug.
Comment 10 Radar WebKit Bug Importer 2016-11-11 14:40:31 PST
<rdar://problem/29226652>