-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
vite build
produces incorrectly flattened nested CSS
#18974
Comments
vite build
produces incorrectly flattened nested CSS
Hello! Any news on this issue ? I have the same issue using some tailwind classes on Nuxt. |
I +1, Got the same issue here, this CSS from tailwind 4 (beta > 6) is not applied in our nuxt build (3.15.1)
became
The beta version of tailwind 4 is not buildable with vite as a result (or I don't know how) |
I've moved my Sveltekit project to Tailwind v4 with Vite yesterday and there I have a @utility scrollbar-hidden {
/* Hide scrollbar for Chrome, Safari and Opera */
&::-webkit-scrollbar {
display: none;
}
/* Hide scrollbar for IE, Edge and Firefox */
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
} This shows up and works in my local dev build using import { defineConfig } from 'vitest/config'
import { sveltekit } from '@sveltejs/kit/vite'
import tailwindcss from '@tailwindcss/vite'
export default defineConfig({
build: { target: 'ESNext' },
plugins: [sveltekit(), tailwindcss()],
test: {
include: ['tests/vitest/**/*.{test,spec}.{js,ts}']
}
}) I'm currently on those package versions:
|
Has anyone resolved this issue? |
same here! .space-x-4 {
:where(& > :not(:last-child)) {
--tw-space-x-reverse: 0;
margin-inline-start: calc(calc(var(--spacing) * 4) * var(--tw-space-x-reverse));
margin-inline-end: calc(calc(var(--spacing) * 4) * calc(1 - var(--tw-space-x-reverse)));
} final code: .space-x-4 :where(>:not(:last-child)) {
--tw-space-x-reverse: 0;
margin-inline-start: calc(calc(var(--spacing) * 4) * var(--tw-space-x-reverse));
margin-inline-end: calc(calc(var(--spacing) * 4) * calc(1 - var(--tw-space-x-reverse)))
} |
Upstream issue was fixed, will likely be part of the next esbuild release. |
v0.25.0 of esbuild has been released 🥳 |
@RobinMalfait do you know when this will fix the issue in tailwind? I'm currently on 4.0.5 and the issue is still present i.e. works in dev mode but the production build is broken. |
@evdama it's not a Tailwind issue. Tailwind produces valid CSS, and then Vite processes the CSS (or in this case esbuild) and esbuild produced invalid CSS. This is now fixed in esbuild and released as part of https://github.com/evanw/esbuild/releases/tag/v0.25.0, once Vite bumps the esbuild version then this should start working again. |
Thanks! Understood. So now we wait https://github.com/vitejs/vite/blob/main/packages/vite/package.json#L88 |
# Motivation We want to bump `tailwindcss` to v4. However [the migration tool does not support SASS files](tailwindlabs/tailwindcss#15716). # Workaround We changed all the `.scss` files to a copy in `.css` and use the migration tool, and then reverted. Same thing with the language in the `<style>` tag of Svelte components. Then we added a few manual tweaks anyway. # Disclaimer Since a part of the PR was a manual process, it may very well be that I missed something or there is some error in migration. # Note Apparently `prettier-plugin-tailwindcss` was bumped too, so a few changes happened in the sorting order of the tailwind classes too. That is the reason for this many files changed in this PR, since we have an auto-formatter. Furthermore, it seems that [a few classes will require a Vite update to work properly](vitejs/vite#18974). For example `space-x-*` and `space-y-*`. # Changes - The migration tool: - installed `tailwindcss` v4; - changed `postcss.config`; - migrated the tailwind classes that required migration (see [upgrade guide](https://tailwindcss.com/docs/upgrade-guide)); - correctly changed `global.css` (that we reverted to `global.scss` after). - A few changes were missing, and we did it manually: - The `Hero` gradient does not need a `via-` color anymore, it can changed to `from-`. - The util `@screen foo` is deprecated and should be replaced with `@media (width >= theme(--breakpoint-foo))` (see [codebase of tailwindcss migration](https://github.com/tailwindlabs/tailwindcss/blob/121cf6bd807a35ad9814dd5444eeb3594601fff8/packages/%40tailwindcss-upgrade/src/codemods/migrate-media-screen.test.ts)). - It is [suggested](https://tailwindcss.com/docs/upgrade-guide#using-vite) to install and add `@tailwindcss/vite` in `vite` (and `vitest`) configs; - Move `@include meta.load-css(...)` inside `@layer base {...}` (suggestion in [tailwindcss discussion](tailwindlabs/tailwindcss#16421)). - We create another branch to make the changes manually following the [upgrade guide](https://tailwindcss.com/docs/upgrade-guide) and they matched: - #4666 # Tests There is not much test to help us, apart update the E2E snapshots and manual navigation in local replica: https://github.com/user-attachments/assets/d0ae2e36-7fff-4ff8-8829-3c93e900650a --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
# Motivation We want to bump `tailwindcss` to v4. However [the migration tool does not support SASS files](tailwindlabs/tailwindcss#15716). # Workaround We changed all the `.scss` files to a copy in `.css` and use the migration tool, and then reverted. Same thing with the language in the `<style>` tag of Svelte components. Then we added a few manual tweaks anyway. # Disclaimer Since a part of the PR was a manual process, it may very well be that I missed something or there is some error in migration. # Note Apparently `prettier-plugin-tailwindcss` was bumped too, so a few changes happened in the sorting order of the tailwind classes too. That is the reason for this many files changed in this PR, since we have an auto-formatter. Furthermore, it seems that [a few classes will require a Vite update to work properly](vitejs/vite#18974). For example `space-x-*` and `space-y-*`. # Changes - The migration tool: - installed `tailwindcss` v4; - changed `postcss.config`; - migrated the tailwind classes that required migration (see [upgrade guide](https://tailwindcss.com/docs/upgrade-guide)); - correctly changed `global.css` (that we reverted to `global.scss` after). - A few changes were missing, and we did it manually: - The `Hero` gradient does not need a `via-` color anymore, it can changed to `from-`. - The util `@screen foo` is deprecated and should be replaced with `@media (width >= theme(--breakpoint-foo))` (see [codebase of tailwindcss migration](https://github.com/tailwindlabs/tailwindcss/blob/121cf6bd807a35ad9814dd5444eeb3594601fff8/packages/%40tailwindcss-upgrade/src/codemods/migrate-media-screen.test.ts)). - It is [suggested](https://tailwindcss.com/docs/upgrade-guide#using-vite) to install and add `@tailwindcss/vite` in `vite` (and `vitest`) configs; - Move `@include meta.load-css(...)` inside `@layer base {...}` (suggestion in [tailwindcss discussion](tailwindlabs/tailwindcss#16421)). - We create another branch to make the changes manually following the [upgrade guide](https://tailwindcss.com/docs/upgrade-guide) and they matched: - #4666 # Tests There is not much test to help us, apart update the E2E snapshots and manual navigation in local replica: https://github.com/user-attachments/assets/d0ae2e36-7fff-4ff8-8829-3c93e900650a --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
# Motivation We want to bump `tailwindcss` to v4. However [the migration tool does not support SASS files](tailwindlabs/tailwindcss#15716). # Workaround We changed all the `.scss` files to a copy in `.css` and use the migration tool, and then reverted. Same thing with the language in the `<style>` tag of Svelte components. Then we added a few manual tweaks anyway. # Disclaimer Since a part of the PR was a manual process, it may very well be that I missed something or there is some error in migration. # Note Apparently `prettier-plugin-tailwindcss` was bumped too, so a few changes happened in the sorting order of the tailwind classes too. That is the reason for this many files changed in this PR, since we have an auto-formatter. Furthermore, it seems that [a few classes will require a Vite update to work properly](vitejs/vite#18974). For example `space-x-*` and `space-y-*`. # Changes - The migration tool: - installed `tailwindcss` v4; - changed `postcss.config`; - migrated the tailwind classes that required migration (see [upgrade guide](https://tailwindcss.com/docs/upgrade-guide)); - correctly changed `global.css` (that we reverted to `global.scss` after). - A few changes were missing, and we did it manually: - The `Hero` gradient does not need a `via-` color anymore, it can changed to `from-`. - The util `@screen foo` is deprecated and should be replaced with `@media (width >= theme(--breakpoint-foo))` (see [codebase of tailwindcss migration](https://github.com/tailwindlabs/tailwindcss/blob/121cf6bd807a35ad9814dd5444eeb3594601fff8/packages/%40tailwindcss-upgrade/src/codemods/migrate-media-screen.test.ts)). - It is [suggested](https://tailwindcss.com/docs/upgrade-guide#using-vite) to install and add `@tailwindcss/vite` in `vite` (and `vitest`) configs; - Move `@include meta.load-css(...)` inside `@layer base {...}` (suggestion in [tailwindcss discussion](tailwindlabs/tailwindcss#16421)). - We create another branch to make the changes manually following the [upgrade guide](https://tailwindcss.com/docs/upgrade-guide) and they matched: - #4666 # Tests There is not much test to help us, apart update the E2E snapshots and manual navigation in local replica: https://github.com/user-attachments/assets/d0ae2e36-7fff-4ff8-8829-3c93e900650a --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Temporarily fix:
nuxt.config.ts:
|
Describe the bug
When using modern CSS with nesting, a production build will generate invalid CSS.
Given the following CSS:
In a production build, this is flattened as:
This CSS is invalid because
:where(…)
doesn't accept relative selectors.But I expect it to be flattened as this instead:
Note: in dev mode (
vite dev
) it works as expected.Reproduction
https://github.com/RobinMalfait/vite-incorrect-css-flattening
Steps to reproduce
npm install
npm run dev
— open http://localhost:5173, the text should be rednpm run build
— open http://localhost:4173, the text should be red, but is blackSystem Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: