From d85b4b83e6c6dcbe119af348d96c70300d6e7c00 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 22 Mar 2023 10:16:31 -0400 Subject: [PATCH 1/3] Remove blocklisted classes from autocomplete --- src/lib/setupContextUtils.js | 3 +++ tests/getClassList.test.js | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/lib/setupContextUtils.js b/src/lib/setupContextUtils.js index 0749da68dbdc..854ea7335736 100644 --- a/src/lib/setupContextUtils.js +++ b/src/lib/setupContextUtils.js @@ -1007,6 +1007,9 @@ function registerPlugins(plugins, context) { } } + // Exclude utilities that are known non-classes (e.g. from the blocklist) + output = output.filter((cls) => !context.notClassCache.has(cls)) + return output } diff --git a/tests/getClassList.test.js b/tests/getClassList.test.js index 671a767ecfe5..06e8dd345538 100644 --- a/tests/getClassList.test.js +++ b/tests/getClassList.test.js @@ -191,6 +191,18 @@ crosscheck(() => { expect(classes).not.toContain('bg-red-500/50') }) + it('should not generate utilities that are present in the blocklist', () => { + let config = { + blocklist: ['font-bold'], + } + + let context = createContext(resolveConfig(config)) + let classes = context.getClassList() + + expect(classes).toContain('font-normal') + expect(classes).not.toContain('font-bold') + }) + it('should not generate utilities that are set to undefined or null to so that they are removed', () => { let config = { theme: { From cdc2596ea48c2e25858684a03346fb8c9bda1fe7 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 22 Mar 2023 10:18:04 -0400 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13c37104d86a..b06102bc1006 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Disallow multiple selectors in arbitrary variants ([#10655](https://github.com/tailwindlabs/tailwindcss/pull/10655)) - Sort class lists deterministically for Prettier plugin ([#10672](https://github.com/tailwindlabs/tailwindcss/pull/10672)) - Ensure CLI builds have a non-zero exit code on failure ([#10703](https://github.com/tailwindlabs/tailwindcss/pull/10703)) +- Remove blocklisted classes from autocomplete ([#10844](https://github.com/tailwindlabs/tailwindcss/pull/10844)) ### Changed From 3332eb620a0fc6b4269e68e2fcfca5d335640aac Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Wed, 22 Mar 2023 10:41:45 -0400 Subject: [PATCH 3/3] Don't unnecessarily loop over classes Co-authored-by: Robin Malfait --- src/lib/setupContextUtils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/setupContextUtils.js b/src/lib/setupContextUtils.js index 854ea7335736..e17ba43c1096 100644 --- a/src/lib/setupContextUtils.js +++ b/src/lib/setupContextUtils.js @@ -1008,7 +1008,9 @@ function registerPlugins(plugins, context) { } // Exclude utilities that are known non-classes (e.g. from the blocklist) - output = output.filter((cls) => !context.notClassCache.has(cls)) + if (context.notClassCache.size > 0) { + output = output.filter((cls) => !context.notClassCache.has(cls)) + } return output }