Skip to content

Commit 3a7c35a

Browse files
authored
@next/font fallback fonts order fix (#43633)
The fallback fonts are applied in the wrong order which can cause the generated fallback font not to get applied. ref: [slack](https://vercel.slack.com/archives/C03S8ED1DKM/p1669834408302339?thread_ts=1669765718.933099&cid=C03S8ED1DKM) ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md) ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm build && pnpm lint` - [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
1 parent bb770ca commit 3a7c35a

File tree

3 files changed

+6
-11
lines changed

3 files changed

+6
-11
lines changed

packages/next/build/webpack/loaders/next-font-loader/postcss-font-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ const postcssFontLoaderPlugn = ({
115115
const isRange = (value: string) => value.trim().includes(' ')
116116
const formattedFontFamilies = [
117117
formatFamily(fontFamily),
118-
...fallbackFonts,
119118
...(adjustFontFallbackFamily ? [adjustFontFallbackFamily] : []),
119+
...fallbackFonts,
120120
].join(', ')
121121
// Add class with family, weight and style
122122
const classRule = new postcss.Rule({ selector: '.className' })

test/e2e/next-font/app/pages/with-fallback.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Open_Sans } from '@next/font/google'
22
const openSans = Open_Sans({
33
fallback: ['system-ui', 'Arial'],
44
variable: '--open-sans',
5+
adjustFontFallback: false,
56
})
67

78
export default function WithFonts() {

test/e2e/next-font/index.test.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('@next/font/google', () => {
108108
className: expect.stringMatching(/__className_.{6}/),
109109
style: {
110110
fontFamily: expect.stringMatching(
111-
/^'__myFont1_.{6}', system-ui, '__myFont1_Fallback_.{6}'$/
111+
/^'__myFont1_.{6}', '__myFont1_Fallback_.{6}', system-ui$/
112112
),
113113
fontStyle: 'italic',
114114
fontWeight: 100,
@@ -275,27 +275,21 @@ describe('@next/font/google', () => {
275275
await browser.eval(
276276
'getComputedStyle(document.querySelector("#with-fallback-fonts-classname")).fontFamily'
277277
)
278-
).toMatch(
279-
/^__Open_Sans_.{6}, system-ui, Arial, __Open_Sans_Fallback_.{6}$/
280-
)
278+
).toMatch(/^__Open_Sans_.{6}, system-ui, Arial$/)
281279

282280
// .style
283281
expect(
284282
await browser.eval(
285283
'getComputedStyle(document.querySelector("#with-fallback-fonts-style")).fontFamily'
286284
)
287-
).toMatch(
288-
/^__Open_Sans_.{6}, system-ui, Arial, __Open_Sans_Fallback_.{6}$/
289-
)
285+
).toMatch(/^__Open_Sans_.{6}, system-ui, Arial$/)
290286

291287
// .variable
292288
expect(
293289
await browser.eval(
294290
'getComputedStyle(document.querySelector("#with-fallback-fonts-variable")).fontFamily'
295291
)
296-
).toMatch(
297-
/^__Open_Sans_.{6}, system-ui, Arial, __Open_Sans_Fallback_.{6}$/
298-
)
292+
).toMatch(/^__Open_Sans_.{6}, system-ui, Arial$/)
299293
})
300294
})
301295

0 commit comments

Comments
 (0)