[docs] Fix Next.js font optimization to preserve typography letter-spacing#48488
Open
starboyvarun wants to merge 7 commits into
Open
[docs] Fix Next.js font optimization to preserve typography letter-spacing#48488starboyvarun wants to merge 7 commits into
starboyvarun wants to merge 7 commits into
Conversation
…acing Using `typography.fontFamily: 'var(--font-roboto)'` in the theme causes Material UI to skip Roboto-specific letter-spacing values. This is because createTypography only applies them when fontFamily strictly equals the default Roboto stack string, and a CSS variable never matches that check. Update both App Router and Pages Router font optimization examples to use `roboto.className` on the root element instead. This leaves the theme fontFamily at its default value, preserving all Roboto letter-spacing, while Next.js still self-hosts and preloads the font at build time. Adds a warning callout to explain the CSS variable limitation for users who intentionally override fontFamily. Closes mui#47575
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
…uide Use non-breaking spaces in all 'Material UI' brand name occurrences added in the font optimization sections.
siriwatknp
reviewed
May 8, 2026
Member
There was a problem hiding this comment.
LGTM for the default roboto font but using variable still required for custom font right?
If yes, I think a new section "Custom font" should be added with the variable approach.
### Font optimization
…what you have updated
### Custom font
…
const theme = createTheme({
typography: {
fontFamily: 'var(--font-geist)',
},
});
…
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 #47575
Problem
The current Next.js font optimization docs recommend using
typography.fontFamily: 'var(--font-roboto)'in the theme. This silently breaks Roboto's letter-spacing values for all typography variants.createTypographyonly applies letter-spacing whenfontFamilystrictly equals the default Roboto font stack string ('"Roboto", "Helvetica", "Arial", sans-serif'). A CSS variable (var(--font-roboto)) never matches that string, so all variants lose their tuned letter-spacing.Solution
Update both the App Router and Pages Router font optimization examples to use
roboto.classNameon the root element instead of a CSS variable. This:typography.fontFamilyat its default value → letter-spacing check passes ✓"Roboto"— including Material UI components ✓theme.tsfile needed just forfontFamilyA
:::warningcallout is added to both sections to explain the CSS variable limitation for users who intentionally overridefontFamily.As suggested by @siriwatknp when closing #48474.