Skip to content

fix(font): not emitting 400 as default value when font weight is omitted - #2796

Open
NriotHrreion wants to merge 1 commit into
cloudflare:mainfrom
NriotHrreion:fix/issue-2793-variable-fonts-clamping
Open

fix(font): not emitting 400 as default value when font weight is omitted#2796
NriotHrreion wants to merge 1 commit into
cloudflare:mainfrom
NriotHrreion:fix/issue-2793-variable-fonts-clamping

Conversation

@NriotHrreion

@NriotHrreion NriotHrreion commented Aug 3, 2026

Copy link
Copy Markdown

Closes #2793

Overview

The next/font/local shim emits font-weight: 400 when no weight was specified. For variable fonts with a wght axis, this descriptor clamps the font face to its regular 400 instance, preventing heavier weights from rendering correctly even when elements use font-weight: 600 or 700.

This aligns vinext with Next.js and the CSS Fonts specification by allowing the descriptor to retain its default auto behavior when omitted, while preserving explicit single weights, weight ranges, and source-level overrides. The fix applies consistently to both development and production output.

What changed

The original behavior sets font weight to 400 if weight is not provided

const weight = sanitizeFontDescriptorValue(src.weight ?? options.weight ?? "400") ?? "400";

rules.push(`@font-face {
font-family: '${escapeCSSString(family)}';
src: url('${escapeCSSString(src.path)}') format('${format}');
font-weight: ${weight};
font-style: ${style};
font-display: ${display};
}`);

The new behavior doesn't set font weight if weight is not provided, leaving it as auto

rules.push(`@font-face {
  font-family: '${escapeCSSString(family)}';
  src: url('${escapeCSSString(src.path)}') format('${format}');
- font-weight: ${weight};
- font-style: ${style};
+ ${weight === undefined ? "" : `  font-weight: ${weight};\n`}  font-style: ${style};
  font-display: ${display};
}`);

Testing

Corresponding tests are added or updated.

  • pnpm test tests/app-router-font-google-prod.test.ts tests/font-local-transform.test.ts tests/pages-router-font-google-prod.test.ts

Notes

I ran into this issue when migrating my project to vinext. Applying the fix is quite important to me. Thanks for reviewing!

…ted (cloudflare#2793)

Emitting `font-weight: 400;` when weight is omitted will clamp the wght axis of variable fonts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

next/font/local emits font-weight: 400 when weight is omitted, clamping variable fonts

1 participant