diff --git a/CHANGELOG.md b/CHANGELOG.md index 5292d918cc87..375288258a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - _Experimental_: Add `@container-size` utility ([#18901](https://github.com/tailwindlabs/tailwindcss/pull/18901)) +### Fixed + +- Discard candidates with an empty data type ([#19172](https://github.com/tailwindlabs/tailwindcss/pull/19172)) + ## [4.1.15] - 2025-10-20 ### Fixed diff --git a/packages/tailwindcss/src/candidate.test.ts b/packages/tailwindcss/src/candidate.test.ts index 3d4aa983b2a0..53d21dda695f 100644 --- a/packages/tailwindcss/src/candidate.test.ts +++ b/packages/tailwindcss/src/candidate.test.ts @@ -1776,6 +1776,14 @@ it('should not parse compound group with a non-compoundable variant', () => { expect(run('group-*:flex', { utilities, variants })).toMatchInlineSnapshot(`[]`) }) +it('empty data types are invalid', () => { + let utilities = new Utilities() + utilities.functional('bg', () => []) + let variants = new Variants() + + expect(run('bg-[:foo]', { utilities, variants })).toMatchInlineSnapshot(`[]`) +}) + it('should parse a variant containing an arbitrary string with unbalanced parens, brackets, curlies and other quotes', () => { let utilities = new Utilities() utilities.static('flex', () => []) diff --git a/packages/tailwindcss/src/candidate.ts b/packages/tailwindcss/src/candidate.ts index c081c3b472b8..fa8cd3047e6d 100644 --- a/packages/tailwindcss/src/candidate.ts +++ b/packages/tailwindcss/src/candidate.ts @@ -554,7 +554,7 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter if (!isValidArbitrary(arbitraryValue)) continue // Extract an explicit typehint if present, e.g. `bg-[color:var(--my-var)])` - let typehint = '' + let typehint: string | null = null for (let i = 0; i < arbitraryValue.length; i++) { let code = arbitraryValue.charCodeAt(i) @@ -580,6 +580,8 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter continue } + if (typehint === '') continue + candidate.value = { kind: 'arbitrary', dataType: typehint || null,