Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ensure spacing utilities with no value (e.g. px) don't generate CSS
  • Loading branch information
adamwathan committed Nov 7, 2024
commit c9c56942fd22dcdeb288bd5533c7b3aa8635e26b
16 changes: 16 additions & 0 deletions packages/tailwindcss/src/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16124,6 +16124,22 @@ describe('spacing utilities', () => {
}"
`)
})

test('spacing utilities must have a value', async () => {
let { build } = await compile(css`
@theme {
--spacing: 4px;
}
@tailwind utilities;
`)
let compiled = build(['px'])

expect(optimizeCss(compiled).trim()).toMatchInlineSnapshot(`
":root {
--spacing: 4px;
}"
`)
})
})

describe('custom utilities', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/tailwindcss/src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ export function createUtilities(theme: Theme) {
// `defaultValue` (for candidates like `grow` that have no theme values)
// or a bare theme value (like `--radius` for `rounded`). No utility
// will ever support both of these.
value = desc.defaultValue ?? theme.resolve(null, desc.themeKeys ?? [])
value =
desc.defaultValue !== undefined
? desc.defaultValue
: theme.resolve(null, desc.themeKeys ?? [])
} else if (candidate.value.kind === 'arbitrary') {
if (candidate.modifier) return
value = candidate.value.value
Expand Down Expand Up @@ -394,6 +397,7 @@ export function createUtilities(theme: Theme) {
themeKeys,
supportsFractions,
supportsNegative,
defaultValue: null,
handleBareValue: ({ value }) => {
let multiplier = theme.resolve(null, ['--spacing'])
if (!multiplier) return null
Expand Down