Skip to content

Commit b1fb02a

Browse files
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
1 parent 1602e78 commit b1fb02a

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Discard matched variants with non-string values ([#18799](https://github.com/tailwindlabs/tailwindcss/pull/18799))
1919
- Show suggestions for known `matchVariant` values ([#18798](https://github.com/tailwindlabs/tailwindcss/pull/18798))
2020
- Replace deprecated `clip` with `clip-path` in `sr-only` ([#18769](https://github.com/tailwindlabs/tailwindcss/pull/18769))
21+
- Hide internal fields from completions in `matchUtilities` ([#18820](https://github.com/tailwindlabs/tailwindcss/pull/18820))
2122
- Upgrade: Migrate `aria` theme keys to `@custom-variant` ([#18815](https://github.com/tailwindlabs/tailwindcss/pull/18815))
2223
- Upgrade: Migrate `data` theme keys to `@custom-variant` ([#18816](https://github.com/tailwindlabs/tailwindcss/pull/18816))
2324
- Upgrade: Migrate `supports` theme keys to `@custom-variant` ([#18817](https://github.com/tailwindlabs/tailwindcss/pull/18817))

packages/tailwindcss/src/compat/plugin-api.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ export function buildPluginApi({
472472
// work even with legacy configs and plugins
473473
valueKeys.delete('__BARE_VALUE__')
474474

475+
// The `__CSS_VALUES__` key is a special key used by the theme function
476+
// to transport `@theme` metadata about values from CSS
477+
valueKeys.delete('__CSS_VALUES__')
478+
475479
// The `DEFAULT` key is represented as `null` in the utility API
476480
if (valueKeys.has('DEFAULT')) {
477481
valueKeys.delete('DEFAULT')

packages/tailwindcss/src/intellisense.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,3 +712,38 @@ test('matchVariant', async () => {
712712
expect(v1.name).toEqual('foo')
713713
expect(v1.values).toEqual(['a', 'b'])
714714
})
715+
716+
test('matchUtilities discards internal only helpers from suggestions when using the theme function', async () => {
717+
let input = css`
718+
@import 'tailwindcss/utilities';
719+
@plugin "./plugin.js";
720+
721+
@theme {
722+
--color-red: red;
723+
}
724+
`
725+
726+
let design = await __unstable__loadDesignSystem(input, {
727+
loadStylesheet: async (_, base) => ({
728+
path: '',
729+
base,
730+
content: '@tailwind utilities;',
731+
}),
732+
loadModule: async () => ({
733+
path: '',
734+
base: '',
735+
module: plugin(({ matchUtilities, theme }) => {
736+
matchUtilities({ foo: (val) => ({ color: val }) }, { values: theme('colors') })
737+
matchUtilities({ bar: (val) => ({ color: val }) }, { values: theme('transitionDuration') })
738+
}),
739+
}),
740+
})
741+
742+
let classNames = design.getClassList().map((e) => e[0])
743+
744+
expect(classNames).not.toContain('foo-__BARE_VALUE__')
745+
expect(classNames).not.toContain('bar-__BARE_VALUE__')
746+
747+
expect(classNames).not.toContain('foo-__CSS_VALUES__')
748+
expect(classNames).not.toContain('bar-__CSS_VALUES__')
749+
})

0 commit comments

Comments
 (0)