Skip to content

Commit c817453

Browse files
Explicitly ignore --inset-shadow and --inset-ring variables in inset handler (#14447)
Resolves #14440. This PR fixes an issue where registering a custom `inset-shadow-*` utility value in your theme like this: ```css @theme { --inset-shadow-potato: inset 0px 2px 6px #7a4724; } ``` …mistakenly generates both an `inset-shadow-*` and `inset-*` utility with that value: ```css .inset-shadow-potato { inset: inset 0px 2px 6px #7a4724; } .inset-shadow-potato { box-shadow: inset 0px 2px 6px #7a4724; } ``` This replaces #14445 which turns out to not be the ideal solution. Now we just explicitly ignore variables like `--inset-shadow-*` and `--inset-ring-*` in the `inset` handler. Kind of a gross patch but I can live with it because the whole existence of the `--inset-*` key is kind of a backwards compatibility thing anyways. --------- Co-authored-by: Adam Wathan <[email protected]> Co-authored-by: Philipp Spiess <[email protected]>
1 parent cb5b7b4 commit c817453

File tree

3 files changed

+46
-13
lines changed

3 files changed

+46
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Ensure individual variants from groups are always sorted earlier than stacked variants from the same groups ([#14431](https://github.com/tailwindlabs/tailwindcss/pull/14431))
1818
- Allow `anchor-size(…)` in arbitrary values ([#14394](https://github.com/tailwindlabs/tailwindcss/pull/14394))
1919
- Skip candidates with invalid `theme()` calls ([#14437](https://github.com/tailwindlabs/tailwindcss/pull/14437))
20+
- Don't generate `inset-*` utilities for `--inset-shadow-*` and `--inset-ring-*` theme values ([#14447](https://github.com/tailwindlabs/tailwindcss/pull/14447))
2021

2122
## [4.0.0-alpha.24] - 2024-09-11
2223

packages/tailwindcss/src/utilities.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14143,14 +14143,6 @@ test('inset-shadow', async () => {
1414314143
--inset-shadow-sm: inset 0 1px 1px #0000000d;
1414414144
}
1414514145
14146-
.inset-shadow {
14147-
inset: var(--inset-shadow, inset 0 2px 4px #0000000d);
14148-
}
14149-
14150-
.inset-shadow-sm {
14151-
inset: var(--inset-shadow-sm, inset 0 1px 1px #0000000d);
14152-
}
14153-
1415414146
.inset-shadow {
1415514147
--tw-inset-shadow: inset 0 2px 4px #0000000d;
1415614148
--tw-inset-shadow-colored: inset 0 2px 4px var(--tw-inset-shadow-color);
@@ -14622,6 +14614,7 @@ test('inset-ring', async () => {
1462214614
css`
1462314615
@theme {
1462414616
--color-red-500: #ef4444;
14617+
--inset-ring-thick: 100px;
1462514618
}
1462614619
@tailwind utilities;
1462714620
`,
@@ -14656,13 +14649,15 @@ test('inset-ring', async () => {
1465614649
'inset-ring-1',
1465714650
'inset-ring-2',
1465814651
'inset-ring-4',
14652+
'inset-ring-thick',
1465914653
'inset-ring-[12px]',
1466014654
'inset-ring-[length:--my-width]',
1466114655
],
1466214656
),
1466314657
).toMatchInlineSnapshot(`
1466414658
":root {
1466514659
--color-red-500: #ef4444;
14660+
--inset-ring-thick: 100px;
1466614661
}
1466714662
1466814663
.inset-ring {

packages/tailwindcss/src/utilities.ts

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -428,12 +428,49 @@ export function createUtilities(theme: Theme) {
428428
let value = candidate.negative ? '-100%' : '100%'
429429
return [decl('inset', value)]
430430
})
431-
functionalUtility('inset', {
432-
supportsNegative: true,
433-
supportsFractions: true,
434-
themeKeys: ['--inset', '--spacing'],
435-
handle: (value) => [decl('inset', value)],
431+
utilities.functional('inset', (candidate) => {
432+
if (!candidate.value) return
433+
434+
let value
435+
if (candidate.value.kind === 'arbitrary') {
436+
if (candidate.modifier) return
437+
value = candidate.value.value
438+
} else {
439+
// We need to make sure variables like `--inset-shadow-sm` and
440+
// `--inset-ring-thick` don't mistakenly generate utilities for the
441+
// `inset` property.
442+
if (
443+
candidate.value.value === 'ring' ||
444+
candidate.value.value === 'shadow' ||
445+
candidate.value.value.startsWith('ring-') ||
446+
candidate.value.value.startsWith('shadow-')
447+
) {
448+
value = theme.resolve(candidate.value.fraction ?? candidate.value.value, ['--spacing'])
449+
} else {
450+
value = theme.resolve(candidate.value.fraction ?? candidate.value.value, [
451+
'--inset',
452+
'--spacing',
453+
])
454+
}
455+
456+
if (!value && candidate.value.fraction) {
457+
let [lhs, rhs] = segment(candidate.value.fraction, '/')
458+
if (!Number.isInteger(Number(lhs)) || !Number.isInteger(Number(rhs))) return
459+
value = `calc(${candidate.value.fraction} * 100%)`
460+
}
461+
462+
if (!value) return
463+
}
464+
value = withNegative(value, candidate)
465+
return [decl('inset', value)]
436466
})
467+
suggest('inset', () => [
468+
{
469+
supportsNegative: true,
470+
valueThemeKeys: ['--inset', '--spacing'],
471+
hasDefaultValue: false,
472+
},
473+
])
437474

438475
staticUtility('inset-x-auto', [
439476
['--tw-sort', 'inset-inline'],

0 commit comments

Comments
 (0)