Skip to content
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

[v4][cli] The --minify and --optimize options remove CSS from output #16478

Open
MariusVatasoiu opened this issue Feb 12, 2025 · 2 comments
Open
Assignees
Labels

Comments

@MariusVatasoiu
Copy link

I have the following tailwind file and I get two different results when I use or not the --minify or --optimize flags.

@import "tailwindcss";

@custom-variant dark {
  &:where(.dark, .dark *) {
    @slot;
  }
  @container style(--dark-mode) {
    @slot;
  }
}

For this HTML:

<div class="dark:hidden">Hello</div>

Without the --minify or --optimize flags, I get:

@layer utilities {
  .dark\:hidden {
    &:where(.dark, .dark *) {
      display: none;
    }
    @container style(--dark-mode) {
      display: none;
    }
  }
}

With --minify or --optimize flags, I get:

.dark\:hidden:where(.dark,  .dark *){
  display:none;
}

The @container style(--dark-mode){...} part is removed, even though I need it for shadow DOM. If I remove &:where(.dark, .dark *) {...}, then I lose support for Light DOM in Firefox and older Chrome and Safari versions.

The issue seems to be in the optimize mechanism, since minify means minify + optimize.

@RobinMalfait RobinMalfait self-assigned this Feb 12, 2025
@RobinMalfait
Copy link
Member

RobinMalfait commented Feb 12, 2025

Hey!

This might be a Lightning CSS bug.

I first thought that your input CSS is invalid. A container query using style(…) should contain a valid condition and --dark-mode on its own is not. If you provide it the value you want to compare it to.

But according to the spec the value could be omitted and evaluates to true.

As a workaround until the bug is fixed upstream, one thing you can do is change the original implementation with a value.

  @import "tailwindcss";

  @custom-variant dark {
    &:where(.dark, .dark *) {
      @slot;
    }
-   @container style(--dark-mode) {
+   @container style(--dark-mode: 1) {
      @slot;
    }
  }

The value will depend on what you set the value to.

Will keep this open a little longer and will open an issue on Lightning CSS's issue tracker.

@MariusVatasoiu
Copy link
Author

You are right, using @container style(--dark-mode: 1) works as expected.

It's funny because I've omitted the value knowing it can be omitted.

Thanks a lot for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants