Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
feedthejim committed Feb 6, 2025
1 parent 2b12be1 commit 352961e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/font/src/google/fetch-css-from-google-fonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export async function fetchCSSFromGoogleFonts(
return mockedResponse
}

// Retry the fetch a few times in case of network issues as some font files
// are quite large:
// https://github.com/vercel/next.js/issues/45080
return retry(async () => {
const controller =
isDev && typeof AbortController !== 'undefined'
Expand All @@ -34,13 +37,14 @@ export async function fetchCSSFromGoogleFonts(
const res = await fetchWithProxy(url, {
signal: controller?.signal,
headers: {
// The file format is based off of the user agent, make sure woff2 files are fetched
'user-agent':
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36',
},
})

if (!res.ok) {
throw new Error(
nextFontError(
`Failed to fetch font \`${fontFamily}\`.\nURL: ${url}\n\nPlease check if the network is available.`
)
}
Expand Down

0 comments on commit 352961e

Please sign in to comment.