next.js: @next/font font-weight not working correctly in Chrome

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 21.4.0: Fri Mar 18 00:46:32 PDT 2022; root:xnu-8020.101.4~15/RELEASE_ARM64_T6000 Binaries: Node: 14.19.0 npm: 6.14.16 Yarn: 1.22.17 pnpm: 7.13.2 Relevant packages: next: 13.1.1 eslint-config-next: 13.1.1 react: 18.2.0 react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

Font optimization (@next/font)

Link to the code that reproduces this issue

https://github.com/denvradiy/next-fonts-loading-issue

To Reproduce

Hard refresh (shift + command+ R) the page multiple times in Chrome in host and font-weight will crash.

Describe the Bug

If you refresh the page with reseting the cache (shift + command+ R) multiple times in Chrome then font-weight crashes and displays incorrectly.

This bug appears only on host (in this case it’s vercel). But if I run next build and next start locally on my computer then it works correctly.

For testing purposes I took generated create-next-app example and didn’t change anything

https://github.com/denvradiy/next-fonts-loading-issue - repo to reproduce https://next-fonts-loading-issue.vercel.app/ - vercel https://monosnap.com/file/2uyrSIIo3k4pMpKW0H9RV1JUB4WY9m - screen recording

Expected Behavior

Font weight should work correctly in all modern browsers

Which browser are you using? (if relevant)

Chrome

How are you deploying your application? (if relevant)

Vercel

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 6
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Also facing this issue

Inter with font weight of 400, 500, and 700 works for me but not 600

adding display: ‘swap’ to the font config fixed my issue

I have exactly the same issue, would be great to fix it asap

I’ve also tried many things. Spent so many hours fixing this. But lastly this is working

body { -webkit-font-smoothing: antialiased; /* Improves clarity / -moz-osx-font-smoothing: grayscale; / Improves clarity */ }

Add this to your global.css file.

I’m experiencing the same issue. The font-weight works for the fonts imported from “next/font/google” but it does not work for local fonts at all. Any quick fix?

Update: For anyone working with local fonts, make sure to pass font-weight as range like this:

const CabinetGrotesk = localFont({
  src: './CabinetGrotesk.ttf',
  variable: '--font-CG',
  display: 'swap',
  style: 'normal',
  weight: '100 1000',
})

I ended up working around the bug by using a <style> tag instead:

      <style jsx global>{`
        html {
          font-family: ${inter.style.fontFamily};
        }
      `}</style>

Now font-weights are working again.