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)))]'],