mirror of
https://github.com/bitbaum/petvity.git
synced 2026-12-04 16:26:59 +01:00
next/font/google downloaded the faces from fonts.gstatic.com **at build time**, which put a third party on the critical path of every CI run and every deploy. It failed twice in one week — module-not-found on the generated @font-face for Jost — blocking a merge each time, both on changes that had nothing to do with typography. A build that only succeeds when Google is reachable cannot be trusted to ship an urgent fix, and re-running until it passes is not a fix. The four .woff2 files are now vendored in lib/font-files/ and declared with next/font/local. 82 KB total, which also removes a render-blocking third-party connection for every visitor. Only the `latin` subset is vendored, matching the previous `subsets: ["latin"]` exactly — ja/zh/ko/ar and the Turkish latin-ext glyphs fell back to system faces before and still do. Plus Jakarta Sans (400–800) and Jost (200–400) are variable fonts, so each is a single file; IBM Plex Mono ships no variable axis and keeps its two static weights. scripts/fetch-fonts.mjs regenerates the files and documents where they came from. It is deliberately NOT wired into the build — doing so would reintroduce the exact network dependency this removes. Verified rendering is unchanged, not merely similar: measured actual glyph advance widths with a Range over the live hero text on prod (Google-hosted) and on the local build (self-hosted). Identical to three decimals — h1 669.688px, eyebrow 222.641px — and the screenshots are pixel-identical. The emitted @font-face URLs are now local ../media/*.woff2 with no gstatic reference in the build output. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
52 lines
2.1 KiB
TypeScript
52 lines
2.1 KiB
TypeScript
import localFont from "next/font/local";
|
||
|
||
/** SSOT for the app's font faces. Both root layout and the [locale] layout
|
||
* render their own <html>, so both must carry these variable classes —
|
||
* import `fontVariables` rather than redeclaring the fonts.
|
||
*
|
||
* The files are vendored in ./font-files rather than fetched by
|
||
* next/font/google, which downloaded them from fonts.gstatic.com **at build
|
||
* time**. That put Google on the critical path of every CI run and every
|
||
* deploy: it failed twice in one week with a module-not-found on the generated
|
||
* @font-face, blocking a merge each time, and a build that only works when a
|
||
* third party is reachable cannot be trusted to ship an urgent fix.
|
||
*
|
||
* Only the `latin` subset is vendored, matching the previous
|
||
* `subsets: ["latin"]` exactly — the non-latin locales (ja/zh/ko/ar, and the
|
||
* Turkish latin-ext glyphs) fell back to system faces before and still do.
|
||
*
|
||
* To refresh or add a weight: edit scripts/fetch-fonts.mjs, run it, commit the
|
||
* .woff2. It is deliberately not wired into the build — that would reintroduce
|
||
* the network dependency this removes. */
|
||
|
||
// Body — everywhere. Variable font, 400–800.
|
||
const sans = localFont({
|
||
src: "./font-files/PlusJakartaSans-latin.woff2",
|
||
weight: "400 800",
|
||
variable: "--font-sans",
|
||
display: "swap",
|
||
});
|
||
|
||
// Luxury-futurist display face — ultra-light geometric (Futura lineage) for
|
||
// the obsidian marketing surface. Large sizes carry the thin weights.
|
||
// Variable font, 200–400.
|
||
const display = localFont({
|
||
src: "./font-files/Jost-latin.woff2",
|
||
weight: "200 400",
|
||
variable: "--font-display",
|
||
display: "swap",
|
||
});
|
||
|
||
// Instrument mono — eyebrows, data labels, telemetry-style details.
|
||
// Static weights; IBM Plex Mono ships no variable axis.
|
||
const mono = localFont({
|
||
src: [
|
||
{ path: "./font-files/IBMPlexMono-400-latin.woff2", weight: "400", style: "normal" },
|
||
{ path: "./font-files/IBMPlexMono-500-latin.woff2", weight: "500", style: "normal" },
|
||
],
|
||
variable: "--font-mono",
|
||
display: "swap",
|
||
});
|
||
|
||
export const fontVariables = `${sans.variable} ${display.variable} ${mono.variable}`;
|