fix(next/font/google): bound Google Fonts fetch timeout on Turbopack#95981
Merged
Conversation
Contributor
Stats from current PR🟢 1 improvement
📊 All Metrics📖 Metrics GlossaryDev Server Metrics:
Build Metrics:
Change Thresholds:
⚡ Dev Server
📦 Dev Server (Webpack) (Legacy)📦 Dev Server (Webpack)
⚡ Production Builds
📦 Production Builds (Webpack) (Legacy)📦 Production Builds (Webpack)
📦 Bundle SizesBundle Sizes⚡ TurbopackClient Main Bundles
Server Middleware
Build DetailsBuild Manifests
📦 WebpackClient Main Bundles
Polyfills
Pages
Server Edge SSR
Middleware
Build DetailsBuild Manifests
Build Cache
🔄 Shared (bundler-independent)Runtimes
📎 Tarball URLCommit: d5ac23c |
Contributor
Tests PassedCommit: d5ac23c |
aurorascharff
marked this pull request as ready for review
July 20, 2026 19:53
aurorascharff
marked this pull request as draft
July 20, 2026 19:53
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the compile-time Google Fonts download path in next/font/google to avoid indefinite hangs on “stuck” networks and to make retry behavior visible in build/dev output.
Changes:
- Bound
fetchResource()request timeouts in both dev and build (3s / 6s) so compilation can’t hang forever. - Switched retry logging to Next’s standard build logger to ensure retry attempts are visible (especially under Turbopack).
- Added targeted Jest coverage for retry logging, request timeouts, and dev/build fallback behavior; fixed a stray brace in the dev fallback error message.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/font/src/google/retry.ts | Logs retry attempts via next/dist/build/output/log instead of console.error. |
| packages/font/src/google/retry.test.ts | Adds unit coverage for retry logging and retry limit behavior. |
| packages/font/src/google/loader.ts | Fixes dev fallback error message formatting (removes stray }). |
| packages/font/src/google/loader.test.ts | Adds coverage for dev fallback logging and build-time failure behavior when Google Fonts is unreachable. |
| packages/font/src/google/fetch-resource.ts | Ensures a timeout is always applied (3s dev / 6s build). |
| packages/font/src/google/fetch-resource.test.ts | Adds coverage ensuring hanging connections time out in both dev and build modes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aurorascharff
marked this pull request as ready for review
July 20, 2026 20:41
bgw
reviewed
Jul 21, 2026
aurorascharff
marked this pull request as draft
July 21, 2026 08:04
aurorascharff
force-pushed
the
aurorascharff/font-google-fetch-timeout
branch
from
July 22, 2026 12:59
9ae296d to
5274cd8
Compare
aurorascharff
marked this pull request as ready for review
July 22, 2026 13:26
aurorascharff
force-pushed
the
aurorascharff/font-google-fetch-timeout
branch
from
July 22, 2026 13:44
5274cd8 to
5fa8d1e
Compare
next/font/google downloads font CSS/files from Google Fonts at compile time. On a "stuck" network (captive portal, hanging corporate proxy, blocked endpoint) the TCP/proxy connect never completes, so `next dev` and `next build` hang until the OS connect timeout (~75s) or forever. Bound the fetch on the Turbopack path: - Add `connect_timeout` (default 10s) and `timeout` (default 60s) to `FetchClientConfig`; the generic crate keeps generous defaults. - Override for Google Fonts: 5s connect / 30s total, one value that works for both dev and build. - Retry transient failures (connect/timeout/request) up to `MAX_FETCH_RETRIES` times, each attempt wrapped in a `duration_span!` so retries are visible in the trace viewer. - Enrich the terminal-visible font Issue to say the download failed after N attempts and to recommend self-hosting with `next/font/local`. On `next build` an unreachable font still fails the build (now promptly), and `next dev` falls back to the metric-adjusted fallback font.
The Turbopack path now emits an enriched message (retry count + self-host hint); the webpack/JS path keeps the original wording. Assert per bundler so both matrices pass.
aurorascharff
force-pushed
the
aurorascharff/font-google-fetch-timeout
branch
from
July 22, 2026 15:35
11152f1 to
9c3a1c9
Compare
bgw
requested changes
Jul 22, 2026
Co-authored-by: Benjamin Woodruff <benjamin.woodruff@vercel.com>
Co-authored-by: Benjamin Woodruff <benjamin.woodruff@vercel.com>
Co-authored-by: Benjamin Woodruff <benjamin.woodruff@vercel.com>
Co-authored-by: Benjamin Woodruff <benjamin.woodruff@vercel.com>
Co-authored-by: Benjamin Woodruff <benjamin.woodruff@vercel.com>
Address review: - Move the retry count into `FetchClientConfig.max_retries` (default 0, generic); Google Fonts opts into 3. - Also retry 5xx responses, not just connect/timeout/request errors. - Add the `std::time::Duration` import the accepted timeout suggestion needed (the branch didn't compile without it).
…edString Address review: - Dedicated GoogleFontsFetchIssue that generates its title/description lazily in the trait impl instead of storing pre-built StyledStrings. - Compose StyledString::Line/Code/Stack instead of format! + interpolation and `\n` in a single Text. - Share the description between dev and build (severity drives the difference). - Mention configuring HTTP_PROXY/HTTPS_PROXY in the guidance. Update the e2e assertions: Turbopack now renders the font name via StyledString::Code (no backticks); the webpack/JS path is unchanged.
bgw
approved these changes
Jul 23, 2026
bgw
left a comment
Member
There was a problem hiding this comment.
Thanks for doing this @aurorascharff
Comment on lines
+51
to
+108
| impl Issue for GoogleFontsFetchIssue { | ||
| fn stage(&self) -> IssueStage { | ||
| IssueStage::Resolve | ||
| } | ||
|
|
||
| fn severity(&self) -> IssueSeverity { | ||
| if self.is_dev { | ||
| IssueSeverity::Warning | ||
| } else { | ||
| IssueSeverity::Error | ||
| } | ||
| } | ||
|
|
||
| async fn file_path(&self) -> Result<FileSystemPath> { | ||
| Ok(self.path.clone()) | ||
| } | ||
|
|
||
| async fn title(&self) -> Result<StyledString> { | ||
| Ok(StyledString::Line(vec![ | ||
| StyledString::Code(rcstr!("next/font:")), | ||
| StyledString::Text(if self.is_dev { | ||
| rcstr!(" warning:") | ||
| } else { | ||
| rcstr!(" error:") | ||
| }), | ||
| ])) | ||
| } | ||
|
|
||
| async fn description(&self) -> Result<Option<StyledString>> { | ||
| let summary = if self.is_dev { | ||
| StyledString::Line(vec![ | ||
| StyledString::Text(rcstr!("Failed to download ")), | ||
| StyledString::Code(self.font_family.clone()), | ||
| StyledString::Text(rcstr!(" from Google Fonts. Using a fallback font instead.")), | ||
| ]) | ||
| } else { | ||
| StyledString::Line(vec![ | ||
| StyledString::Text(rcstr!("Failed to fetch ")), | ||
| StyledString::Code(self.font_family.clone()), | ||
| StyledString::Text(rcstr!(" from Google Fonts.")), | ||
| ]) | ||
| }; | ||
| let guidance = StyledString::Line(vec![ | ||
| StyledString::Text(rcstr!( | ||
| "If you are offline or behind a proxy, self-host the font with " | ||
| )), | ||
| StyledString::Code(rcstr!("next/font/local")), | ||
| StyledString::Text(rcstr!(", or set ")), | ||
| StyledString::Code(rcstr!("HTTP_PROXY")), | ||
| StyledString::Text(rcstr!("/")), | ||
| StyledString::Code(rcstr!("HTTPS_PROXY")), | ||
| StyledString::Text(rcstr!(" so Next.js can reach ")), | ||
| StyledString::Code(rcstr!("fonts.googleapis.com")), | ||
| StyledString::Text(rcstr!(".")), | ||
| ]); | ||
| Ok(Some(StyledString::Stack(vec![summary, guidance]))) | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
Awesome. This is much nicer, thanks.
Comment on lines
+2709
to
+2715
| // Bounds the Google Fonts fetch. Dev fails fast and falls back to a system font; | ||
| // build tolerates a slower network since a missing font fails the build. | ||
| let (connect_timeout, timeout) = if matches!(*next_mode.await?, NextMode::Development) { | ||
| (Duration::from_secs(5), Duration::from_secs(10)) | ||
| } else { | ||
| (Duration::from_secs(10), Duration::from_secs(30)) | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Bound the compile-time Google Fonts fetch on the Turbopack path so
next dev/next buildcan't hang forever on a stuck network.Why?
next/font/googlefetches 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?
FetchClientConfiggets aconnect_timeout(10s) and totaltimeout(60s); Google Fonts overrides them to 5s / 30s.duration_span!.next builderrors (fails the build),next devwarns and uses the fallback font. Both messages report the attempt count and suggestnext/font/local.Follow-ups
packages/font/src/google).Related: #92301. #76473.