fix(font): not emitting 400 as default value when font weight is omitted - #2796
Open
NriotHrreion wants to merge 1 commit into
Open
fix(font): not emitting 400 as default value when font weight is omitted#2796NriotHrreion wants to merge 1 commit into
NriotHrreion wants to merge 1 commit into
Conversation
…ted (cloudflare#2793) Emitting `font-weight: 400;` when weight is omitted will clamp the wght axis of variable fonts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2793
Overview
The
next/font/localshim emitsfont-weight: 400when no weight was specified. For variable fonts with awghtaxis, this descriptor clamps the font face to its regular 400 instance, preventing heavier weights from rendering correctly even when elements usefont-weight: 600or700.This aligns vinext with Next.js and the CSS Fonts specification by allowing the descriptor to retain its default
autobehavior 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
400ifweightis not providedvinext/packages/vinext/src/shims/font-local.ts
Line 120 in d65ff09
vinext/packages/vinext/src/shims/font-local.ts
Lines 132 to 138 in d65ff09
The new behavior doesn't set font weight if
weightis not provided, leaving it asautorules.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.tsNotes
I ran into this issue when migrating my project to vinext. Applying the fix is quite important to me. Thanks for reviewing!