-
-
Notifications
You must be signed in to change notification settings - Fork 27k
Custom font produce dragging behavior (FOUT, FOIT) #2987
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
Comments
Well this is less than optimal! We'd like this to not happen, I recall we had an issue open about it once before but I cannot recall the terms to search for it. I'd be happy to take a PR to fix this, we can discuss the implications of such a change then. Thanks! |
Sure. I've just wanted to verify before PR. I will try to dive deeper and let you know.
|
So, I've investigated that issue. The reason we get FOIT is that browser loads fonts asyncronusly. User see the page first, browser loads font and then renders the page again. The most reasonable solution is to use fontfaceobserver and defer rendering before fonts are loaded: @font-face {
font-family: 'Myfont';
font-style: normal;
font-weight: 400;
src: url('./Myfont.ttf');
} import './index.css';
import FontFaceObserver from 'fontfaceobserver';
new FontFaceObserver('Myfont').load().then(() => {
ReactDOM.render(<App />, document.getElementById('root'));
}); I don't think we can fix that inside react-scripts. I think, we should just add this recommendation to documentation on how to use custom fonts. Should I make a PR for README.md? |
Closing as stale. |
I'm experiencing FOUT with:
in Is there any solution to this other than It would be great for this to be documented in any case. Even if the font is subsequently cached, FOUT on the first load doesn't give a good first impression to users. |
Is this question related to CRA or browsers in general? I’m struggling to understand how this is different from what would happen if you just wrote HTML and CSS by hand. If it’s a generic HTML/CSS issue I don’t think it belongs in our docs. |
You're right, I had assumed naively that having imported fonts from the typefaces NPM packages had made a difference, it happens regardless so not a CRA issue. Apologies for the confusion, and thanks for your time. |
No worries! |
Is this a bug report?
Yes
Environment
node -v
: v6.10.3npm -v
: 3.10.10yarn --version
(if you use Yarn): 0.27.5npm ls react-scripts
(if you haven’t ejected): 1.0.11Then, specify:
Steps to Reproduce
Try to update page several times. You will see FOUT.
Expected Behavior
I expect page load without dragging (FOUT, FOIT)
Actual Behavior
First page load behave like this:

Reproducible Demo
https://github.com/tsmirnov/create-react-app-fout-example
I added custom font like @gaearon proposed on stackoverflow. However, I get FOUT.
This is happening, because fonts are loaded asyncronusly. Synchronous font loading must solve the problem. I couldn't find anywhere how to do it properly without eject. I can work on PR, to solve that issue. What do you think?
The text was updated successfully, but these errors were encountered: