Skip to content

perf(docsite): avatars load at the size the page shows them - #12545

Merged
nynexman4464 merged 2 commits into
mainfrom
nynexman4464/perf/docsite-avatar-sizes
Nov 19, 2026
Merged

nynexman4464 merged 2 commits into
mainfrom
nynexman4464/perf/docsite-avatar-sizes

Conversation

@nynexman4464

@nynexman4464 nynexman4464 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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/docsite changes.

User or maintainer impact

  • Visitors to /community: the twelve wall avatars cost 27 KB on a standard screen and 61 KB on a dense one, in place of 557 KB.
  • Visitors to any page that links to /community: the router prefetches the community page, and that prefetch downloads the wall's avatars. On /blog that background download was 557 KB; it is now 26 KB (61 KB on a dense screen).
  • Visitors to the blog: the byline avatars cost 19 KB on the index in place of 115 KB, and 14 KB on a post in place of 36 KB.
  • Maintainers: nothing to maintain. An author's avatar and the contributor list come from the same places as before.

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.

Page Avatars Before After, 1× screen After, 2× and 3× screens
/community 12 on the wall, shown at 48 px 557 KB, files of 176 to 460 px 27 KB, 48 px files 61 KB, 96 px files
/blog 7 authors on the cards, shown at 20 px 115 KB, 128 px files 19 KB, 40 px files 19 KB, 40 px files
/blog/how-astryx-works 2 authors, shown at 36 px 36 KB, 128 px files 14 KB, 72 px files 14 KB, 72 px files

The numbers are the same at 1440 and 390 px wide.

Problem and solution fit

  1. Why are the files large? The wall used each contributor's avatar_url as 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.
  2. Why were the byline's files large? The byline asked for 128 pixels for every avatar. A card shows an avatar at 20 pixels and an article at 36.
  3. Why does it matter beyond these pages? The site prefetches the pages behind the links on screen, and the header links to /community on 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.com reads s, and github.com/<name>.png reads size and ignores s.
  • The wall is a plain <img>, so it also gets a srcset with a 48-pixel file for a 1× screen and a 96-pixel file for a denser one. The browser makes the choice.
  • The byline renders the core Avatar, which takes one src. It asks for 40 pixels on a card and 72 on an article.
  • A picture that GitHub does not serve keeps its URL: the placeholder portraits (already 80 pixels) and the team avatar that the site serves.
  • The byline also renders in the browser, inside the blog index and the landing page's blog section. The helper parses a URL with new URL in a try, not with URL.canParse: Chrome and Edge before version 120 do not have URL.canParse, and the supported range starts at 114.

No tagalongs. The comment on the default size in authors.ts changes, because it said the byline uses that size.

Authority

  • Owner decision (nynexman4464, 2026-11-17): an avatar loads at a size picked from the size it is shown at, as the site's other images do.
  • GitHub's behavior, measured on 2026-11-17:
    • https://avatars.githubusercontent.com/u/<id>?v=4&s=96 returns a 96×96 file, and &s=48 a 48×48 file.
    • https://github.com/<name>.png?size=40 redirects to the avatar host and returns a 40×40 file.
    • https://github.com/<name>.png?s=40 returns the full file (460×460, 396 KB for one author).

Change and evidence

File Change
src/lib/githubAvatarUrl.ts New. The avatar URL at a size, and the src and srcSet of an avatar <img>.
src/app/(site)/community/page.tsx The wall asks for each avatar at its 48 pixels. The style and the request share one constant.
src/components/blog/AuthorByline.tsx The byline asks for each avatar at the size of its variant.
src/content/blog/authors.ts Comment only.
  • The byline's two sizes. The byline is a server component and the Avatar module is client code, so the byline cannot call Avatar's size scale. It holds the two pixel sizes it uses (20 and 36), and a test compares them with Avatar's resolveSize.
  • No visible change. Screenshots of the wall on production and on this build, at device scale 2, at 1440 and 390 px wide: the wall looks the same. The pixels differ only inside the avatars (3.6% of the 1440 px screenshot, mean difference 7 of 255): the browser scaled a large file down before, and GitHub scales it now.
  • Sharpness. On a 1× or 2× screen each avatar has exactly one file pixel for each device pixel on the wall, and two for each CSS pixel in the byline. On a 3× screen an avatar has two file pixels for each CSS pixel, where it had 3.6 or more.
  • Loading. On this build /community, /blog and 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 same srcset.
  • The fallback, in a real build. During the build of the head, GitHub's API refused the contributor request (its rate limit for requests without a token). The wall showed the twelve placeholder portraits with their own URLs and no srcset, as before this change.

Scope

Components: docsite community page, docsite blog byline

  • This PR has one primary intent.
  • Independently removable deltas were removed or split.
  • Public text and artifacts contain no internal Meta context.

Testing

pnpm -F @astryxdesign/docsite exec vitest run
pnpm build && pnpm -F @astryxdesign/docsite build
pnpm test:docsite-browser
pnpm review:pre
  • 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 without URL.canParse, and the srcSet.
  • 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 the Avatar scale, an author that the registry does not list, and the team avatar unchanged.
  • Mutation check: 21 mutations of the changed lines (the wrong parameter for a host, a size left in the URL, rounding down, the 1× file as src, the wall or the byline using the URL as it came, a size that differs from what the page draws, a call to URL.canParse). Each fails at least one test.
  • The docsite unit suite passes: 986 passed, 8 skipped. Type check and lint are clean.
  • The whole docsite browser suite passes on the build of the head: 59 passed; the 17 internal-docs-prompt cases skip without their environment.

Not tested: Firefox and Safari. The change has no browser-specific code; srcset with pixel-density descriptors is in every current browser.

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.
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 18, 2026 2:58am UTC

Request Review

@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 18, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 18, 2026
@astracat-bot

astracat-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 18, 2026, 3:00 AM UTC

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 74cec11

Storybook · Sandbox · built from this PR's head

Current run: The current CI run completed, but its trusted analysis is unavailable.


Generated by PR Enrichment workflow | View current CI run

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.canParse in githubAvatarUrl.ts also runs in the browser, because the byline renders inside client components on /blog and the homepage (BlogIndex, BlogShowcase), so browsers before Chrome 120 or Safari 17 throw there; parsing with try { 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 Avatar size 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 srcset and 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.ts and the three new test files: clear.

Automated review (maintainer link)

Comment thread apps/docsite/src/lib/githubAvatarUrl.ts Resolved
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.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Avatar size 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 srcset and 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.ts and the three new test files: clear.

Automated review (maintainer link)

@nynexman4464
nynexman4464 marked this pull request as ready for review November 18, 2026 22:52
@nynexman4464
nynexman4464 merged commit cda6ca7 into main Nov 19, 2026
234 of 246 checks passed
@github-actions
github-actions Bot deleted the nynexman4464/perf/docsite-avatar-sizes branch November 19, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 74cec11e Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant