Skip to content

Commit e3f416c

Browse files
Don't inject the fallback if the injected fallback is initial
1 parent ac83f35 commit e3f416c

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

packages/@tailwindcss-postcss/src/__snapshots__/index.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
99
--text-2xl: 1.5rem;
1010
--text-2xl--line-height: calc(2 / 1.5);
1111
--font-weight-bold: 700;
12-
--default-font-family: var(--font-sans, initial);
13-
--default-mono-font-family: var(--font-mono, initial);
12+
--default-font-family: var(--font-sans);
13+
--default-mono-font-family: var(--font-mono);
1414
}
1515
}
1616

packages/tailwindcss/src/__snapshots__/index.test.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ exports[`compiling CSS > prefix all CSS variables inside preflight 1`] = `
9898
:root, :host {
9999
--tw-font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
100100
--tw-font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
101-
--tw-default-font-family: var(--tw-font-sans, initial);
102-
--tw-default-mono-font-family: var(--tw-font-mono, initial);
101+
--tw-default-font-family: var(--tw-font-sans);
102+
--tw-default-mono-font-family: var(--tw-font-mono);
103103
}
104104
}
105105

packages/tailwindcss/src/css-functions.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,43 @@ describe('--theme(…)', () => {
286286
`)
287287
})
288288

289+
test.only('--theme(…) does not inject the fallback if the fallback is `initial`', async () => {
290+
expect(
291+
await compileCss(
292+
css`
293+
@theme prefix(tw) {
294+
--font-sans:
295+
ui-sans-serif, system-ui, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
296+
'Segoe UI Symbol', 'Noto Color Emoji';
297+
--default-font-family: --theme(--font-sans, initial);
298+
}
299+
@layer base {
300+
html {
301+
font-family: --theme(--default-font-family, sans-serif);
302+
}
303+
}
304+
@tailwind utilities;
305+
`,
306+
['tw:font-sans'],
307+
),
308+
).toMatchInlineSnapshot(`
309+
":root, :host {
310+
--tw-font-sans: ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
311+
--tw-default-font-family: var(--tw-font-sans);
312+
}
313+
314+
@layer base {
315+
html {
316+
font-family: var(--tw-default-font-family, sans-serif);
317+
}
318+
}
319+
320+
.tw\\:font-sans {
321+
font-family: var(--tw-font-sans);
322+
}"
323+
`)
324+
})
325+
289326
test('--theme(…) forces the value to be retrieved as inline when used inside an at rule', async () => {
290327
expect(
291328
await compileCss(css`

packages/tailwindcss/src/css-functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,16 @@ function theme(
106106
// - …as the value if the value returned is `initial`
107107
// - …expect any `initial` fallbacks on `var(…)`, `theme(…)`, or `--theme(…)`
108108
// - …as the fallback if a `var(…)` with no fallback is returned
109-
if (resolvedValue === 'initial') return fallback.join(', ')
109+
let joinedFallback = fallback.join(', ')
110+
if (joinedFallback === 'initial') return resolvedValue
111+
if (resolvedValue === 'initial') return joinedFallback
110112
if (
111113
resolvedValue.startsWith('var(') ||
112114
resolvedValue.startsWith('theme(') ||
113115
resolvedValue.startsWith('--theme(')
114116
) {
115117
let valueAst = ValueParser.parse(resolvedValue)
116-
injectFallbackForInitialFallback(valueAst, fallback.join(', '))
118+
injectFallbackForInitialFallback(valueAst, joinedFallback)
117119
return ValueParser.toCss(valueAst)
118120
}
119121

0 commit comments

Comments
 (0)