Skip to content

FE-M0-16 · Fonts through next/font, with no request to Google

ID FE-M0-16 · Level L0 · Run order row 28, after FE-M0-14 is merged · Why the Lighthouse audit, D8

Inter Tight and JetBrains Mono are hosted by the app itself, through next/font, and a page opening makes no request to fonts.googleapis.com or fonts.gstatic.com. Line 1 of design/opleet/opleet.css imports Google Fonts as a CSS @import, which holds up the page until two other origins have answered. The copy stays byte for byte as the design system published it (D8); postcss.config.mjs drops that one @import when the CSS is built, and app/layout.tsx loads both fonts. Committed on the branch web/fonts and merged.

  • FE-M0-14 is Done and pack D is merged: this step's app/layout.tsx and app/app.css are pack D's with the fonts added, and block 2 checks that first.
  • fe-pack-d.zip is unzipped in ~/opleet-v2/packs (FE-M0-12 block 1). FE-M0-16's folder is in it.
  • The Mac is online: the first build downloads the two fonts from Google once, and from then on serves them itself. Vercel is online at build time too.
  • You are in ~/opleet-v2/opleet and git status --short prints nothing.
Terminal window
git switch main && git pull
git switch -c web/fonts

2 · Check the four files this step replaces, then copy them: layout.tsx, app.css, postcss.config.mjs and the note in design/opleet/SOURCE.md

Section titled “2 · Check the four files this step replaces, then copy them: layout.tsx, app.css, postcss.config.mjs and the note in design/opleet/SOURCE.md”
Terminal window
shasum -a 256 -c ~/opleet-v2/packs/fe-pack-d/FE-M0-16/BASE.sha256 &&
cp -R ~/opleet-v2/packs/fe-pack-d/FE-M0-16/apps . &&
git status --short
Terminal window
pnpm --filter web typecheck
pnpm lint
pnpm --filter web build

4 · Start the app, open the sign-in page with the browser's Network tab open, and filter it by “font”. Then stop the app with Ctrl+C

Section titled “4 · Start the app, open the sign-in page with the browser's Network tab open, and filter it by “font”. Then stop the app with Ctrl+C”
Terminal window
pnpm --filter web dev

5 · Commit, push, open the pull request, merge

Section titled “5 · Commit, push, open the pull request, merge”
Terminal window
git add -A apps/web
git commit -m "feat(web): host the fonts with next/font (d8)"
git push -u origin web/fonts
gh pr create --title "feat(web): host the fonts with next/font" --body "FE-M0-16: no request to Google Fonts; opleet.css unchanged (D8)."
gh pr checks --watch
gh pr merge --squash --delete-branch
git switch main
git pull
  • Block 2: four lines ending in “: OK”, then M for apps/web/app/app.css, apps/web/app/layout.tsx, apps/web/design/opleet/SOURCE.md and apps/web/postcss.config.mjs, and nothing else.
  • Block 3: typecheck prints “design/opleet/tokens.css and theme.css are up to date”, the Keys line and no errors; “No fixes applied.”; the build lists the same routes as FE-M0-10 and does not fail on a font.
  • Block 4: two font files, both from localhost:3000/_next/static/media, with a name ending in .woff2; no request to fonts.googleapis.com or fonts.gstatic.com. The sign-in page looks the same as before.
  • Block 5: checks and pr-title pass, then “✓ Squashed and merged pull request #…”.

Run it after block 3, before block 5.

Terminal window
grep -rlE 'fonts\.(googleapis|gstatic)\.com' apps/web/.next/static apps/web/.next/server
ls apps/web/.next/static/media | grep -c '\.woff2$'
(cd apps/web && shasum -a 256 -c design/opleet/SHA256SUMS | grep -vc ': OK$')

Expect: the first prints nothing; the second prints 2; the third prints 0, so every file in design/opleet still matches its checksum.

Then run the Lighthouse audit again, on the Vercel preview of the pull request or on pnpm --filter web build and pnpm --filter web start, and log the score on #18. The fonts should no longer appear among the render-blocking requests, and the waterfall has no third-party origin for them. If a score moved, say which one.

  • Block 2 prints “FAILED” for a file and stops: your copy of that file is not pack D's (main has changed it, or it was edited by hand). Nothing was copied. Paste the FAILED lines and stop; FE rebuilds the step.
  • The build says “Failed to fetch Inter Tight from Google Fonts”: this machine could not reach Google while building. Check the connection and run block 3 again. Paste the line if it repeats.
  • A request to fonts.googleapis.com is still there: the first command of the Check lists the file that holds it. If that is a .css file in .next, postcss.config.mjs did not run: paste cat apps/web/postcss.config.mjs.
  • The text shows in the system font: open the Elements tab, select <html>, and look at its class and at the computed --font-sans. The class should hold the two names from next/font, and --font-sans should start with var(--font-inter-tight). Paste both.
  • A shift of the text as the font arrives: expected for a moment. display: swap shows the text at once, and next/font gives the fallback font Inter Tight's metrics so the lines don't move.
Terminal window
git checkout -- apps/web
git switch main
git branch -D web/fonts

Before the commit. After it, before merging: gh pr close --delete-branch. After merging: revert it with a new pull request.

Not run yet.