-
Notifications
You must be signed in to change notification settings - Fork 711
[css-scoping] explicit inherit
values for non-inherited properties give unexpected results inside shadow DOM transformations such as <details>
#8184
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
Comments
Alternatively if it is not possible to select the shadow-root (e.g. because it is not allowed to carry CSS properties? not familiar enough with the spec to know this for sure), then the meaning of "inherit" should be tweaked so as to treat the shadow-host as the "effective parent" for CSS inheritance purposes, if the "real parent" is a shadow-root. |
Precisely, this would amend 3.3.2 inheritance to say that
The overall justification being that the current behaviour of details > summary { box-sizing: inherit; } is absurd - |
Selectors from outside the shadow tree not matching the shadow tree is a feature, not a bug. What you're seeing is one of the subtle ways shadow dom is observable, because the inheritance parent is different from the DOM parent. This is described in https://drafts.csswg.org/css-scoping-1/#flattening |
This feature becomes a bug when it is used to implement things native to HTML like details > summary { box-sizing: inherit; } behaving absurdly.
Can you read the rest of my comments including my suggestion about changing the behaviour of inheritance so it behaves more intuitively without absurdities? |
It seems to me you should just use :root { --box-sizing: border-box; }
*, *:before, *:after { box-sizing: var(--box-sizing); } And then change |
Never mind
intuitively, one would expect that $b inherits $a's $property in all circumstances. But that's not the case when shadow DOM is used and $b is cut away from $a (and $property isn't an inherited property, otherwise the bug exists but isn't visible as $property gets inherited "through" the shadow DOM via other CSS rules) . OTOH, $b is in fact selected via |
Would something break if we were to implement what I suggested? Does something important on the web strongly depend on the fact that inheritance works differently than selecting descendants in the case of a shadow DOM? |
See this testcase. Would you really prefer inheriting the magenta border instead of the cyan one? I wouldn't. |
Yup, as others have said, while Selectors works on the original tree(s), inheritance (and the entire rest of CSS) works on the "flattened tree" - that is, a shadow host's children get replaced by its shadow tree, its original children are reparented to their slots, etc. This is the tree that layout works on, by both intention and necessity, and most of CSS wants to be compatible with this tree as a result. In particular, inheritance needs to be compatible with it, since inheritance happens after we figure out computed values, and computed value determination works on the flattened tree (so it's consistent with layout) This also means that properties that inherit by default take their inheritance from the shadow, when an element is slotted. This, too, is a good thing - an element slotted into a shadow would generally like its text color to be consistent with the background color coming from the shadow elements, for example. There are a few places where this is a less convenient, or more confusing, behavior - you've found one, where explicit inheritance of a non-inherited property "breaks" when the element is slotted, because the shadow parent isn't explicitly inheriting as well. Unfortunately, we have to choose a behavior, and the current behavior makes the most sense in the most cases, despite the occasional mismatch in expectations. |
The difference between the above testcase (and most other explicit use cases of shadow DOM I've seen described) vs It's an exception that makes
In other words, the shadow DOM is intended to provide some level of encapsulation. However, its usage in Forced encapsulation when the user does not request it, is a deficiency of any language. Can you please re-open the bug - since this issue exists and is not fixed. If changing the behaviour of inheritance is too awkward, there are other options:
|
Or even more bluntly,
The options for fixing are all pretty simple, I'm not sure why people are continuing to play "bug denial" here. |
The options to "fix" it are not simple. We can change things to fix your case, but only by breaking other cases. As with many API design choices, there are tradeoffs that have to be made. |
inherit
values for non-inherited properties give unexpected results inside shadow DOM transformations such as <details>
Another idea that might fix it is to make explicit In the past I think we discussed something similar for |
inherit
values for non-inherited properties give unexpected results inside shadow DOM transformations such as <details>inherit
values for non-inherited properties give unexpected results inside shadow DOM transformations such as <details>
Of course I can understand, if this is the case for a particular suggestion, then it is no good. But specifically, how do my suggestions break other use cases? @Loirooriol pointed out one issue above and I followed this up with a tweak of the suggestion to address it. That is how I imagined the discussion would proceed, by iterating on successive ideas. Instead however, most of the rest of the previous comments have been to just deny there is a problem in the first place, which IMO is not constructive. I can also understand if this issue is treated as low-priority if there are lots of other things to do by this team. But in this case the appropriate thing to do is to comment as such, say you have no time, mark the issue as low-priority, but leave it open, and not deny there is a problem.
Yes, this is similar to my (3) above except we allow the user to explicitly select which option they want. We can split the thinking of the solution into two parts, the mechanism vs the exposed interface. As I see it there are 2 possible mechanisms:
Either of these two mechanisms will fix the issue. There is a third option i.e. redefine For mechanism (1), the natural interface is to add a selector to allow the user/webdev to actually select the shadow root, currently there is no interface to do this. This was my original suggestion (the very first title of this bug report) as well as a tweaked suggestion in (1) above. For mechanism (2), there are a few options for interfaces, either implicit (my (3) above, or @dbaron's idea), or even explicit, e.g. a. via a Again, I would appreciate if the discussion could focus on downsides of any of these suggestions, rather than just flat-out denying that the problem exists. (And re-open the issue, ofc.) |
Original issue at https://bugzilla.mozilla.org/show_bug.cgi?id=1803927
Basically the bug is caused by
*
selecting only "element nodes", and not selecting the shadow-root "non-element node" [1] that is created by the definition of<details>
. [2]As I understand, and according to various other people's understanding of Shadow DOM as described in various web documents, shadow DOM is meant to provide encapsulation, e.g. so you can include other people's content in your own content without their scripts/styles breaking your scripts/styles, including browser UI elements. (Your scripts/styles OTOH can affect their scripts/styles, which makes sense as you are in control, and can write your scripts/styles in a way so as not to break theirs. All good.)
Normally when people use
<details>
however, there is no encapsulation intended. The content inside and outside the<details>
is my own content, and I do not want there to be any separation. In particular, I want elements inside the<details>
to inherit CSS rules as normal. Because*
does not select the shadow-root, there is no way to have it pass through inherited properties likebox-sizing
, even though my CSS rules can reach into its children directly and apply there.[1] https://www.w3.org/TR/css-scoping-1/#shadow-dom
[2] https://html.spec.whatwg.org/#the-details-and-summary-elements
The text was updated successfully, but these errors were encountered: