Repository navigation
Reject bare color opacity modifiers above 100 - #20609
otarampinelli wants to merge 6 commits into
Conversation
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
[Medium impact] This PR appears safe to merge. Reviews (5) · Last reviewed commit: "Add changelog fragment for #20609" · Reviewed by Greptile |
|
The failing test it's caused by bun I checked locally with the same |
|
I have a PR fixing that bun version CI failure for now, but is should pass for newer version later, this is pinning the version of the test to use |
|
CI test failures solved on #20650 |
…ng utility tests Each utility test already has a list of invalid candidates. The cases for `bg`, `text`, `border-*`, `shadow`, `inset-shadow`, `text-shadow` and `drop-shadow` now live there, with `--color-red-500` in the theme so that they are dropped because of the modifier, not because of an unknown color.
The size form of `shadow-*`, `inset-shadow-*`, `text-shadow-*` and `drop-shadow-*` computed its own alpha, outside of `asColor(…)`. So `shadow-lg/150` still generated `--tw-shadow-alpha: 150%`. Together with a shadow color, this resolves to `color-mix(…, 150%, …)`, which makes the whole `box-shadow` invalid. The rule now lives in one `bareAlpha(…)` helper, which `asColor(…)` and the 4 shadow utilities use.
`matchUtilities(…, { type: 'color' })` doesn't use `asColor(…)`, and
turned any number into a percentage. So `plugin-red-500/150` still
generated `color-mix(…, 150%, …)`.
`main` now collects changelog entries as fragments in `.changelog/`, so the entry goes there instead of in `CHANGELOG.md`.
Summary
Bare opacity modifiers only check if the value isn't negative or it's a multiple of
0.25, with none validation for values above100for opacity, sobg-red-500/150generates a bad value likecolor-mix(in oklab, var(--color-red-500) 150%, transparent), browser rejectscolor-mix()percentages above 100%, so the declaration is silently droppedThe solution is rejecting bare values above 100 in
asColor()which also covers theshadow,inset-shadow,text-shadowanddrop-shadow, the sharedisValidOpacityValueis unchanged becauseopacity-150orbackdorp-opacity-150are valid, browser clamps themTailwind play with some evidences
Test plan
New test invalid bare color opacity modifiers: checks that
/101,/150,/500,/100.25and/2.3on color and shadow utilities generate no css, it fails when running against mainadded
opacity-150to the opacity test, checks that plain opacity still works above 100,opacity: 1.5, which the browser clampspnpm exec vitest run --project tailwindcss packages/tailwindcss/src/utilities.test.ts