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

Minification breaks nested @apply #14092

Closed
pokonski opened this issue Jul 31, 2024 · 3 comments
Closed

Minification breaks nested @apply #14092

pokonski opened this issue Jul 31, 2024 · 3 comments

Comments

@pokonski
Copy link

What version of Tailwind CSS are you using?

For example: v3.4.7

What build tool (or framework if it abstracts the build tool) are you using?

tailwindcss standalone executable 3.4.7

What version of Node.js are you using?

N/A, using standalone

What browser are you using?

Firefox 127

What operating system are you using?

MacOS

Reproduction URL

https://github.com/pokonski/tailwind-minify-nesting/tree/master

Describe your issue

Minification breaks nested rules and flattens them:

Source file

.parent {
  & .child {
    @apply text-blue-500;

    &:not([href]) {
      @apply text-red-500;
    }
  }
}

Running tailwindcss -i source.css -o build.css outputs working CSS:

.parent {
  & .child {
    --tw-text-opacity: 1;
    color: rgb(59 130 246 / var(--tw-text-opacity))
  }
  & .child {
    &:not([href]) {
      --tw-text-opacity: 1;
      color: rgb(239 68 68 / var(--tw-text-opacity))
    }
  }
}

But running tailwindcss -i source.css -o build-min.css -m outputs broken CSS with missing nested rules:
(formatted by me for readability)

.parent {
  & .child {
    --tw-text-opacity: 1;
    color: rgb(239 68 68/var(--tw-text-opacity));
    color: rgb(59 130 246/var(--tw-text-opacity))
  }
}
@adamwathan
Copy link
Member

Super weird, can reproduce even without using @apply by just using this as the source CSS:

.parent {
  & .child {
    --tw-text-opacity: 1;
    color: rgb(59 130 246 / var(--tw-text-opacity))
  }
  & .child {
    &:not([href]) {
      --tw-text-opacity: 1;
      color: rgb(239 68 68 / var(--tw-text-opacity))
    }
  }
}

My first instinct is this is a bug in cssnano that has maybe been fixed (we're on v6 internally and it looks like v7 is out now) so going to see if that helps. Thanks for raising!

@pokonski
Copy link
Author

pokonski commented Aug 2, 2024

Thank you for looking into this @adamwathan ! Looks like @thecrypticace already spotted the problem that was indeed in cssnano :) The issue was addressed in cssnano 6.0.1: cssnano/cssnano@eb9a9a1

thecrypticace added a commit that referenced this issue Aug 2, 2024
We bundle cssnano in our CLI and it's on an older version that does not
handle nested CSS correctly. This PR updates it to the latest version of
v6.x

Fixes #14092
@thecrypticace
Copy link
Contributor

I've merged the fix for it and it'll be available in the next patch release. In the meantime you can use our insiders build which has the fix:

npm tailwindcss@insiders

stuartc added a commit to OpenFn/lightning that referenced this issue Oct 1, 2024
stuartc added a commit to OpenFn/lightning that referenced this issue Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants