Skip to content

Commit ef598fd

Browse files
committed
fix(canonicalize): collapse arbitrary values into shorthand utilities
`dynamicUtilities` — which discovers collapse targets by swapping utility roots — only handled named values. Arbitrary values like `px-[1.2rem] py-[1.2rem]` were never collapsed into `p-[1.2rem]`, even though they are equivalent. Relax the guard to allow root-swapping for arbitrary values (e.g., `px` → `p`). Fixes #19835
1 parent 17d324f commit ef598fd

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

packages/tailwindcss/src/canonicalize-candidates.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,3 +1310,19 @@ test(
13101310
)
13111311
},
13121312
)
1313+
1314+
test('collapse canonicalization works for arbitrary values', { timeout }, async () => {
1315+
let designSystem = await designSystems.get(__dirname).get(css`
1316+
@import 'tailwindcss';
1317+
`)
1318+
1319+
let options: CanonicalizeOptions = {
1320+
collapse: true,
1321+
logicalToPhysical: true,
1322+
rem: 16,
1323+
}
1324+
1325+
expect(
1326+
designSystem.canonicalizeCandidates(['px-[1.2rem]', 'py-[1.2rem]', 'text-left'], options),
1327+
).toEqual(['text-left', 'p-[1.2rem]'])
1328+
})

packages/tailwindcss/src/canonicalize-candidates.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,7 @@ function collapseCandidates(options: InternalCanonicalizeOptions, candidates: st
321321
if (relevantProperties.size === 0) return result
322322

323323
for (let parsedCandidate of parseCandidate(designSystem, candidate)) {
324-
if (
325-
parsedCandidate.kind !== 'functional' ||
326-
parsedCandidate.value?.kind !== 'named' // Necessary for bare values
327-
) {
324+
if (parsedCandidate.kind !== 'functional' || parsedCandidate.value === null) {
328325
continue
329326
}
330327

0 commit comments

Comments
 (0)