Skip to content

Fix fontSize array upgrade #17630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Ensure the `color-mix(…)` polyfill creates fallbacks for theme variables that reference other theme variables ([#17562](https://github.com/tailwindlabs/tailwindcss/pull/17562))
- Fix brace expansion in `@source inline('z-{10..0}')` with range going down ([#17591](https://github.com/tailwindlabs/tailwindcss/pull/17591))
- Ensure container query variant names can contain hyphens ([#17628](https://github.com/tailwindlabs/tailwindcss/pull/17628))
- Ensure compatibility with array tuples used in `fontSize` JS theme keys ([#17630](https://github.com/tailwindlabs/tailwindcss/pull/17630))
- Upgrade: Convert `fontSize` array tuple syntax to CSS theme variables ([#17630](https://github.com/tailwindlabs/tailwindcss/pull/17630))

## [4.1.3] - 2025-04-04

Expand Down
8 changes: 8 additions & 0 deletions integrations/upgrade/js-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ test(
xs: ['0.75rem', { lineHeight: '1rem' }],
sm: ['0.875rem', { lineHeight: '1.5rem' }],
base: ['1rem', { lineHeight: '2rem' }],
lg: ['1.125rem', '2.5rem'],
xl: ['1.5rem', '3rem', 'invalid'],
'2xl': ['2rem'],
},
width: {
px: '1px',
Expand Down Expand Up @@ -188,6 +191,11 @@ test(
--text-sm--line-height: 1.5rem;
--text-base: 1rem;
--text-base--line-height: 2rem;
--text-lg: 1.125rem;
--text-lg--line-height: 2.5rem;
--text-xl: 1.5rem;
--text-xl--line-height: 3rem;
--text-2xl: 2rem;

--width-*: initial;
--width-0: 0%;
Expand Down
18 changes: 18 additions & 0 deletions packages/tailwindcss/src/compat/apply-config-to-theme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ test('config values can be merged into the theme', () => {
lineHeight: '1.5',
},
],
lg: ['1.125rem', '2'],
xl: ['1.5rem', '3rem', 'invalid'],
'2xl': ['2rem'],
},

letterSpacing: {
Expand Down Expand Up @@ -102,6 +105,21 @@ test('config values can be merged into the theme', () => {
'1rem',
{ '--line-height': '1.5' },
])
expect(theme.resolve('lg', ['--text'])).toEqual('1.125rem')
expect(theme.resolveWith('lg', ['--text'], ['--line-height'])).toEqual([
'1.125rem',
{ '--line-height': '2' },
])
expect(theme.resolve('xl', ['--text'])).toEqual('1.5rem')
expect(theme.resolveWith('xl', ['--text'], ['--line-height'])).toEqual([
'1.5rem',
{ '--line-height': '3rem' },
])
expect(theme.resolve('2xl', ['--text'])).toEqual('2rem')
expect(theme.resolveWith('2xl', ['--text'], ['--line-height'])).toEqual([
'2rem',
{},
])
expect(theme.resolve('super-wide', ['--tracking'])).toEqual('0.25em')
expect(theme.resolve('super-loose', ['--leading'])).toEqual('3')
expect(theme.resolve('1/2', ['--width'])).toEqual('60%')
Expand Down
11 changes: 10 additions & 1 deletion packages/tailwindcss/src/compat/apply-config-to-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,16 @@ export function themeableValues(config: ResolvedConfig['theme']): [string[], unk
}

if (Array.isArray(value) && value.every((v) => typeof v === 'string')) {
toAdd.push([path, value.join(', ')])
if (path[0] === 'fontSize') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (path[0] === 'fontSize') {
if (path[0] === 'fontSize' && value.length === 2) {

I'd probably want to make sure this only works for tuples.

Copy link
Collaborator Author

@wongjn wongjn Apr 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we are to keep maximum compatibility with v3, we shouldn't restrict to 2 values. In v3, it still emits line-height with > 2 values, though I'm not sure how likely this would have occurred in the real world. Though one could argue we shouldn't support > 2 values as this was never truly intended.

Though thinking about this, perhaps we may need to check that there is at least two values for the value[1] reference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yep let's check for at least 2 entries then

Copy link
Collaborator Author

@wongjn wongjn Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tested again in v3 and an array value with one element, i.e. 2xl: ['2rem'] actually unsets the line-height. I'll assume we want to mirror this behavior as well in the compat layer. Edit: but only for extends? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this logic is better placed in mergeTheme() in packages/tailwindcss/src/compat/config/resolve-config.ts? We already do some massaging of screens here, so perhaps it would be best to have special cases be reworked in this function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wongjn Hm that's interesting. Maybe we'll keep this in the back of our minds for now and see if this is actually causing an issue for people?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK! Sure thing :)

toAdd.push([path, value[0]])

if (value.length >= 2) {
toAdd.push([[...path, '-line-height'], value[1]])
}
} else {
toAdd.push([path, value.join(', ')])
}

return WalkAction.Skip
}
})
Expand Down