Skip to content

Commit d325e70

Browse files
Convert , to in grid-cols-[…], grid-rows-[…], and object-[…] (#14927)
This PR converts legacy commas in arbitrary values to spaces. In Tailwind CSS v3, we allowed commas in arbitrary values for `grid-cols-[…]`, `grid-rows-[…]`, and `object-[…]` for backwards compatibility. The underlying CSS value did use spaces instead of commas. This PR adds a code mod where convert the commas to spaces when we see them. Test plan: --- Running this on Catalyst it goes from this: <img width="393" alt="image" src="https://github.com/user-attachments/assets/03cbda73-41f9-4601-b77a-5b511226b876"> To the expected value of: <img width="376" alt="image" src="https://github.com/user-attachments/assets/dd9bbe01-5eb1-4340-937b-70c435e7e4f0"> --------- Co-authored-by: Adam Wathan <[email protected]>
1 parent 9c41ce8 commit d325e70

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4444
- _Upgrade (experimental)_: Remove whitespace around `,` separator when print arbitrary values ([#14838](https://github.com/tailwindlabs/tailwindcss/pull/14838))
4545
- _Upgrade (experimental)_: Fix crash during upgrade when content globs escape root of project ([#14896](https://github.com/tailwindlabs/tailwindcss/pull/14896))
4646
- _Upgrade (experimental)_: Don't convert `theme(…/15%)` to modifier unless it is the entire arbitrary value of a utility ([#14922](https://github.com/tailwindlabs/tailwindcss/pull/14922))
47+
- _Upgrade (experimental)_: Convert `,` to ` ` in arbitrary `grid-cols-*`, `grid-rows-*`, and `object-*` values ([#14927](https://github.com/tailwindlabs/tailwindcss/pull/14927))
4748

4849
### Changed
4950

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { __unstable__loadDesignSystem } from '@tailwindcss/node'
2+
import { expect, test } from 'vitest'
3+
import { legacyArbitraryValues } from './legacy-arbitrary-values'
4+
5+
test.each([
6+
['grid-cols-[auto,1fr]', 'grid-cols-[auto_1fr]'],
7+
['grid-rows-[auto,1fr]', 'grid-rows-[auto_1fr]'],
8+
['object-[10px,20px]', 'object-[10px_20px]'],
9+
])('%s => %s', async (candidate, result) => {
10+
let designSystem = await __unstable__loadDesignSystem('@import "tailwindcss";', {
11+
base: __dirname,
12+
})
13+
14+
expect(legacyArbitraryValues(designSystem, {}, candidate)).toEqual(result)
15+
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Config } from 'tailwindcss'
2+
import { parseCandidate } from '../../../../tailwindcss/src/candidate'
3+
import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
4+
import { segment } from '../../../../tailwindcss/src/utils/segment'
5+
import { printCandidate } from '../candidates'
6+
7+
export function legacyArbitraryValues(
8+
designSystem: DesignSystem,
9+
_userConfig: Config,
10+
rawCandidate: string,
11+
): string {
12+
for (let candidate of parseCandidate(rawCandidate, designSystem)) {
13+
let clone = structuredClone(candidate)
14+
let changed = false
15+
16+
// Convert commas to spaces. E.g.: [auto,1fr] to [auto_1fr]
17+
if (
18+
clone.kind === 'functional' &&
19+
clone.value?.kind === 'arbitrary' &&
20+
(clone.root === 'grid-cols' || clone.root == 'grid-rows' || clone.root == 'object')
21+
) {
22+
changed = true
23+
clone.value.value = segment(clone.value.value, ',').join(' ')
24+
}
25+
26+
return changed ? printCandidate(designSystem, clone) : rawCandidate
27+
}
28+
29+
return rawCandidate
30+
}

packages/@tailwindcss-upgrade/src/template/migrate.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { arbitraryValueToBareValue } from './codemods/arbitrary-value-to-bare-va
77
import { automaticVarInjection } from './codemods/automatic-var-injection'
88
import { bgGradient } from './codemods/bg-gradient'
99
import { important } from './codemods/important'
10+
import { legacyArbitraryValues } from './codemods/legacy-arbitrary-values'
1011
import { maxWidthScreen } from './codemods/max-width-screen'
1112
import { modernizeArbitraryValues } from './codemods/modernize-arbitrary-values'
1213
import { prefix } from './codemods/prefix'
@@ -35,6 +36,7 @@ export const DEFAULT_MIGRATIONS: Migration[] = [
3536
themeToVar,
3637
variantOrder, // Has to happen before migrations that modify variants
3738
automaticVarInjection,
39+
legacyArbitraryValues,
3840
arbitraryValueToBareValue,
3941
modernizeArbitraryValues,
4042
]

0 commit comments

Comments
 (0)