tailwindcss/packages
Jordan Pittman 5e2a160d8b
Drop exact duplicate declarations from output CSS within a style rule (#18809)
Fixes #18178

When someone writes a utility like `after:content-['foo']` it'll produce
duplicate `content: var(--tw-content)` declarations. I thought about
special casing these but we already have an optimization pass where we
perform a full walk of the AST, flattening some rules (with the `&`
selector), analyzing declarations, etc… We can utilize that existing
spot in core to analyze and remove duplicate declarations within rules
across the AST.

The implementation does this by keeping track of declarations within a
style rule and keeps the last one for any *exact duplicate* which is a
tuple of `(property, value, important)`. This does require some
additional loops but preseving the *last* declaration is important for
correctness with regards to CSS nesting.

For example take this nested CSS:
```css
.foo {
  color: red;
  & .bar {
    color: green;
  }
  color: red;
}
```

It expands to this:
```css
.foo {
  color: red;
}
.foo.bar {
  color: green;
}
.foo {
  color: red;
}
```

If you remove the *last* rule then a `<div class="foo bar">…</div>` will
have green text when its supposed to be red. Since that would affect
behavior we have to always preserve the last declaration for a given
property.

We could go further and eliminate multiple declarations for the same
property *but* this presents a problem: every property and value must be
understood and combined with browser targets to understand whether or
not that property may act as a "fallback" or whether definitely
overwrites its previous value in all cases. This is a much more
complicated task that is much more suited to something light Lighting
CSS.
2025-08-29 11:01:56 -04:00
..
@tailwindcss-browser Drop warning from browser build (#18732) 2025-08-14 12:20:19 -04:00
@tailwindcss-cli Prepare v4.1.12 release (#18728) 2025-08-14 14:35:49 +02:00
@tailwindcss-node Update magic-string 0.30.17 → 0.30.18 (minor) (#18821) 2025-08-29 14:22:19 +00:00
@tailwindcss-postcss Prepare v4.1.12 release (#18728) 2025-08-14 14:35:49 +02:00
@tailwindcss-standalone Prepare v4.1.12 release (#18728) 2025-08-14 14:35:49 +02:00
@tailwindcss-upgrade Migrate supports theme keys (#18817) 2025-08-28 14:50:48 +00:00
@tailwindcss-vite Prepare v4.1.12 release (#18728) 2025-08-14 14:35:49 +02:00
internal-example-plugin Prefix internal modules with internal-* (#14074) 2024-07-29 10:58:07 -04:00
tailwindcss Drop exact duplicate declarations from output CSS within a style rule (#18809) 2025-08-29 11:01:56 -04:00
tsconfig.base.json Improve debug logs (#15303) 2024-12-11 15:27:20 +01:00