You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[css-cascade] [css-scoping] [cssom] What should getComputedStyle return for an element which isn't in the flat tree? #1964
I believe implementations now just make it inherit from the default style, but that's not intuitive either, and in any case it's not specced, but should be.
Inheritance propagates property values from parent elements to their children. The inherited value of a property on an element is the computed value of the property on the element’s parent element. For the root element, which has no parent element, the inherited value is the initial value of the property.
But there's no mention to the flattened tree anywhere in that spec.
However, the shadow tree, when it exists, is used in the construction of the flattened element tree, which CSS uses for all purposes after Selectors (including inheritance and box construction).
changed the title [-][cssom] What should getComputedStyle return for an element which isn't in the flat tree?[/-][+][css-cascade] [css-scoping] [cssom] What should getComputedStyle return for an element which isn't in the flat tree?[/+]on Nov 9, 2017
An element assigned to a slot doesn't inherit from the shadow host, but from the assigned slot. There's no spec that defines that in case it's not assigned to any slot it should inherit from the host, afaict.
Ah, that should probably be added then; more than likely it's just an oversight. Using their parent's style is the closest approximation of the behavior that would happen whenever it gets slotted, so that looks reasonable to me.
A comparison could be made to SVG <symbol> and <defs> children, which are never rendered directly. When the element is cloned into a use-element shadow tree, the clone inherits from that context. But the original DOM elements can still have matched & inherited styles (based on its DOM tree parents), even if they are never used because the element isn't rendered. I think all browsers now calculate styles in that case -- although Firefox used to be (maybe still is) buggy, treating them as detached elements.
The Working Group just discussed What should getComputedStyle return for an element which isn't in the flat tree?.
The full IRC log of that discussion
<florian> topic: What should getComputedStyle return for an element which isn't in the flat tree?
<florian> github: https://github.com//issues/1964
<florian> emilio: frremy added that, but we already resolved
<florian> frremy: it's a bot bug, nothing to talk about
<emilio> Was resolved on https://github.com//issues/1548#issuecomment-380383455
Okay, we've added a paragraph to section 4 that should cover this, per the resolution in #1548:
Elements that are not connected or are not part of the document’s flattened element tree do not participate in CSS value processing, and do not have declared, cascaded, specified, computed, used, or actual values, even if they potentially have style declarations assigned to them (for example, by a style attribute).
CSSOM still needs to define what should be output by gCS() when an element has no styles; it might already do so but I haven't checked.
Activity
emilio commentedon Nov 9, 2017
I guess this affects a few more specs.
CSS Cascade says in https://drafts.csswg.org/css-cascade/#inheriting:
But there's no mention to the flattened tree anywhere in that spec.
CSS Scoping says in https://drafts.csswg.org/css-scoping/#shadow-gloss:
[-][cssom] What should getComputedStyle return for an element which isn't in the flat tree?[/-][+][css-cascade] [css-scoping] [cssom] What should getComputedStyle return for an element which isn't in the flat tree?[/+]FremyCompany commentedon Feb 6, 2018
Merging with #1548
emilio commentedon Feb 6, 2018
@FremyCompany I think this is not a dupe of that. A detached subree is not the same as an element which is not on the flat tree.
An element which is part of a document tree but not of the flat tree would be an unassigned child of a shadow host.
Could you reopen, o clarify in #1548 that this is also going to be addressed in there? (I don't have the permission).
Thanks!
FremyCompany commentedon Feb 8, 2018
Cross-posting from 1548:
Ah, that should probably be added then; more than likely it's just an oversight. Using their parent's style is the closest approximation of the behavior that would happen whenever it gets slotted, so that looks reasonable to me.
AmeliaBR commentedon Feb 8, 2018
A comparison could be made to SVG
<symbol>and<defs>children, which are never rendered directly. When the element is cloned into a use-element shadow tree, the clone inherits from that context. But the original DOM elements can still have matched & inherited styles (based on its DOM tree parents), even if they are never used because the element isn't rendered. I think all browsers now calculate styles in that case -- although Firefox used to be (maybe still is) buggy, treating them as detached elements.css-meeting-bot commentedon Jul 4, 2018
The Working Group just discussed
What should getComputedStyle return for an element which isn't in the flat tree?.The full IRC log of that discussion
<florian> topic: What should getComputedStyle return for an element which isn't in the flat tree?<florian> github: https://github.com//issues/1964
<florian> emilio: frremy added that, but we already resolved
<florian> frremy: it's a bot bug, nothing to talk about
<emilio> Was resolved on https://github.com//issues/1548#issuecomment-380383455
[css-cascade-4] Define that elements that are disconnected or not in …
tabatkins commentedon Jan 13, 2021
Okay, we've added a paragraph to section 4 that should cover this, per the resolution in #1548:
CSSOM still needs to define what should be output by gCS() when an element has no styles; it might already do so but I haven't checked.
@emilio Can you confirm that this looks correct?
fantasai commentedon Jan 13, 2021
Also pls edit cssom since you are the editor. :P
emilio commentedon Mar 12, 2021
Yeah that sounds good, thanks. https://drafts.csswg.org/cssom-1/#extensions-to-the-window-interface should already be doing the right thing.