Skip to content
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

Font Optimization is not fully working #35835

Closed
1 task done
okisdev opened this issue Apr 2, 2022 · 14 comments · Fixed by #36837
Closed
1 task done

Font Optimization is not fully working #35835

okisdev opened this issue Apr 2, 2022 · 14 comments · Fixed by #36837
Labels
bug Issue was opened via the bug report template. Font (next/font) Related to Next.js Font Optimization.

Comments

@okisdev
Copy link

okisdev commented Apr 2, 2022

Verify canary release

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

Provide environment information

Operating System:
      Platform: darwin
      Arch: arm64
      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: 17.8.0
      npm: 8.5.5
      Yarn: 1.22.18
      pnpm: N/A
    Relevant packages:
      next: 12.1.4
      react: 18.0.0
      react-dom: 18.0.0

What browser are you using? (if relevant)

Chrome 100.0.4896.60

How are you deploying your application? (if relevant)

Vercel, Heroku

Describe the Bug

Font Optimization is not working fully.

This happened after upgrading to React@18.

I have set up the project and using _document.tsx would like to add some of Google Fonts.

This is what it looks like in _document.tsx.
CleanShot 2022-04-02 at 17 07 48@2x

This is what it should look like after deployment.
CleanShot 2022-04-02 at 17 09 31@2x

However, this is what it looks currently like after deployment.
CleanShot 2022-04-02 at 17 10 30@2x

The href is turned to data-href after font optimization. But, link is not turned to style.

Expected Behavior

Font Optimization should work.

To Reproduce

Since it appears in individual projects, it is normal in most cases. So it's hard to reproduce. I tried, but I can't reproduce it by creating a new project.

@okisdev okisdev added the bug Issue was opened via the bug report template. label Apr 2, 2022
@firatciftci
Copy link

I am also experiencing the same issue. This problem started after upgrading my project to React 18.0.0.

@irekrog
Copy link
Contributor

irekrog commented Apr 5, 2022

Same issue, after upgraded to React 18 external fonts doesn't work after build (on dev works)

@balazsorban44 balazsorban44 added Font (next/font) Related to Next.js Font Optimization. React 18 labels Apr 5, 2022
@balazsorban44
Copy link
Member

Related: #24781 (comment)

@firatciftci
Copy link

@balazsorban44 My _document.js file is in the class component format and I am stil experiencing the issue.

@okisdev
Copy link
Author

okisdev commented Apr 5, 2022

Hi, @balazsorban44. I'm having the same situation as @firatciftci. So, it is may not be because class or function cause this issue.
Besides, as @irekrog said, when using next dev, font optimization works, however, it doesn't work for next build.

@irekrog
Copy link
Contributor

irekrog commented Apr 5, 2022

Yep, and I've just noticed one thing. Fonts doesn't work when the page includes getServerSideProps. With static pages using getStaticProps or without any data fetching function fonts works fine.

@ronsj
Copy link

ronsj commented Apr 10, 2022

From a fresh install and copying exactly what is suggested in the Font Optimization docs. The Inter font does not display.

After some research on font-display: optional it seems like this is the intended behavior.

https://css-tricks.com/really-dislike-fout-font-display-optional-might-jam/

If you’d prefer that if the web font isn’t immediately available, to just show the fallback font and not ever swap to it, even after it’s downloaded. You can! That’s what font-display: optional; does. It still gives the ~100ms font block period (giving the font a fighting chance to show up on first page view), but after that, the fallback is shown and will not swap. Chances are, the font did ultimately get downloaded, and next page view it will be cached and used.

I ended up switching the display param in the Google Fonts URL from optional to swap just to get it to show the Inter font all the time.

@firatciftci
Copy link

@ronsj I have display=swap set in the <link /> tag and doing it that way unfortunately does not work:

<link
  href="https://fonts.googleapis.com/css2?family=Jost:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"
  rel="stylesheet"
/>

I am not sure how to best achieve setting up font-display: swap; globally though. Any thoughts/recommendations on that so I can try it out and see if it fixes anything?

@Cianekjr
Copy link

Temporary fix:
https://nextjs.org/docs/basic-features/font-optimization#disabling-optimization
Add:
optimizeFonts: false,
to your next.config.js.

Then it won't change href to data-href.

powerfulyang added a commit to powerfulyang/powerfulyang.com that referenced this issue Apr 16, 2022
1. react@18 下 font-optimization 有 BUG, Temporary fix:
optimizeFonts: false; vercel/next.js#35835 (comment)
2. next@12.1.5 swcMinify 有 BUG, 12.1.4 还是好的, Temporary fix:
swcMinify: false; vercel/next.js#36127 (comment)
3. 当前 next@12.1.5 和 @sentry/nextjs@6.19.6 的情况有 BUG, 不会上传 sourcemap 不知道以前是否是好; getsentry/sentry-javascript#3579 (comment)
powerfulyang added a commit to powerfulyang/powerfulyang.com that referenced this issue Apr 16, 2022
1. react@18 下 font-optimization 有 BUG, Temporary fix:
optimizeFonts: false; vercel/next.js#35835 (comment)
2. next@12.1.5 swcMinify 有 BUG, 12.1.4 还是好的, Temporary fix:
swcMinify: false; vercel/next.js#36127 (comment)
3. 当前 next@12.1.5 和 @sentry/nextjs@6.19.6 的情况有 BUG, 新发现仅仅 Windows 有问题, 不会上传 sourcemap 不知道以前是否是好; getsentry/sentry-javascript#3579 (comment)
@cleberj
Copy link

cleberj commented May 9, 2022

Seems like

const generateStaticHTML = supportsDynamicHTML !== true

we always have generateStaticHTML as false.
image

Hence the processors never work for ssr:

image

There were some commits 3 months ago regarding this. Not sure if that is what make SSR stop working. I change the code manually to start as TRUE, and the web optimizations started working again.

@cleberj
Copy link

cleberj commented May 9, 2022

@shuding Do you know if this has sth to do with your refactoring? Can you help us, please ?

@kodiakhq kodiakhq bot closed this as completed in #36837 May 12, 2022
kodiakhq bot pushed a commit that referenced this issue May 12, 2022
Follow up for #35888 to re-enable more test, and re-enable post processors after #36792 has better support for document.gIP with react 18. Apply post-pocessing when the the shell chunk is fully buffered.

re-enabled integration tests for react 18:
- amphtml
- amphtml-custom-optimizer
- app-document
- font-optimization

Fixes #35835


## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
@huozhi
Copy link
Member

huozhi commented May 13, 2022

Hi, the fix is landed in next@12.1.7-canary.5, could you try it to see if the issue is reolsved for you?

@okisdev
Copy link
Author

okisdev commented May 13, 2022

Hi @huozhi

I can confirm that this issue has been resolved in next@12.1.7-canary.5.

Thanks

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. Font (next/font) Related to Next.js Font Optimization.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants