Next font sever/client mismatch in app dir
Hi trying to include a style tag which sets css vars based on next font but get the following error
seems likes next font is adding ' on the server, tried logging it but didn't appear in logs ty for any help
here is the layout.tsx (root layout)
Solution:Jump to solution
It looks like it’s encoding the
'
. What happens if you dangerously set html for var styles6 Replies
Solution
It looks like it’s encoding the
'
. What happens if you dangerously set html for var stylesThat said, I don’t think you need to use the style tag. It should be applying it automatically
ty the encoding was the issue : D
I'm using tailwind & my tailwind config references the css var, so when the app loads it briefly flashes the font as the var is undefined, so have to set it in the html
wrote this to fix the error
thanks again OwO
never mind <body className={
${font_p.variable}
}> is performing the same functionality I'm implementing by setting the css var it seems, but the flashing of the font still remains T~TThis shouldn’t happen. Check this doc https://nextjs.org/docs/app/building-your-application/optimizing/fonts#with-tailwind-css
Optimizing: Fonts
Optimize your application's web fonts with the built-in
next/font
loaders.ty that's how I have it setup except for the className on the body, after switching it to the html the brief flash was even shorter : D
was also reading this
https://www.lydiahallie.io/blog/optimizing-webfonts-in-nextjs-13
and it seems that a brief flash is inevitable as long as the page loads before the font does, which is probably the case if I'm building and running locally, & reloading the page without the cache
Optimizing Web Fonts in Next.js 13
Learn more about optimizing web fonts and the @next/font module in Next.js 13.