question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom font produce dragging behavior (FOUT, FOIT)

See original GitHub issue

Is this a bug report?

Yes

Environment

  1. node -v: v6.10.3
  2. npm -v: 3.10.10
  3. yarn --version (if you use Yarn): 0.27.5
  4. npm ls react-scripts (if you haven’t ejected): 1.0.11

Then, specify:

  1. Operating system: OSX 10.12.6
  2. Browser and version:
  • Chrome Version 60.0.3112.101
  • Safari Version 10.1.2

Steps to Reproduce

git clone git@github.com:tsmirnov/create-react-app-fout-example.git
yarn start

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: fout

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?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
tsmirnovcommented, Aug 29, 2017

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?

0reactions
gaearoncommented, Jan 10, 2018

No worries!

Read more comments on GitHub >

github_iconTop Results From Across the Web

FOUT, FOIT, FOFT - CSS-Tricks
When using a custom font via @font-face, browsers used to display a ... This makes the behavior like FOUT – speeding up readable...
Read more >
Font loading strategies: FOIT and FOUT
FOIT and FOUT are font loading strategies used by browsers to load custom fonts. FOIT shows an invisible text while FOUT uses a...
Read more >
Controlling Font Performance with font-display
If the font face is not yet loaded when this period starts, it's marked as a failed load, causing normal font fallback.
Read more >
FOIT vs FOUT: a comparison on web font loading - Rock Content
In this content, we will deal with the FOIT vs. FOUT comparison, addressing each of their details and the impact on custom font...
Read more >
Scaling Fonts Automatically | Apple Developer Documentation
If you use a custom font in your app and want to let the user control the text size, you must create a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found