[PR #892] [MERGED] port Next.js Google Fonts metadata + URL pipeline (PR 1 of 2 for #885) #924

Closed
opened 2026-05-06 13:10:51 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/892
Author: @NathanDrake2406
Created: 4/25/2026
Status: Merged
Merged: 4/26/2026
Merged by: @james-elicx

Base: mainHead: nathan/font-google-helpers


📝 Commits (5)

  • 6aed8ea vendor Google Fonts metadata from Next.js
  • 8755bae port Google Fonts URL pipeline from Next.js
  • f833894 port Google Fonts options validator from Next.js
  • b67c713 fold attribution into font-metadata header, drop unused exports
  • c1abf20 address PR 892 review: document subsets parity, harden preload-disable test

📊 Changes

10 files changed (+16771 additions, -0 deletions)

View changed files

packages/vinext/src/build/google-fonts/build-url.ts (+69 -0)
packages/vinext/src/build/google-fonts/font-data.json (+16071 -0)
packages/vinext/src/build/google-fonts/font-metadata.ts (+33 -0)
packages/vinext/src/build/google-fonts/get-axes.ts (+83 -0)
packages/vinext/src/build/google-fonts/sort-variants.ts (+24 -0)
packages/vinext/src/build/google-fonts/validate.ts (+165 -0)
tests/google-fonts/build-url.test.ts (+75 -0)
tests/google-fonts/get-axes.test.ts (+82 -0)
tests/google-fonts/sort-variants.test.ts (+42 -0)
tests/google-fonts/validate.test.ts (+127 -0)

📄 Description

What this changes

Vendors font-data.json from vercel/next.js and ports four pure helpers that consume it. Build-time scaffolding only; no runtime wired up.

New file Ported from
font-data.json next.js/packages/font/src/google/font-data.json
font-metadata.ts typed re-export of the JSON
sort-variants.ts next.js/packages/font/src/google/sort-fonts-variant-values.ts
build-url.ts next.js/packages/font/src/google/get-google-fonts-url.ts
get-axes.ts next.js/packages/font/src/google/get-font-axes.ts
validate.ts next.js/packages/font/src/google/validate-google-font-function-call.ts

Why

Issue #885: :wght@100..900 is hardcoded in the shim and plugin URL builders, so fonts with narrower axes (Sen 400..800, Anton 400) get HTTP 400 from Google. Investigation also found four sibling bugs in the same code: italic-only requests drop italic, the axes option is ignored, weight: 'variable' 400s, unknown families build URLs silently.

The minimal fix (drop the hardcoded range) regresses Inter from 9 weights to 1. Next.js avoids both regressions by validating + resolving axes against bundled metadata. This PR vendors that metadata and ports the helpers; PR 2 swaps the consumers and adds a Sen fixture.

Approach

Three commits: vendor metadata, port URL pipeline, port validator. A fourth cleanup commit drops NOTICE.md and an unused barrel after vp run knip flagged them; Vercel's MIT attribution lives in the font-metadata.ts header instead.

Validation

  • vp test run tests/google-fonts/: 37 new tests pass (regression case for #885, italic-only branch, axes on non-variable, unknown family, unknown subsets, preload auto-disable, every throw branch)
  • vp test run tests/font-google.test.ts: 84 existing tests still pass
  • vp check packages/vinext/src/build/google-fonts/ tests/google-fonts/: clean
  • vp run knip: clean

Risks / follow-ups

  • The vendor commit is ~16 K added lines, the upstream pretty-printed JSON (1911 fonts). Refresh by re-copying from next.js/packages/font/src/google/font-data.json.
  • "Auto-disables preload" test pins on Playwrite AR Guides. If upstream adds a subset to that family the fixture needs to change.
  • Helpers are unused until PR 2.

PR 2 (next)

  • swap shims/font-google-base.ts and plugins/fonts.ts to use the new pipeline
  • drop the silent catch { return; } around the build-time fetch so 400s surface as build errors
  • add tests/fixtures/font-narrow-axis/ (Sen) for CI regression coverage
  • extend tests/font-google.test.ts for the new throw paths

Refs #885.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/892 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 4/25/2026 **Status:** ✅ Merged **Merged:** 4/26/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `nathan/font-google-helpers` --- ### 📝 Commits (5) - [`6aed8ea`](https://github.com/cloudflare/vinext/commit/6aed8ea7699b4a24c2e2f4c46a3c53545030ea57) vendor Google Fonts metadata from Next.js - [`8755bae`](https://github.com/cloudflare/vinext/commit/8755bae1d56b677e23576fa7d6de50e5bf6cee5e) port Google Fonts URL pipeline from Next.js - [`f833894`](https://github.com/cloudflare/vinext/commit/f8338943b11ac0b3233f7879a8286a343d7fcfa3) port Google Fonts options validator from Next.js - [`b67c713`](https://github.com/cloudflare/vinext/commit/b67c71345e6d494c31a4ff019ebd4091cae47a2c) fold attribution into font-metadata header, drop unused exports - [`c1abf20`](https://github.com/cloudflare/vinext/commit/c1abf202763d40a33f20049f5e028ba86c45e5f7) address PR 892 review: document subsets parity, harden preload-disable test ### 📊 Changes **10 files changed** (+16771 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `packages/vinext/src/build/google-fonts/build-url.ts` (+69 -0) ➕ `packages/vinext/src/build/google-fonts/font-data.json` (+16071 -0) ➕ `packages/vinext/src/build/google-fonts/font-metadata.ts` (+33 -0) ➕ `packages/vinext/src/build/google-fonts/get-axes.ts` (+83 -0) ➕ `packages/vinext/src/build/google-fonts/sort-variants.ts` (+24 -0) ➕ `packages/vinext/src/build/google-fonts/validate.ts` (+165 -0) ➕ `tests/google-fonts/build-url.test.ts` (+75 -0) ➕ `tests/google-fonts/get-axes.test.ts` (+82 -0) ➕ `tests/google-fonts/sort-variants.test.ts` (+42 -0) ➕ `tests/google-fonts/validate.test.ts` (+127 -0) </details> ### 📄 Description ## What this changes Vendors `font-data.json` from `vercel/next.js` and ports four pure helpers that consume it. Build-time scaffolding only; no runtime wired up. | New file | Ported from | |---|---| | `font-data.json` | `next.js/packages/font/src/google/font-data.json` | | `font-metadata.ts` | typed re-export of the JSON | | `sort-variants.ts` | `next.js/packages/font/src/google/sort-fonts-variant-values.ts` | | `build-url.ts` | `next.js/packages/font/src/google/get-google-fonts-url.ts` | | `get-axes.ts` | `next.js/packages/font/src/google/get-font-axes.ts` | | `validate.ts` | `next.js/packages/font/src/google/validate-google-font-function-call.ts` | ## Why Issue #885: `:wght@100..900` is hardcoded in the shim and plugin URL builders, so fonts with narrower axes (Sen 400..800, Anton 400) get HTTP 400 from Google. Investigation also found four sibling bugs in the same code: italic-only requests drop italic, the `axes` option is ignored, `weight: 'variable'` 400s, unknown families build URLs silently. The minimal fix (drop the hardcoded range) regresses Inter from 9 weights to 1. Next.js avoids both regressions by validating + resolving axes against bundled metadata. This PR vendors that metadata and ports the helpers; PR 2 swaps the consumers and adds a Sen fixture. ## Approach Three commits: vendor metadata, port URL pipeline, port validator. A fourth cleanup commit drops `NOTICE.md` and an unused barrel after `vp run knip` flagged them; Vercel's MIT attribution lives in the `font-metadata.ts` header instead. ## Validation - `vp test run tests/google-fonts/`: 37 new tests pass (regression case for #885, italic-only branch, axes on non-variable, unknown family, unknown subsets, preload auto-disable, every throw branch) - `vp test run tests/font-google.test.ts`: 84 existing tests still pass - `vp check packages/vinext/src/build/google-fonts/ tests/google-fonts/`: clean - `vp run knip`: clean ## Risks / follow-ups - The vendor commit is ~16 K added lines, the upstream pretty-printed JSON (1911 fonts). Refresh by re-copying from `next.js/packages/font/src/google/font-data.json`. - "Auto-disables preload" test pins on `Playwrite AR Guides`. If upstream adds a subset to that family the fixture needs to change. - Helpers are unused until PR 2. ## PR 2 (next) - swap `shims/font-google-base.ts` and `plugins/fonts.ts` to use the new pipeline - drop the silent `catch { return; }` around the build-time fetch so 400s surface as build errors - add `tests/fixtures/font-narrow-axis/` (Sen) for CI regression coverage - extend `tests/font-google.test.ts` for the new throw paths Refs #885. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:10:52 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#924
No description provided.