-
Notifications
You must be signed in to change notification settings - Fork 27.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add retry for fetching subsetted Google Fonts #56583
Conversation
@@ -1,6 +1,7 @@ | |||
// @ts-ignore | |||
import fetch from 'next/dist/compiled/node-fetch' | |||
import { getProxyAgent } from './get-proxy-agent' | |||
import { retry } from './retry' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use async-retry
instead of the self-baked solution.
bf906a4
to
b3ceafc
Compare
"@types/fontkit": "2.0.0", | ||
"@vercel/ncc": "0.34.0", | ||
"async-retry": "1.3.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: async-retry is already in devDeps at root and create-next-app
@@ -1,24 +1,10 @@ | |||
// @ts-ignore | |||
import fetch from 'next/dist/compiled/node-fetch' | |||
// eslint-disable-next-line import/no-extraneous-dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import/no-extraneous-dependencies
is now useless because of ncc, right?
introduced by #13482
disable directives: https://github.com/search?q=repo%3Avercel%2Fnext.js+%22import%2Fno-extraneous-dependencies%22+%22eslint-disable%22&type=code
current configuration:
Lines 163 to 176 in 9b2f29e
{ | |
"files": ["packages/**"], | |
"excludedFiles": [ | |
"packages/next/taskfile*.js", | |
"packages/next/webpack.config.js" | |
], | |
"rules": { | |
"no-shadow": ["warn", { "builtinGlobals": false }], | |
"import/no-extraneous-dependencies": [ | |
"error", | |
{ "devDependencies": false } | |
] | |
} | |
}, |
b3ceafc
to
db57027
Compare
(e as Error).message + `\n\nRetrying ${attempt}/${retries}...` | ||
) | ||
}, | ||
minTimeout: 100, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOTE: The cooldown time for retries is based on the original code.
However, the second retry and later, the wait time doubles with each subsequent retry. This behavior is due to the default settings of async-retry and can be modified if needed. async-retry API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the default "Exponential Backoff" behavior of async-retry
and IMHO we should keep it.
db57027
to
b422eaa
Compare
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
2 similar comments
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Stats from current PRDefault BuildGeneral Overall increase
|
vercel/next.js canary | berlysia/next.js add-retry-for-font-fetching | Change | |
---|---|---|---|
buildDuration | 10.6s | 10.5s | N/A |
buildDurationCached | 6.1s | 6.1s | N/A |
nodeModulesSize | 174 MB | 174 MB | |
nextStartRea..uration (ms) | 515ms | 497ms | N/A |
Client Bundles (main, webpack)
vercel/next.js canary | berlysia/next.js add-retry-for-font-fetching | Change | |
---|---|---|---|
199-HASH.js gzip | 27.5 kB | 27.5 kB | ✓ |
3f784ff6-HASH.js gzip | 53.3 kB | 53.3 kB | ✓ |
99.HASH.js gzip | 182 B | 182 B | ✓ |
framework-HASH.js gzip | 45.3 kB | 45.3 kB | ✓ |
main-app-HASH.js gzip | 254 B | 251 B | N/A |
main-HASH.js gzip | 32.9 kB | 32.9 kB | N/A |
webpack-HASH.js gzip | 1.75 kB | 1.75 kB | N/A |
Overall change | 126 kB | 126 kB | ✓ |
Legacy Client Bundles (polyfills)
vercel/next.js canary | berlysia/next.js add-retry-for-font-fetching | Change | |
---|---|---|---|
polyfills-HASH.js gzip | 31 kB | 31 kB | ✓ |
Overall change | 31 kB | 31 kB | ✓ |
Client Pages
vercel/next.js canary | berlysia/next.js add-retry-for-font-fetching | Change | |
---|---|---|---|
_app-HASH.js gzip | 206 B | 205 B | N/A |
_error-HASH.js gzip | 182 B | 180 B | N/A |
amp-HASH.js gzip | 506 B | 505 B | N/A |
css-HASH.js gzip | 322 B | 323 B | N/A |
dynamic-HASH.js gzip | 2.57 kB | 2.57 kB | N/A |
edge-ssr-HASH.js gzip | 260 B | 259 B | N/A |
head-HASH.js gzip | 350 B | 350 B | ✓ |
hooks-HASH.js gzip | 369 B | 369 B | ✓ |
image-HASH.js gzip | 4.36 kB | 4.36 kB | N/A |
index-HASH.js gzip | 256 B | 256 B | ✓ |
link-HASH.js gzip | 2.64 kB | 2.63 kB | N/A |
routerDirect..HASH.js gzip | 312 B | 311 B | N/A |
script-HASH.js gzip | 385 B | 384 B | N/A |
withRouter-HASH.js gzip | 307 B | 308 B | N/A |
1afbb74e6ecf..834.css gzip | 106 B | 106 B | ✓ |
Overall change | 1.08 kB | 1.08 kB | ✓ |
Client Build Manifests
vercel/next.js canary | berlysia/next.js add-retry-for-font-fetching | Change | |
---|---|---|---|
_buildManifest.js gzip | 484 B | 482 B | N/A |
Overall change | 0 B | 0 B | ✓ |
Rendered Page Sizes
vercel/next.js canary | berlysia/next.js add-retry-for-font-fetching | Change | |
---|---|---|---|
index.html gzip | 528 B | 529 B | N/A |
link.html gzip | 543 B | 542 B | N/A |
withRouter.html gzip | 524 B | 524 B | ✓ |
Overall change | 524 B | 524 B | ✓ |
Edge SSR bundle Size
vercel/next.js canary | berlysia/next.js add-retry-for-font-fetching | Change | |
---|---|---|---|
edge-ssr.js gzip | 94 kB | 94 kB | N/A |
page.js gzip | 155 kB | 155 kB | N/A |
Overall change | 0 B | 0 B | ✓ |
Middleware size
vercel/next.js canary | berlysia/next.js add-retry-for-font-fetching | Change | |
---|---|---|---|
middleware-b..fest.js gzip | 624 B | 624 B | ✓ |
middleware-r..fest.js gzip | 150 B | 151 B | N/A |
middleware.js gzip | 22.9 kB | 22.9 kB | N/A |
edge-runtime..pack.js gzip | 1.92 kB | 1.92 kB | ✓ |
Overall change | 2.55 kB | 2.55 kB | ✓ |
This PR picks up where I missed it and I think we should merge this and do a point release soon as this addresses a pretty serious issue. |
b422eaa
to
4e3d0a4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks! 🎉
@styfle Thanks for taking care of this! |
Reverting due to an error #57154 |
Reverts #56583 due to missing dependency ``` app/layout.jsx An error occured in 'next/font'. Error: Cannot find module 'async-retry' Require stack: - node_modules/•pnpm/next@13.5.7-canary.12_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/@next/font/dist/google/retry.js - node_modules/-pnpm/next@13.5.7-canary-12_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/compiled/@next/font/dist/google/fetch-css-from-google-fonts.js ```
Hello @styfle , I noticed that this PR was reverted. I'm confident that my changes still can resolve the issue. However, I'm not certain why the
Which approach do you prefer, or another? I'm not familiar with the behavior of the ncc library or the way of next.js , so I can't say with confidence which solution is best at this moment. |
What?
Add the same re-retrieval process for subseted font files of Google Font as for CSS files.
Why?
It was reported in #45080 that Japanese fonts such as Noto Sans JP were frequently
Failed to fetch
.A retry process was added in #51890, but it did not resolve the issue completely ( #51890 (comment) ).
Here is my reproduction code with 13.5.5-canary.4 (please run locally).
https://stackblitz.com/edit/stackblitz-starters-n8zxlq?file=app%2Fpage.tsx
And my local error log is here(folded)
I've found that the issue is not limited to fetching CSS, fetching subset font files is also failing.
By adding retry handling to the fetch of individual subseted font files as well, I (almost) never see
Failed to fetch
anymore.The issue tends to become more apparent when downloading a larger number of subsetted fonts.
This suggests that the problem is more likely to occur with larger fonts, such as those designed for CJK languages.
How?
Add the same re-retrieval process for subseted font files of Google Font as for CSS files.
Related to #51890 #53239 #45080 #53279