mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #158] feat: implement next/font/google and next/font/local with build-time metrics #357
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#357
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/158
Author: @dknecht
Created: 2/27/2026
Status: 🔄 Open
Base:
main← Head:feat/next-font-implementation📝 Commits (1)
f069e47feat: implement next/font/google and next/font/local with build-time metrics📊 Changes
19 files changed (+2375 additions, -753 deletions)
View changed files
📝
.agents/skills/migrate-to-vinext/SKILL.md(+1 -1)📝
.agents/skills/migrate-to-vinext/references/compatibility.md(+2 -2)📝
README.md(+3 -3)📝
packages/vinext/package.json(+2 -0)📝
packages/vinext/src/check.ts(+2 -2)➕
packages/vinext/src/font-metrics.ts(+391 -0)📝
packages/vinext/src/index.ts(+298 -56)📝
packages/vinext/src/shims/font-google.ts(+131 -310)📝
packages/vinext/src/shims/font-local.ts(+104 -268)➕
packages/vinext/src/shims/font-utils.ts(+304 -0)📝
pnpm-lock.yaml(+24 -5)📝
tests/check.test.ts(+11 -14)➕
tests/fixtures/fonts/LICENSE(+7 -0)➕
tests/fixtures/fonts/inter-latin-400.woff2(+0 -0)📝
tests/font-google.test.ts(+63 -30)📝
tests/font-local-transform.test.ts(+188 -49)➕
tests/font-metrics.test.ts(+504 -0)➕
tests/font-utils.test.ts(+326 -0)📝
tests/shims.test.ts(+14 -13)📄 Description
Summary
next/font/googleandnext/font/localparity with Next.js, including deterministic hashing, CSS sanitization, and build-time fallback font metrics via@capsizecss/metricsandfontkittenfont-utils.ts(sanitization, hashing, SSR injection) andfont-metrics.ts(capsize math, metrics lookup, fallback generation)Details
New files
packages/vinext/src/font-metrics.ts— Build-time module: capsize math, Google/local font metrics lookup, hashed font-family names, fallback @font-face generation (async, uses dynamic imports for@capsizecss/metricsandfontkitten)packages/vinext/src/shims/font-utils.ts— Shared runtime module: CSS sanitization helpers (escapeCSSString,sanitizeCSSVarName,sanitizeFallback, etc.), deterministic djb2 hashing,FontSSRStatecontainer, CSS injection helpers with dedup, shared:rootvariable dedup across font modulestests/font-utils.test.ts— 45 unit tests for all font-utils functionstests/font-metrics.test.ts— 55 tests including local font file parsing with real Inter woff2 fixturePlugin changes
index.ts): Balanced-brace matching replaces fragile[^}]*regex;localToOriginalmap handlesimport { Inter as MyFont }renames; build mode fetches CSS + woff2 files, rewrites font-family, generates fallback metricsindex.ts): Build mode reads font files viafontkitten, generates self-hosted CSS with hashed families and size-adjust fallbacksfont-utils.ts, eliminating ~400 lines of duplicationType safety
as anyor!non-null assertions in test filesGoogleFontsTestPlugin,GoogleFontProxy,Record<string, unknown>)Test coverage
unitsPerEm=0edge case, multiplelocalFont()calls per file, import renames, balanced-brace parsing, SSR injection dedupKnown limitations (pre-existing, not introduced here)
_selfHostedCSScontains absolute filesystem paths — production on Workers needs web-relative paths (requires separate rearchitecting)(this as any)._isBuildin plugins — pre-existing Vite ecosystem pattern🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.