-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
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
Custom Element Mode - Styles applied in wrong order #13029
Comments
I think this is normal. If you want to modify the styles of the component's internal DOM, you should use :deep(). // HelloWorld.vue
<script setup>
import { ref } from 'vue';
import Box from './Box.vue';
defineProps({
msg: String,
});
const count = ref(0);
</script>
<template>
<div class="warp">
<Box class="my-box"> {{ msg }} </Box>
</div>
</template>
<style scoped>
.warp :deep(.box) {
background-color: green;
}
</style>
|
https://github.com/vuejs/core/blob/main/packages/runtime-dom/src/apiCustomElement.ts#L584-L595 |
I agree to disagree here. When using standard Vue build mode like here the styles are applied from child to parent. Like I said before, it is not something that could not be fixed on the user side (you can just add another class and do something like |
The behavior is inconsistent with when custom elements are not used. |
Vue version
3.5.13
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-pn21u36z?file=src%2Fcomponents%2FHelloWorld.vue,src%2Fcomponents%2FBox.vue,src%2FApp.vue,src%2Fmain-ce.js,index.html,vite.config.js,src%2FApp.ce.vue&terminal=dev
Steps to reproduce
Open the page and wait until load.
What is expected?
I would expect the first box to be red and the second box to be green.
What is actually happening?
The first box is red, also second is red.
Generally speaking this is something that can potentially be avoided by using CSS selector specifity. But the issue here is that the behavior is inconsistent between standard Vue app and the app bundled as web component.
Basically the issue here is that there is some "box" component which has its
class="box"
and some "nested" component which uses "box", but applies additional class and style. LikeSo, in normal Vue app (if you switch the mode in Vite config in example) the styles will get applied from deepest to most shallow, like
Box
styles will be injected into DOM and thenHelloWorld
styles. For CE that's not (always?) the case and styles get applied "in order", soHelloWorld
gets injected beforeBox
.I've been trying to find some info regarding this behavior, but I only found the general PR @11517 which adds some support to web component styles. Is it something that is anyhow achievable to behave like normal Vue app ? Or is there some oversight from my side here ?
I would gladly take a look at this if I'd been given a bit of a guidance here, where approximately should I look into, is it core, or maybe compiler etc. ?
System Info
The text was updated successfully, but these errors were encountered: