-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next.js next/font does not apply to components with presentation role #37080
Comments
The two workarounds are below. Each method has a drawback.
const montserrat = Montserrat({ subsets: ['latin'], variable: '--font-montserrat' })
const readexPro = Readex_Pro({ subsets: ['latin'], variable: '--font-readex-pro' })
const MyApp = ({ Component, pageProps, router }: AppPropsWithLayout) => {
//other bootstrap code
return (
<>
<style global jsx>
{`
html {
font-family: ${montserrat.style.fontFamily};
}
`}
</style>
<div className={cx(montserrat.variable, readexPro.variable)}>
<StyledEngineProvider injectFirst>
<ThemeProvider theme={sharpTheme}>
<CssBaseline />
<SSRProvider>
<Component {...pageProps} {...router} />
</SSRProvider>
</ThemeProvider>
</StyledEngineProvider>
</div>
</>
);
}
const montserrat = Montserrat({ subsets: ['latin'] })
const readexPro = Readex_Pro({ subsets: ['latin'] })
const baseThemeOptions: ThemeOptions = {
typography: {
fontFamily: [montserrat.style.fontFamily, 'helvetica neue', 'sans-serif'].join(','),
fontWeightBold: 700,
body1: {
fontFamily: [readexPro.style.fontFamily, 'arial', 'sans-serif'].join(','),
fontSize: 13,
fontWeight: 300,
textTransform: 'none',
letterSpacing: 0.65,
},
}
}
|
Linking this to the Next.js 13 umbrella issue: #34905 |
It's not a bug, but a question/docs problem. The behavior described looks expected to me (based on how it was configured. It surfaces the need for #38082. A CSS variable is applied to a div, which only impacts its children, when a component that uses a portal is used, it's not under the parent CSS variable, so doesn't know about the font family. In #38095, I pushed a commit, I think it's the right way to do it, hopefully if developers are using this as a starting point, it will already solve an good chunk of the problem, see below for an even better fix ⬇️ |
Duplicate of #38082 |
I have the same issue when using "Syncopate" google font with nextjs 13.4.19. |
My issue is exactly same, with TextareaAutoSize component. Its showing text with monospace font under this component, where as we had put Montserrat as global font and this global font is applicable to all components except TextareaAutoSize component in our project |
This is really lame. |
Duplicates
Latest version
Steps to reproduce 🕹
Live Version: I was unable to get next/font to work in Codesandbox.
Related: vercel/next.js#45433
Steps:
Current behavior 😯
The next/font styles are applying correctly to all components that do not have the presentation role. The font is probably added to the css output but the font is not found, causing the browser to use a fallback.
Expected behavior 🤔
next/font declarations are applied to all MUI components
Context 🔦
We are attempting to use next/font to remove the CLS from Google Fonts and optimizer our page load. The fonts are being applied correctly to all elements except those with presentation role. See related issue from NextJS
Your environment 🌎
npx @mui/envinfo
The text was updated successfully, but these errors were encountered: