fix(next-font): respect custom font-family declarations in local fonts (Turbopack) #88895
+82
−3
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.
What?
Fixes a bug in Turbopack where
next/font/localwith a customfont-familydeclaration would generate mismatched CSS:@font-facecorrectly used the custom declaration value (e.g.,"My Custom Font").classNameincorrectly used the JS variable name (e.g.,"myCustomFont")This caused the font not to apply because the names didn't match.
Why?
When users specify a custom
font-familyin declarations:The generated CSS had a mismatch:
@font-face { font-family: 'My Custom Font'; ... }✅.className { font-family: 'myCustomFont', ... }❌Note: This bug only affects Turbopack. The Webpack implementation already handles this correctly via
postcss-next-font.How?
Updated the Turbopack implementation to check for custom
font-familydeclarations when building:util.rs:build_font_family_stringnow checks declarations for a customfont-familyvalue before falling back to the variable namefont_fallback.rs:get_font_fallbacksnow uses the customfont-familyfor fallback naming (e.g.,"My Custom Font Fallback"instead of"myCustomFont Fallback")Test Plan
font-familycontaining a spacefontFamilymatches the custom declarationFixes #88894