tailwindlabs / tailwindcss

A utility-first CSS framework for rapid UI development.
https://tailwindcss.com/
MIT License
83.18k stars 4.22k forks source link

media-query duplicates its generated styles #14222

Open Tobitubbie opened 3 months ago

Tobitubbie commented 3 months ago

What version of Tailwind CSS are you using? v3.4.10 (tested in v3.4.4, too)

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

What version of Node.js are you using? v18.20.1

What browser are you using? Chrome

What operating system are you using? Windows

Reproduction URL https://play.tailwindcss.com/4aiEEar1oo?file=config

Describe your issue

The 3 preconditions for the error to occur are:

Every style (key of the object) defined for the media-query is repeated x times in the final generated css!


2 times on sibling css:

'@media (...)': { 
  '.a': {...}, 
  '.b': {...} 
}

=> results in:

@media (...): { 
  '.a':  {...}, 
  '.b':  {...}, 

  '.a':  {...}, 
  '.b':  {...} 
}

3 times on nested css:

'@media (...)': { 
  '.a': { '.b': {...} } 
}

=> results in:

'@media': { 
  '.a .b':  {...}, 

  '.a .b':  {...}, 

  '.a .b':  {...}
}

5 nested properties ( a { b { c { d { e } } } } ) lead to 15 duplications

This is increasing our final stylesheet quite a bit 🥲

Is this intended behaviour or am I doing something wrong?

monixca345 commented 1 month ago

Thanks for the step by step tutorial. Works like a charm! The solution worked for me thanks to the community and the members for the solution. aa jetnet