w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.44k stars 656 forks source link

[css-fonts] Flash of disappearing text after inserting @font-face rules #5455

Open xiaochengh opened 4 years ago

xiaochengh commented 4 years ago

Reposted from crbug.com/770003

Browsers (tested with Chrome, Firefox and Safari) currently make text that has already been displayed invisible when a stylesheet loads that provides a font for that text.

Simple example. Try http://output.jsbin.com/qonelib/quiet with cache disabled and network throttling to see the effect.

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">

    <title>Flash on disappearing text</title>
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <style>
      body {
        font-family: "IM Fell DW Pica", serif;
        padding: 3rem;
        line-height: 1.3rem;
      }
    </style>
  </head>
  <body>
    <h1>Some text</h1>
  </body>
  <script>
    var url = 'https://fonts.googleapis.com/css?family=IM+Fell+DW+Pica&x='+Math.random();
    var l = document.createElement('link');
    l.rel = 'stylesheet';
    l.href = url;

    setTimeout(function() {
      document.head.appendChild(l);
    }, 2000)
  </script>
</html>

Should browsers make text invisible that has previously been painted as visible?

tabatkins commented 4 years ago

No, I don't think they should; if we've gotten to the point of painting, damage has already been done, and we shouldn't hide text afterward. I guess we might need to put an escape hatch into the font-display values that hide text to account for this.