Issues with next google fonts

According to next docs, I applied config in _app. and tailwind.config.mjs, but this approach works badly, after some refresh app shows the expected font and sometimes the default font is displayed. import { type AppType } from "next/app"; import { type Session } from "next-auth"; import { SessionProvider } from "next-auth/react"; import { Space_Grotesk } from "@next/font/google"; const spaceGrotesk = Space_Grotesk({ variable: "--font-space-grotesk", subsets: ["latin"], }); import { trpc } from "../utils/trpc"; import "../styles/globals.css"; import { Layout } from "src/components/layout"; const MyApp: AppType<{ session: Session | null; withoutNavbar: boolean }> = ({ Component, pageProps: { session, ...pageProps }, }) => { return ( <SessionProvider session={session}> <main className={${spaceGrotesk.variable} min-h-screen font-sans}> <Layout withoutNavbar={pageProps.withoutNavbar}> <Component {...pageProps} /> </Layout> </main> </SessionProvider> ); }; export default trpc.withTRPC(MyApp); // eslint-disable-next-line @typescript-eslint/no-var-requires const { fontFamily } = require("tailwindcss/defaultTheme"); / @type {import('tailwindcss').Config} */ module.exports = { mode: "jit", content: ["./src//*.{js,ts,jsx,tsx}"], theme: { extend: { fontFamily: { sans: ["var(--font-space-grotesk)", ...fontFamily.sans], }, }, }, plugins: [], };
10 Replies
barry
barry3y ago
you need to set swap i dont remember the exact property
const font = fontThing({
weight...,
whatnot...,
fontSwap: something here, idk if its called fontswap or something else
})
const font = fontThing({
weight...,
whatnot...,
fontSwap: something here, idk if its called fontswap or something else
})
nexxel
nexxel3y ago
const spaceGrotesk = Space_Grotesk({
variable: "--font-space-grotesk",
subsets: ["latin"],
display: "swap",
});
const spaceGrotesk = Space_Grotesk({
variable: "--font-space-grotesk",
subsets: ["latin"],
display: "swap",
});
i think
barry
barry3y ago
something like that yh i had to play around with it to find out and i found it randomly
nexxel
nexxel3y ago
@next/font uses display optional as default
barry
barry3y ago
weird its not mentioned somewhere
nexxel
nexxel3y ago
which i think is kinda dumb since they do all the calculation to minimize layout shift while swappig in the font makes no sense why optional is default
nexxel
nexxel3y ago
@next/font | Next.js
Optimizing loading web fonts with the built-in @next/font loaders.
barry
barry3y ago
yh ofc theres docs on that but they didnt think that some people wouldnt know you need display swap but i also think its browser sided, afaik different browsers behave differently with display optional
nexxel
nexxel3y ago
yeah its a bad default
kewinzaq1
kewinzaq1OP3y ago
thanks guys i really appreciate it
Want results from more Discord servers?
Add your server