Skip to content

Commit 65bad11

Browse files
authored
Do not migrate variant = 'outline' during upgrades (#18922)
This PR improves the upgrade tool for shadcn/ui projects where the `variant = "outline"` is incorrectly migrated to `variant = "outline-solid"`. This PR also handles a few more cases: ```ts // As default argument function Button({ variant = "outline", ...props }: ButtonProps) { } // With different kinds of quotes (single, double, backticks) function Button({ variant = 'outline', ...props }: ButtonProps) { } // Regardless of whitespace function Button({ variant="outline", ...props }: ButtonProps) { } // In JSX <Button variant="outline" /> // With different quotes and using JavaScript expressions <Button variant={'outline'} /> // As an object property buttonVariants({ variant: "outline" }) ```
1 parent d1fd645 commit 65bad11

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Do not generate `grid-column` utilities when configuring `grid-column-start` or `grid-column-end` ([#18907](https://github.com/tailwindlabs/tailwindcss/pull/18907))
2121
- Do not generate `grid-row` utilities when configuring `grid-row-start` or `grid-row-end` ([#18907](https://github.com/tailwindlabs/tailwindcss/pull/18907))
2222
- Prevent duplicate CSS when overwriting a static utility with a theme key ([#18056](https://github.com/tailwindlabs/tailwindcss/pull/18056))
23+
- Do not migrate `variant = 'outline'` during upgrades ([#18922](https://github.com/tailwindlabs/tailwindcss/pull/18922))
2324

2425
## [4.1.13] - 2025-09-03
2526

packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,18 @@ describe('is-safe-migration', async () => {
9191

9292
[`function foo(blur, foo)`, 'blur'],
9393
[`function foo(blur,foo)`, 'blur'],
94+
95+
// shadcn/ui variants
96+
[`<Button variant="outline" />`, 'outline'],
97+
[`<Button variant='outline' />`, 'outline'],
98+
[`<Button variant={"outline"} />`, 'outline'],
99+
[`<Button variant={'outline'} />`, 'outline'],
100+
[`function Button({ variant = "outline" }) {}`, 'outline'],
101+
[`function Button({ variant = 'outline' }) {}`, 'outline'],
102+
[`function Button({ variant="outline" }) {}`, 'outline'],
103+
[`function Button({ variant='outline' }) {}`, 'outline'],
104+
[`Button({ variant: "outline" })`, 'outline'],
105+
[`Button({ variant: 'outline' })`, 'outline'],
94106
])('does not replace classes in invalid positions #%#', async (example, candidate) => {
95107
expect(
96108
await migrateCandidate(designSystem, {}, candidate, {

packages/@tailwindcss-upgrade/src/codemods/template/is-safe-migration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ const CONDITIONAL_TEMPLATE_SYNTAX = [
1818
/x-if=['"]$/,
1919
/x-show=['"]$/,
2020
/wire:[^\s]*?$/,
21+
22+
// shadcn/ui variants
23+
/variant\s*[:=]\s*\{?['"`]$/,
2124
]
2225
const NEXT_PLACEHOLDER_PROP = /placeholder=\{?['"`]$/
2326
const VUE_3_EMIT = /\b\$?emit\(['"`]$/

0 commit comments

Comments
 (0)