From 97b9f5cf30b90f26dd6e90da80053c7f75b2b1e6 Mon Sep 17 00:00:00 2001 From: picklesrus <picklesrus@users.noreply.github.com> Date: Thu, 3 Jan 2019 15:14:41 -0500 Subject: [PATCH] Stop waiting for non scratch fonts to load. --- src/lib/font-loader-hoc.jsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/font-loader-hoc.jsx b/src/lib/font-loader-hoc.jsx index ea05143b9..9e98cf127 100644 --- a/src/lib/font-loader-hoc.jsx +++ b/src/lib/font-loader-hoc.jsx @@ -4,6 +4,17 @@ import omit from 'lodash.omit'; import {connect} from 'react-redux'; import {setFontsLoaded} from '../reducers/fonts-loaded'; +// This list is from scratch-render-fonts: +// https://github.com/LLK/scratch-render-fonts/blob/master/src/index.js#L4 +const FONTS = [ + 'Sans Serif', + 'Serif', + 'Handwriting', + 'Marker', + 'Curly', + 'Pixel', + 'Scratch' +]; /* Higher Order Component to provide behavior for loading fonts. * @param {React.Component} WrappedComponent component to receive fontsLoaded prop * @returns {React.Component} component with font loading behavior @@ -22,8 +33,12 @@ const FontLoaderHOC = function (WrappedComponent) { typeof document.fonts.values === 'function' && typeof document.fonts.values()[Symbol.iterator] === 'function') { for (const fontFace of document.fonts.values()) { - fontPromises.push(fontFace.loaded); - fontFace.load(); + // Only load fonts from this list. If we load all fonts on the document, we may block on + // loading fonts from things like chrome extensions. + if (FONTS.indexOf(fontFace.family) !== -1) { + fontPromises.push(fontFace.loaded); + fontFace.load(); + } } } return fontPromises; -- GitLab