From b45838bc671d0ecabe55c82ee443bc5ea10a56b7 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 3 Oct 2024 16:22:13 -0400 Subject: [PATCH 1/3] =?UTF-8?q?Don=E2=80=99t=20crash=20when=20scanning=20c?= =?UTF-8?q?andidate=20matching=20the=20prefix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/tailwindcss/src/candidate.ts | 2 +- packages/tailwindcss/src/prefix.test.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/tailwindcss/src/candidate.ts b/packages/tailwindcss/src/candidate.ts index 02fa4aaa8a28..b602fbb1a993 100644 --- a/packages/tailwindcss/src/candidate.ts +++ b/packages/tailwindcss/src/candidate.ts @@ -229,7 +229,7 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter // A prefix is a special variant used to prefix all utilities. When present, // all utilities must start with that variant which we will then remove from // the variant list so no other part of the codebase has to know about it. - if (designSystem.theme.prefix) { + if (designSystem.theme.prefix && rawVariants.length > 1) { if (rawVariants[0] !== designSystem.theme.prefix) return null rawVariants.shift() diff --git a/packages/tailwindcss/src/prefix.test.ts b/packages/tailwindcss/src/prefix.test.ts index 7841c3076544..17cea3eb6d76 100644 --- a/packages/tailwindcss/src/prefix.test.ts +++ b/packages/tailwindcss/src/prefix.test.ts @@ -333,3 +333,19 @@ test('a prefix must be letters only', async () => { `[Error: The prefix "__" is invalid. Prefixes must be lowercase ASCII letters (a-z) only.]`, ) }) + +test('a candidate matching the prefix does not crash', async () => { + let input = css` + @theme reference prefix(tomato); + @tailwind utilities; + ` + + let compiler = await compile(input) + + expect(compiler.build(['tomato', 'tomato:flex'])).toMatchInlineSnapshot(` + ".tomato\\:flex { + display: flex; + } + " + `) +}) From ec0a4cb11023a165ee6be324a54eeab313367b1a Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 3 Oct 2024 16:25:28 -0400 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74d7628d7cef..c6be95ffc9a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -- Nothing yet! +### Fixed + +- Don’t crash when scanning a candidate equal to the configured prefix ([#14588](https://github.com/tailwindlabs/tailwindcss/pull/14588)) ## [4.0.0-alpha.26] - 2024-10-03 From d88681495c40462c2d70845b5e3b1806ffe2df11 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Thu, 3 Oct 2024 16:28:07 -0400 Subject: [PATCH 3/3] wip --- packages/tailwindcss/src/candidate.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/tailwindcss/src/candidate.ts b/packages/tailwindcss/src/candidate.ts index b602fbb1a993..9738c9b0f8c8 100644 --- a/packages/tailwindcss/src/candidate.ts +++ b/packages/tailwindcss/src/candidate.ts @@ -229,7 +229,8 @@ export function* parseCandidate(input: string, designSystem: DesignSystem): Iter // A prefix is a special variant used to prefix all utilities. When present, // all utilities must start with that variant which we will then remove from // the variant list so no other part of the codebase has to know about it. - if (designSystem.theme.prefix && rawVariants.length > 1) { + if (designSystem.theme.prefix) { + if (rawVariants.length === 1) return null if (rawVariants[0] !== designSystem.theme.prefix) return null rawVariants.shift()