Hide internal fields from completions in matchUtilities (#18820)

The `__CSS_VALUES__` field is an internal field we use to transport data
about theme options from CSS throug hte JS plugin API. It wasn’t
supposed to show up in suggestions but we forgot to remove it from them.

Fixes #18812
This commit is contained in:
Jordan Pittman 2025-08-29 11:01:20 -04:00 committed by GitHub
parent 1602e7866d
commit b1fb02a2d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 40 additions and 0 deletions

View File

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Discard matched variants with non-string values ([#18799](https://github.com/tailwindlabs/tailwindcss/pull/18799))
- Show suggestions for known `matchVariant` values ([#18798](https://github.com/tailwindlabs/tailwindcss/pull/18798))
- Replace deprecated `clip` with `clip-path` in `sr-only` ([#18769](https://github.com/tailwindlabs/tailwindcss/pull/18769))
- Hide internal fields from completions in `matchUtilities` ([#18820](https://github.com/tailwindlabs/tailwindcss/pull/18820))
- Upgrade: Migrate `aria` theme keys to `@custom-variant` ([#18815](https://github.com/tailwindlabs/tailwindcss/pull/18815))
- Upgrade: Migrate `data` theme keys to `@custom-variant` ([#18816](https://github.com/tailwindlabs/tailwindcss/pull/18816))
- Upgrade: Migrate `supports` theme keys to `@custom-variant` ([#18817](https://github.com/tailwindlabs/tailwindcss/pull/18817))

View File

@ -472,6 +472,10 @@ export function buildPluginApi({
// work even with legacy configs and plugins
valueKeys.delete('__BARE_VALUE__')
// The `__CSS_VALUES__` key is a special key used by the theme function
// to transport `@theme` metadata about values from CSS
valueKeys.delete('__CSS_VALUES__')
// The `DEFAULT` key is represented as `null` in the utility API
if (valueKeys.has('DEFAULT')) {
valueKeys.delete('DEFAULT')

View File

@ -712,3 +712,38 @@ test('matchVariant', async () => {
expect(v1.name).toEqual('foo')
expect(v1.values).toEqual(['a', 'b'])
})
test('matchUtilities discards internal only helpers from suggestions when using the theme function', async () => {
let input = css`
@import 'tailwindcss/utilities';
@plugin "./plugin.js";
@theme {
--color-red: red;
}
`
let design = await __unstable__loadDesignSystem(input, {
loadStylesheet: async (_, base) => ({
path: '',
base,
content: '@tailwind utilities;',
}),
loadModule: async () => ({
path: '',
base: '',
module: plugin(({ matchUtilities, theme }) => {
matchUtilities({ foo: (val) => ({ color: val }) }, { values: theme('colors') })
matchUtilities({ bar: (val) => ({ color: val }) }, { values: theme('transitionDuration') })
}),
}),
})
let classNames = design.getClassList().map((e) => e[0])
expect(classNames).not.toContain('foo-__BARE_VALUE__')
expect(classNames).not.toContain('bar-__BARE_VALUE__')
expect(classNames).not.toContain('foo-__CSS_VALUES__')
expect(classNames).not.toContain('bar-__CSS_VALUES__')
})