Repository navigation
perf(docsite): avatars load at the size the page shows them - #12545
Conversation
The community page's contributor wall loaded each GitHub avatar as the person uploaded it: up to 460 pixels on a side for a 48-pixel tile, and 557 KB for the twelve. A blog byline loaded 128-pixel files for avatars that it shows at 20 or 36 pixels. Both now ask GitHub for the size they show, at two device pixels for each CSS pixel. The wall also gives the browser a file for a 1x screen through `srcset`. The site prefetches the community page from every page that links to it, so the wall's avatars were also a background download on most first visits.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
PR Analysis Report🔎 Preview ·
|
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet.
The avatar requests on the community wall and in the blog byline now match the size each surface draws, other URLs are left alone, and the new tests pass. One optional suggestion:
URL.canParseingithubAvatarUrl.tsalso runs in the browser, because the byline renders inside client components on/blogand the homepage (BlogIndex,BlogShowcase), so browsers before Chrome 120 or Safari 17 throw there; parsing withtry { new URL(url) } catch { return null; }keeps the unchanged-URL fallback everywhere.
Claims and files checked
Review mode: full; reason: no-earlier-review
- Claim: only the docsite changes and no public API is added: verified.
- Claim: the wall used the API's full-size avatar URL, and the byline asked for 128 px files for 20 px and 36 px avatars: verified in the base code and the
Avatarsize scale. - Claim: the header links to the community page on every site and blog page: verified; that the prefetch downloads the wall's avatars: not verified here (needs a browser with network access).
- Claim: the helper asks for two device pixels per CSS pixel, using each host's own parameter: verified in the code; GitHub's handling of each parameter: not verified here.
- Claim: the wall gets a 1x/2x
srcsetand the byline asks for 40 px and 72 px: verified in the code and tests. - Claim: pictures GitHub does not serve (the placeholders, the team avatar) keep their URL: verified.
- Claim: the byline cannot call
Avatar's size scale because it renders on the server: partly accurate, since it renders on the server in articles and in client components on the blog index and homepage; the conclusion holds, and a test keeps the two sizes in step. - Claim: no visible change, the byte savings, the loading and preload results, and the mutation check: not verified here (they need network access).
- Claim: the 12, 4 and 5 new tests: verified, all pass; the full docsite unit and browser suite counts: not reproduced (they need the whole workspace build).
- Claim: no browser-specific code: true for current browsers; see the suggestion above.
- File
apps/docsite/src/lib/githubAvatarUrl.ts: the suggestion above. - Files
community/page.tsx,AuthorByline.tsx,authors.tsand the three new test files: clear.
The blog byline also renders in the browser, inside the blog index and the landing page's blog section. Chrome and Edge before version 120 have no `URL.canParse`, so the helper threw there. It now parses with `new URL` in a `try`. The byline test reads the Avatar size scale while the file loads, so no test waits for the module.
There was a problem hiding this comment.
Approved pending CI: CI has not run on this head yet.
The avatar helper now parses with new URL inside a try, so the blog byline renders in browsers without URL.canParse, and the new test catches a return to it. The wall and byline still request avatars at the size each surface draws, and nothing else needs to change.
Claims and files checked
Review mode: incremental; reason: none
- Claim: only the docsite changes and no public API is added: verified.
- Claim: the wall used the API's full-size avatar URL, and the byline asked for 128 px files for 20 px and 36 px avatars: verified in the base code and the
Avatarsize scale. - Claim: the header links to the community page on every page: verified; that the prefetch downloads the wall's avatars: not verified here (needs a browser with network access).
- Claim: the helper asks for two device pixels per CSS pixel, using each host's own size parameter: verified in the code; GitHub's handling of each parameter: not verified here.
- Claim: the wall gets a 1x/2x
srcsetand the byline asks for 40 px and 72 px: verified in the code and tests. - Claim: pictures GitHub does not serve (the placeholders, the team avatar) keep their URL: verified.
- Claim: the byline also renders in the browser on the blog index and the landing page, so the helper avoids
URL.canParse, which Chrome and Edge lack before version 120 while the supported range starts at 114: verified against the client components and the Browser Support guide's Baseline − 2 row. - Claim: the byline cannot call
Avatar's size scale because it renders on the server: holds for the article page, where it does; a test keeps the two sizes in step. - Claim: the second commit changes only how the helper parses a URL: verified for shipped code; its other changes are tests.
- Claim: the 13, 4 and 5 new tests: verified, all pass.
- Claim: no visible change, the byte savings, the loading and preload results, and the mutation check: not verified here (they need network access).
- Claim: the full docsite unit and browser suite counts and a clean type check and lint: not reproduced (they need the whole workspace build); the type check shows no error in the changed files.
- Files
githubAvatarUrl.ts,community/page.tsx,AuthorByline.tsx,authors.tsand the three new test files: clear.
Primary intent
A GitHub avatar on the docs site loads at the size the page shows it. The community page's contributor wall and the blog byline both loaded files several times larger than they draw.
No other template fits: this is a performance change with no visible change and no new capability.
New public API: none. Only
apps/docsitechanges.User or maintainer impact
/community: the twelve wall avatars cost 27 KB on a standard screen and 61 KB on a dense one, in place of 557 KB./community: the router prefetches the community page, and that prefetch downloads the wall's avatars. On/blogthat background download was 557 KB; it is now 26 KB (61 KB on a dense screen).Avatar bytes on the wire, for the page's own avatar images. "Before" is the production site on 2026-11-17. "After" is a local production build of this branch: the wall row is from the build of the first commit, and the two byline rows were measured again on the build of the head. The second commit changes only how the helper parses a URL. Headless Chromium, cold cache.
/community/blog/blog/how-astryx-worksThe numbers are the same at 1440 and 390 px wide.
Problem and solution fit
avatar_urlas GitHub's API returns it. Without a size, GitHub sends the picture as the person uploaded it: up to 460 pixels on a side, and up to 163 KB for one of the twelve. The wall draws it at 48 pixels./communityon every page. So most first visits downloaded the wall's 557 KB in the background.The change asks GitHub for the size the page shows:
githubAvatarUrl(url, cssPixels)sets GitHub's size parameter to two device pixels for each CSS pixel. The two hosts read different parameters:avatars.githubusercontent.comreadss, andgithub.com/<name>.pngreadssizeand ignoress.<img>, so it also gets asrcsetwith a 48-pixel file for a 1× screen and a 96-pixel file for a denser one. The browser makes the choice.Avatar, which takes onesrc. It asks for 40 pixels on a card and 72 on an article.new URLin atry, not withURL.canParse: Chrome and Edge before version 120 do not haveURL.canParse, and the supported range starts at 114.No tagalongs. The comment on the default size in
authors.tschanges, because it said the byline uses that size.Authority
https://avatars.githubusercontent.com/u/<id>?v=4&s=96returns a 96×96 file, and&s=48a 48×48 file.https://github.com/<name>.png?size=40redirects to the avatar host and returns a 40×40 file.https://github.com/<name>.png?s=40returns the full file (460×460, 396 KB for one author).Change and evidence
src/lib/githubAvatarUrl.tssrcandsrcSetof an avatar<img>.src/app/(site)/community/page.tsxsrc/components/blog/AuthorByline.tsxsrc/content/blog/authors.tsAvatarmodule is client code, so the byline cannot callAvatar's size scale. It holds the two pixel sizes it uses (20 and 36), and a test compares them withAvatar'sresolveSize./community,/blogand the post have no page error and no broken avatar, and the server HTML stays through hydration. The preload hints that React writes for the wall carry the samesrcset.srcset, as before this change.Scope
Components: docsite community page, docsite blog byline
Testing
src/__tests__/github-avatar-url.test.ts(new, 13 tests): the parameter for each host, the pixel density, rounding, a size that the URL came with, the URLs that stay as they are, a browser withoutURL.canParse, and thesrcSet.src/__tests__/community-wall-avatars.test.tsx(new, 4 tests): renders the page with GitHub's answer mocked. Twelve contributor avatars at 48 and 96 pixels; placeholder portraits unchanged when GitHub returns fewer contributors, refuses the request, or the request fails.src/__tests__/author-byline-avatars.test.tsx(new, 5 tests): 40 pixels on a card and 72 on an article, the sizes agree with theAvatarscale, an author that the registry does not list, and the team avatar unchanged.src, the wall or the byline using the URL as it came, a size that differs from what the page draws, a call toURL.canParse). Each fails at least one test.internal-docs-promptcases skip without their environment.Not tested: Firefox and Safari. The change has no browser-specific code;
srcsetwith pixel-density descriptors is in every current browser.