nuxt / fonts

Plug-and-play web font optimization and configuration for Nuxt apps.
https://fonts.nuxt.com
MIT License
424 stars 7 forks source link

Loading fonts causes flickering in dev mode #181

Open lostful opened 3 months ago

lostful commented 3 months ago

Whenever I reload my page the font flickers

dosubot[bot] commented 3 months ago

Hey @lostful! I'm here to help you with any bugs, questions, or contributions you have in mind. Let's tackle this flickering font issue together!

To fix the issue of font flickering whenever you reload your page, you can use the nuxt-fonts module to optimize and configure web fonts in your Nuxt app. Here is how you can set it up in your .nuxtrc file:

typescript.tsConfig.compilerOptions.noUncheckedIndexedAccess=true
modules[]=nuxt-fonts-devtools

This configuration will help in optimizing the fonts and reducing the flickering issue [1].

To continue talking to Dosu, mention @dosu.

danielroe commented 3 months ago

Is this only in development?

github-actions[bot] commented 3 months ago

Would you be able to provide a reproduction? πŸ™

More info ### Why do I need to provide a reproduction? Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making. ### What will happen? If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect. If `needs reproduction` labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it. ### How can I create a reproduction? We have a template for starting with a minimal reproduction: πŸ‘‰ https://stackblitz.com/github/nuxt/fonts/tree/main/example A public GitHub repository is also perfect. πŸ‘Œ Please ensure that the reproduction is as **minimal** as possible. See more details [in our guide](https://nuxt.com/docs/community/reporting-bugs/#create-a-minimal-reproduction). You might also find these other articles interesting and/or helpful: - [The Importance of Reproductions](https://antfu.me/posts/why-reproductions-are-required) - [How to Generate a Minimal, Complete, and Verifiable Example](https://stackoverflow.com/help/mcve)
lostful commented 3 months ago

Is this only in development?

Ah yes, this is only in development. Is that intended?

danielroe commented 3 months ago

Not intended, but I did observe it previously. Need to investigate, so let’s leave it open.

kickthemooon commented 1 month ago

same here i have the font in my css like this

@font-face {
  font-family: 'Quicksand';
  src: url('/fonts/quicksand/Quicksand-VariableFont_wght.ttf') format('TrueType');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

and the actual file is in the public directory public/fonts

maybe I should do it differently?

danielroe commented 1 week ago

This looks like an upstream vite bug to me - likely caused by the fact that:

<link rel="stylesheet" href="/_nuxt/__uno.css">

returns a JS module and not CSS.