-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Scoped styles applied to child component when component has 1 root element or when used composition api #3382
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
the first two examples are expected, even though they are admittedly non-ideal. Why: In Vue 2, every component had a root node, and scoped styles were specifically designed to also be apply-able to a child component's root node in order to control .e. it's positioning from the parent. However in Vue 3, we know have Fragments - components are no longer guaranteed to have a root node. The compromise that was reached for the Migration story was that styles could only apply to components that actually guarantee to have a rood node. In your second example, there's a second root node, that is simply never shown because of The third example however should be seen as a bug, imho. |
The third is also fragment too, Why is it a bug... |
Because the style is applied, when it shouldn't be applied to fragments at all. |
@Kingbultsea In this case, I think it is worth mentioning this in the manual, since at the moment it is very difficult to come to this conclusion after reading the manual. |
A few paragraphs down the same manual page: https://vue-loader.vuejs.org/guide/scoped-css.html#child-component-root-elements
That's the Vue 2 behavior I was mentioning (vue-loader docs are still vor v15 (which is for Vue 2). |
@Kingbultsea new example betwean same logic in tradition and composition API style. @LinusBorg new
It very usefull when you write libs to have a choose. |
Some thoughts: I think you will not be able to make the same logic for the Composition API, since the compiler cannot know how many root components will be returned until the component is mounted. It is not up to the compiler to decide during the build process. |
try |
@Kingbultsea better when "only second", but in first and second itteration its not same
|
This will be fixed in #3374 |
Version
3.0.7
Reproduction link
https://codesandbox.io/s/nice-bas-xpf2b?file=/src/components/HelloWorld.vue
Steps to reproduce
Open: https://codesandbox.io/s/nice-bas-xpf2b?file=/src/components/HelloWorld.vue
see that the same logic works different depended on compostion api or count of root element.
What is expected?
background: red;
must never be applied to child component classWhat is actually happening?
class
.tst
applied to child components when:background: red;
)scoped styles must never be applied to child compontens OR at least always (no matter it used composition api or have 2-3-5 root childs), we need clear login like "always works like this" or "newer works like this"
When used Composition api for SWITH (like v-if) - first DOM element will have
background: red;
but second - no. Its extra strange because I have only 1 root element in one time (like v-if) but second elemen doest get style.The text was updated successfully, but these errors were encountered: