Canonicalization: make hex colors case insensitive - #20298
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThis change adds case-insensitive canonicalization for hex color values. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/tailwindcss/src/canonicalize-candidates.ts (2)
2547-2556: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low valueHex regex can match inside non-color string literals.
HEX_REGEXblindly scans the entire declaration value and lowercases any hash-prefixed hex-length sequence, including inside quoted string literals (e.g.content: "#FFF002"). Since this only affects the internal canonicalization/signature string (not real output), the practical risk is narrow, but it's a latent correctness gap if declarations with quoted hex-like content are ever canonicalized/compared.
2551-2555: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove the redundant
lastIndexreset.String.prototype.replace()already starts a global regex atlastIndex = 0, so this line can be dropped without changing behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: a7a2f9a8-9a1a-4a5a-bd31-2d22cc8cc17b
📒 Files selected for processing (2)
packages/tailwindcss/src/canonicalize-candidates.test.tspackages/tailwindcss/src/canonicalize-candidates.ts
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to the canonicalization comparison path and does not affect emitted CSS. The fix applies hex-color lowercasing only during signature comparison (canonicalizeAst), never to emitted CSS. The regex is correct for all valid CSS hex lengths (3, 4, 6, 8 digits), the global flag's lastIndex is reset defensively before each use, and CSS variable declarations are explicitly excluded. Tests cover both affected code paths and the original bug report. No files require special attention. Reviews (2): Last reviewed commit: "update changelog" | Re-trigger Greptile |
This PR fixes an issue where hex-based colors in arbitrary properties and values were considered case-sensitive even though they are case-insensitive in CSS.
If you look at the linked issue, there is this input CSS:
We expect that both
bg-[#3f3cbb]andbg-[#3F3CBB]get canonicalized tocolor-brand-purplebut before this pr, only the first one would get canonicalized that way (since it's a perfect match).Technically a bunch more values are case-insensitive but a lot of them are sensitive so to get this 100% correct, a lot more parsing needs to happen. I think we can start with this and expand the logic when needed.
Fixes: #20295
Test plan
[color:#fff]vs[color:#FFF]), and tests for arbitrary properties (bg-[#fff]vsbg-[#FFF])