Deep selectors don't work if child component has multiple root elements
Vue version
3.2.40
Link to minimal reproduction
Steps to reproduce
See the preview in SFC playground.
What is expected?
Both child components should be affected by the deep selector rule.
What is actually happening?
The deep selector only affects the one with a single wrapping root element.
System Info
No response
Any additional comments?
No response
I'd call this expected behaviour fom the way scoped styles and deep selectors work.
This is the generated CSS:
[data-v-472cff63] h1 {
color: red;
}
As you can see, it requires a parent element bearing the parent's scope-id. Parent scope ids are only applied to the (single) root element of child components (so you can style it from the parent for i.e. margins or positioning). Mutpliple-root children don't inherit that attribute.
the normal usecase would be to apply a deep rule in the context of a parent element, i.e.:
.some-parent-class :deep(h1) {
}
I think it's also a normal usage in my example. As a user I don't need to know about how scoped CSS works. We just expect that it works.
Mutpliple-root children don't inherit that attribute.
Why? What if we apply parent scope id to every child component even if it has multiple root elements, and we change the generated CSS to:
[data-v-472cff63] h1, [data-v-472cff63]h1 {
color: red;
}
so that it applies in all situations? I don't know if there are some other pitfalls or considerations.