Skip to content
Snippets Groups Projects
Commit 97b9f5cf authored by picklesrus's avatar picklesrus
Browse files

Stop waiting for non scratch fonts to load.

parent 95381f25
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,17 @@ import omit from 'lodash.omit'; ...@@ -4,6 +4,17 @@ import omit from 'lodash.omit';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import {setFontsLoaded} from '../reducers/fonts-loaded'; 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. /* Higher Order Component to provide behavior for loading fonts.
* @param {React.Component} WrappedComponent component to receive fontsLoaded prop * @param {React.Component} WrappedComponent component to receive fontsLoaded prop
* @returns {React.Component} component with font loading behavior * @returns {React.Component} component with font loading behavior
...@@ -22,8 +33,12 @@ const FontLoaderHOC = function (WrappedComponent) { ...@@ -22,8 +33,12 @@ const FontLoaderHOC = function (WrappedComponent) {
typeof document.fonts.values === 'function' && typeof document.fonts.values === 'function' &&
typeof document.fonts.values()[Symbol.iterator] === 'function') { typeof document.fonts.values()[Symbol.iterator] === 'function') {
for (const fontFace of document.fonts.values()) { for (const fontFace of document.fonts.values()) {
fontPromises.push(fontFace.loaded); // Only load fonts from this list. If we load all fonts on the document, we may block on
fontFace.load(); // loading fonts from things like chrome extensions.
if (FONTS.indexOf(fontFace.family) !== -1) {
fontPromises.push(fontFace.loaded);
fontFace.load();
}
} }
} }
return fontPromises; return fontPromises;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment