question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CSS class do not pass to children in the production build

See original GitHub issue

Describe the bug

  1. 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>
  1. During the dev server this code works as expected image
  2. But in production, we have no class image

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
edikdeislingcommented, May 18, 2022

@poyoho one addition is class is passing even if the root node is template. This code:

<template v-if="true">
  <div>Child</div>
</template>

works both in dev and prod.

1reaction
poyohocommented, May 18, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found