From 2b5be1875bab988df84db1858082d0c962b252f7 Mon Sep 17 00:00:00 2001 From: sudeepgowda55 Date: Sat, 14 Nov 2026 21:39:21 +0530 Subject: [PATCH] Canonicalization: keep whitespace-only arbitrary property values --- .changelog/canonicalize-whitespace-only-value.md | 3 +++ packages/tailwindcss/src/candidate.ts | 7 ++++++- packages/tailwindcss/src/canonicalize-candidates.test.ts | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changelog/canonicalize-whitespace-only-value.md diff --git a/.changelog/canonicalize-whitespace-only-value.md b/.changelog/canonicalize-whitespace-only-value.md new file mode 100644 index 000000000000..83f22e3f8d38 --- /dev/null +++ b/.changelog/canonicalize-whitespace-only-value.md @@ -0,0 +1,3 @@ +### Fixed + +- Canonicalization: keep the value of arbitrary properties that only contain whitespace (e.g. `[--foo:_]` no longer becomes `[--foo:]`) diff --git a/packages/tailwindcss/src/candidate.ts b/packages/tailwindcss/src/candidate.ts index 6e32f0dc1cab..89dc2d0955dd 100644 --- a/packages/tailwindcss/src/candidate.ts +++ b/packages/tailwindcss/src/candidate.ts @@ -1149,7 +1149,12 @@ const printArbitraryValueCache = new DefaultMap((input) => { } // Leading and trailing whitespace - else if (node.kind === 'separator' && node.value.length > 0 && node.value.trim() === '') { + else if ( + node.kind === 'separator' && + node.value.length > 0 && + node.value.trim() === '' && + ctx.siblings.length > 1 + ) { if (ctx.siblings[0] === node || ctx.siblings[ctx.siblings.length - 1] === node) { drop.add(node) } diff --git a/packages/tailwindcss/src/canonicalize-candidates.test.ts b/packages/tailwindcss/src/canonicalize-candidates.test.ts index 1c23608b4e31..6f300c2f5abf 100644 --- a/packages/tailwindcss/src/canonicalize-candidates.test.ts +++ b/packages/tailwindcss/src/canonicalize-candidates.test.ts @@ -1413,6 +1413,7 @@ describe.each([['default'], ['with-variant'], ['important'], ['prefix']])('%s', 'shadow-[inset_0px_1px_--theme(--color-white/15%)]', 'shadow-[inset_0px_1px_--theme(--color-white/15%)]', ], + ['[--foo:_]', '[--foo:_]'], // Improve readability when whitespace was used for readability ['w-[calc(100%_-_calc(var(--spacing)*60))]', 'w-[calc(100%-(--spacing(60)))]'],