CSS class do not pass to children in the production build
See original GitHub issueDescribe the bug
- Create this structure
parent component
<script setup lang="ts">
import HelloWorld from './components/HelloWorld.vue'
</script>
<template>
<HelloWorld class="parent-class" />
</template>
<style scoped>
.parent-class {
background-color: red;
}
</style>
child component(HelloWorld.vue
)
<template>
<template v-if="true">
<div v-if="true">Child</div>
</template>
</template>
<style scoped></style>
- During the dev server this code works as expected
- But in production, we have no class
If we remove the template tag or if we remove the v-if from div - everything starts working
Reproduction
https://github.com/edikdeisling/issue-vite-scoped-css-production
System Info
System:
OS: Linux 5.15 Ubuntu 22.04 LTS 22.04 LTS (Jammy Jellyfish)
CPU: (8) x64 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
Memory: 4.48 GB / 15.42 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 17.6.0 - ~/.nvm/versions/node/v17.6.0/bin/node
Yarn: 1.22.17 - ~/.nvm/versions/node/v17.6.0/bin/yarn
npm: 8.5.1 - ~/.nvm/versions/node/v17.6.0/bin/npm
Browsers:
Chrome: 101.0.4951.54
Firefox: 99.0.1
npmPackages:
@vitejs/plugin-vue: ^2.3.1 => 2.3.1
vite: 2.9.7 => 2.9.7
Used Package Manager
yarn
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
CSS class do not pass to children in the production build · vitejs/vite ...
CSS class do not pass to children in the production build. Issue Labeled #4799 #4799. Sign in to view logs · Sign in...
Read more >Cascade, specificity, and inheritance - Learn web development
At some point, you will be working on a project and you will find that the CSS you thought should be applied to...
Read more >Pass class to children component host - css - Stack Overflow
In React I would just add prop with the class name and assign it or pass some inline styles, depending on what style...
Read more >not - CSS-Tricks
The :not() property in CSS is a negation pseudo class and accepts a simple selector or a selector list as an argument.
Read more >Styling in React: 5 ways to style React apps - LogRocket Blog
The other is a JavaScript object that maps the original CSS name with the renamed name. Alright, let's create a CSS class in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@poyoho one addition is class is passing even if the root node is
template
. This code:works both in dev and prod.
I am not sure. I can re-show it in vue-sfc. But it only appear in the root node is
template
. It may be a design do not add the attr in template node in vuejs. I think we need to make the dev and prod had the same behavior