mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What? Bound the compile-time Google Fonts fetch on the Turbopack path so `next dev` / `next build` can't hang forever on a stuck network. ### Why? `next/font/google` fetches from Google Fonts at compile time. When the connection *hangs* (captive portal, packet-dropping proxy, broken IPv6), the fetch had no timeout, so compilation blocked until the OS connect timeout (~75s) or indefinitely. ### How? - `FetchClientConfig` gets a `connect_timeout` (10s) and total `timeout` (60s); Google Fonts overrides them to 5s / 30s. - Transient failures retry up to 3×, each attempt its own `duration_span!`. - On failure: `next build` errors (fails the build), `next dev` warns and uses the fallback font. Both messages report the attempt count and suggest `next/font/local`. ### Follow-ups - [ ] Reduce the dev-mode timeout (build keeps the longer value). - [ ] Port the fix to the webpack/JS path (`packages/font/src/google`). Related: #92301. #76473. --------- Co-authored-by: Benjamin Woodruff <[email protected]>
70 lines
2.3 KiB
TypeScript
70 lines
2.3 KiB
TypeScript
import { FileRef, nextTestSetup } from 'e2e-utils'
|
|
import { join } from 'path'
|
|
|
|
const mockedGoogleFontResponses = require.resolve(
|
|
'./google-font-mocked-responses.js'
|
|
)
|
|
|
|
describe('next/font/google fetch error', () => {
|
|
const isDev = (global as any).isNextDev
|
|
const isTurbopack = !!process.env.IS_TURBOPACK_TEST
|
|
|
|
if ((global as any).isNextDeploy) {
|
|
it('should skip next deploy for now', () => {})
|
|
return
|
|
}
|
|
|
|
const { next } = nextTestSetup({
|
|
files: {
|
|
pages: new FileRef(join(__dirname, 'google-fetch-error/pages')),
|
|
},
|
|
env: {
|
|
NEXT_FONT_GOOGLE_MOCKED_RESPONSES: mockedGoogleFontResponses,
|
|
},
|
|
skipStart: true,
|
|
})
|
|
|
|
if (isDev) {
|
|
it('should use a fallback font in dev', async () => {
|
|
await next.start()
|
|
const outputIndex = next.cliOutput.length
|
|
const browser = await next.browser('/')
|
|
|
|
const ascentOverride = await browser.eval(
|
|
'Array.from(document.fonts.values()).find(font => font.family.includes("Inter Fallback")).ascentOverride'
|
|
)
|
|
expect(ascentOverride).toMatchInlineSnapshot(`"90.44%"`)
|
|
|
|
const descentOverride = await browser.eval(
|
|
'Array.from(document.fonts.values()).find(font => font.family.includes("Inter Fallback")).descentOverride'
|
|
)
|
|
expect(descentOverride).toMatchInlineSnapshot(`"22.52%"`)
|
|
|
|
const lineGapOverride = await browser.eval(
|
|
'Array.from(document.fonts.values()).find(font => font.family.includes("Inter Fallback")).lineGapOverride'
|
|
)
|
|
expect(lineGapOverride).toMatchInlineSnapshot(`"0%"`)
|
|
|
|
const sizeAdjust = await browser.eval(
|
|
'Array.from(document.fonts.values()).find(font => font.family.includes("Inter Fallback")).sizeAdjust'
|
|
)
|
|
expect(sizeAdjust).toMatchInlineSnapshot(`"107.12%"`)
|
|
|
|
expect(next.cliOutput.slice(outputIndex)).toInclude(
|
|
isTurbopack
|
|
? 'Failed to download Inter from Google Fonts. Using a fallback font instead.'
|
|
: 'Failed to download `Inter` from Google Fonts. Using fallback font instead.'
|
|
)
|
|
})
|
|
} else {
|
|
it('should error when not in dev', async () => {
|
|
await expect(next.start()).rejects.toThrow('next build failed')
|
|
expect(next.cliOutput).toInclude(
|
|
isTurbopack
|
|
? 'Failed to fetch Inter from Google Fonts.'
|
|
: 'Failed to fetch `Inter` from Google Fonts.'
|
|
)
|
|
})
|
|
}
|
|
})
|