Skip to content

fix: three Tailwind 4 cascade regressions (.underline, .client, duplicated @apply utilities) - #60

Merged
moufmouf merged 3 commits into
mainfrom
fix/tailwind4-cascade-regressions
Aug 6, 2026
Merged

moufmouf merged 3 commits into
mainfrom
fix/tailwind4-cascade-regressions

Conversation

@moufmouf

@moufmouf moufmouf commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Three Tailwind-4 cascade regressions found while rebuilding workadventu.re against 3.0.3, plus a cleanup of the pattern that caused two of them.

All of these were invisible in the v3 → v4 migration diff, because Tailwind 3 emitted no cascade layers at all. Its output is flat, so plain source order decided everything. v4 puts the design system's rules in @layer base/@layer components and Tailwind's own utilities in @layer utilities, and layer order beats both specificity and source order — so outcomes flipped without anyone editing a rule.

1. .underline draws two underlines

.underline is the brush-stroke emphasis span. Since 3.0.0 it has rendered the stroke and a plain rule struck through the text.

The rule already asks for the right thing, and it is more specific than anything Tailwind generates — :is(h1,…,.h6) .underline is (0,2,0) against the utility's (0,1,0). It loses anyway, because the class name collides with Tailwind's built-in underline:

@layer base      { :is(h1,…,.h6) .underline { … text-decoration-line: none } }
@layer utilities { .underline { text-decoration-line: underline } }

Nothing a consumer writes on the element can reach it either.

Fix: restate the reset inside @layer utilities, where it is judged against the built-in on equal terms and the higher specificity finally settles it.

Deliberately not @utility underline { … } — that would replace Tailwind's built-in everywhere, so consumers could no longer use underline as a plain text-decoration utility outside a heading. This keeps the fix to the one place the design system owns. (@utility container in utilities/general.css is the opposite case, where replacing the built-in is exactly what you want.)

2. .client lays out at 6 per line instead of 4

.client { @apply grow list-none lg:basis-1/6 p-4 lg:basis-1/4; }
/*                              ^^^^^^^^^^^^     ^^^^^^^^^^^^ same property, twice */

Under v4 the winner is decided by the utilities' order in the generated sheet, not by the order written, and basis-1/6 comes out on top.

The knock-on effect is worse than the layout: .clients .client img is sm:w-full, so each logo resolves to the width of its squeezed box and every one renders at two thirds of its intended size. 25% is the value the original theme shipped, both unconditionally and inside its min-width: 1024px block.

Same class of mistake as the duplicated flex-row in .brick-feature (#57) — and released after that fix, which is why this PR also does the sweep below.

3. Duplicated utilities elsewhere (no output change)

I swept every @apply in src/ for two utilities from the same property group. Four sites; two were the bugs above, two are harmless but worth removing since this pattern has now caused two real regressions:

  • .nav-submenu listed flex and hidden, plus a second opacity-0 and a second absolute. The generated order happens to resolve to display: none, which is what the open state (display: block) expects — so it works today, by luck.
  • .possibilities listed items-center twice.

I also swept for the other pattern — component classes shadowed by a same-named built-in utility — by generating every one of the 263 class names this package defines through a real Tailwind 4 build and diffing against @layer utilities. .underline is the only genuine collision. The other 19 hits are the package's own @utility definitions (.h1–.h4, .paragraph*, .container, .bg-blur, .brick, .cursor, .col-3/4), which override their built-ins on purpose.

Verified

Against the built example in Chrome:

Result
.underline in <h2> and in <div class="h3"> text-decoration-line: none, 6px stroke intact
.underline in a <p> (control) still underline, no stroke — not a breaking change
.clients .client at ≥1024px flex-basis: 25%
.nav-submenu display: none closed, block open — unchanged

The example gains an "Emphasis inside a title" sample showing .underline and .highlight, which is what would have caught #1 by eye.

Not in this PR

The heading type scale (42/34/28/24/18/18) is smaller than the theme workadventu.re actually ships (44/40/36/32/28/24), widening to −36% at h5. That is not a v4 regression — v2.0.4's theming/fontSize.ts carries the same tokens — so the two scales simply never agreed. The site overrides it locally for now. If this package is meant to describe that site, its heading scale should probably become those numbers; happy to open a separate PR, but it changes every consumer so it wants a deliberate decision.

🤖 Generated with Claude Code

`.underline` is the brush-stroke emphasis span: a blue word with the hand-drawn
underline.svg painted under it by an `::after`. It has been rendering with TWO
underlines since 3.0.0 — the brush stroke and a plain rule struck through the
text.

The rule already asks for the right thing (`@apply relative no-underline …`), and
it is more specific than anything Tailwind generates: `:is(h1,…,.h6) .underline`
is (0,2,0) against the utility's (0,1,0). It loses anyway, because the class name
collides with Tailwind's built-in `underline` utility and cascade layers beat
specificity:

    @layer base      { :is(h1,…,.h6) .underline { … text-decoration-line: none } }
    @layer utilities { .underline { text-decoration-line: underline } }

Nothing a consumer writes on the element can reach it either.

This was invisible in the Tailwind 3 -> 4 migration diff, which is why it slipped
through: v3 emitted no cascade layers at all, so plain source order decided it and
the component rule — emitted after the utility — won.

Restated inside `@layer utilities` so it is judged against the built-in on equal
terms, where the higher specificity finally settles it. Deliberately NOT
`@utility underline { … }`: that would replace Tailwind's built-in everywhere and
consumers could no longer use `underline` as a plain text-decoration utility.

Verified in the built example: inside an `<h2>` and inside a `<div class="h3">`
the span computes `text-decoration-line: none` with the 6px stroke intact, while
an `.underline` in a `<p>` still computes `underline` and gets no stroke.

The example gains an "Emphasis inside a title" sample showing `.underline` and
`.highlight`, which is what would have caught this by eye.
`.client` applied `flex-basis` twice in one `@apply` — `lg:basis-1/6` and
`lg:basis-1/4`. Under Tailwind 4 the winner is decided by the utilities' order in
the generated stylesheet rather than by the order written, and `basis-1/6` came
out on top, so the row laid out at 6 per line instead of 4.

The knock-on effect is worse than the layout: `.clients .client img` is
`sm:w-full`, so each logo resolves to the width of its squeezed box and every one
renders at two thirds of its intended size.

25% is the value the original theme shipped, unconditionally and inside its
`min-width: 1024px` block.

Same class of mistake as the duplicated `flex-row` in `.brick-feature` (#57).
Neither changes a byte of emitted CSS; both remove the trap that produced #57 and
the `.client` basis bug.

`.nav-submenu` listed `flex` and `hidden` in the same `@apply`, plus a second
`opacity-0` and a second `absolute`. The generated order happens to resolve to
`display: none`, which is what the open state (`display: block`) expects — but a
duplicated `display` inside one `@apply` is exactly what silently broke
`.brick-feature`.

`.possibilities` listed `items-center` twice.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Tailwind v4 cascade-layer regressions where layer order caused previously-correct component styling to be overridden by built-in utilities, and removes duplicated/conflicting utilities in @apply blocks to prevent similar breakages.

Changes:

  • Fixes heading .underline so it no longer inherits Tailwind’s built-in underline text decoration under v4 layer ordering by restating the reset in @layer utilities.
  • Removes duplicated/conflicting utilities in @apply for .client (fixing lg:basis-* layout) and .nav-submenu / .possibilities (cleanup to avoid future cascade traps).
  • Adds an example snippet to visually cover emphasis styling inside headings.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/components/possibilities.css Removes redundant items-center from the @apply list to eliminate duplicated utilities.
src/components/nav.css Cleans up conflicting/duplicated @apply utilities for .nav-submenu while preserving the open/closed behavior (hidden → block).
src/components/clients.css Removes conflicting lg:basis-* utilities so lg:basis-1/4 consistently wins under Tailwind v4.
src/base/index.css Adds a targeted @layer utilities override so heading .underline correctly resets text-decoration-line under v4 cascade layers.
example/index.html Adds a heading example that exercises .underline and .highlight together for visual verification.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@moufmouf
moufmouf merged commit 8d86fb3 into main Aug 6, 2026
3 checks passed
@moufmouf
moufmouf deleted the fix/tailwind4-cascade-regressions branch August 6, 2026 07:34
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

Successfully merging this pull request may close these issues.

2 participants