[Typography] Add applyRobotoLetterSpacing option to fix letter spacing with CSS variable fontFamily#48474
Closed
starboyvarun wants to merge 1 commit into
Closed
Conversation
…ing with CSS variable fontFamily (mui#47575)
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
mj12albert
reviewed
May 4, 2026
| @@ -29,6 +29,12 @@ export interface FontStyle { | |||
|
|
|||
| export interface FontStyleOptions extends Partial<FontStyle> { | |||
| allVariants?: React.CSSProperties | undefined; | |||
| /** | |||
Member
There was a problem hiding this comment.
IMO this is too niche to justify adding to the API surface #47575 (comment)
Member
|
I'm closing this PR. Would you mind creating a separate PR to update the docs instead? Thank you for your effort. |
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.
Fixes #47575
Problem
The Next.js font optimization guide recommends setting
typography.fontFamily: 'var(--font-roboto)'in the theme. However,createTypographyapplies Roboto-specific letter spacing only whenfontFamily === defaultFontFamily(strict string equality). A CSS variable reference never matches that string, so the letter spacing is silently dropped — even though the font in use is still Roboto.This was identified by @Janpot in #47575. A previous PR (#47627) attempted heuristic string detection which was rightly rejected as too fragile.
Solution
Add an explicit
applyRobotoLetterSpacingoption totypography(option 2 from @Janpot's comment). It defaults tofontFamily === defaultFontFamily, preserving existing behaviour for all current users. Callers who reference Roboto via a CSS variable can opt in:Changes
createTypography.js— extractapplyRobotoLetterSpacing(defaultfontFamily === defaultFontFamily) and use it inbuildVariantcreateTypography.d.ts— add type with JSDocnextjs.md— addapplyRobotoLetterSpacing: trueto both App Router and Pages Router font optimization examples