diff --git a/src/helpers/dom/loadFonts.ts b/src/helpers/dom/loadFonts.ts index 8e88894f..2d00a3f9 100644 --- a/src/helpers/dom/loadFonts.ts +++ b/src/helpers/dom/loadFonts.ts @@ -5,8 +5,13 @@ */ let promise: Promise; -export default function loadFonts(): Promise { +export default function loadFonts(): Promise { if(promise) return promise; - // @ts-ignore - return promise = 'fonts' in document ? Promise.all(['400 1rem Roboto', '500 1rem Roboto', '500 1rem tgico'].map(font => document.fonts.load(font))) : Promise.resolve(); + return promise = 'fonts' in document ? + Promise.race([ + // @ts-ignore + Promise.all(['400 1rem Roboto', '500 1rem Roboto', '500 1rem tgico'].map(font => document.fonts.load(font))), + new Promise((resolve) => setTimeout(resolve, 1e3)) + ]) : + Promise.resolve(); } diff --git a/src/index.ts b/src/index.ts index b5ef9c91..eaad18cf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -279,7 +279,7 @@ console.timeEnd('get storage1'); */ /** * won't fire if font is loaded too fast */ - function fadeInWhenFontsReady(elem: HTMLElement, promise: Promise) { + function fadeInWhenFontsReady(elem: HTMLElement, promise: Promise) { elem.style.opacity = '0'; promise.then(() => { @@ -346,8 +346,13 @@ console.timeEnd('get storage1'); */ await pagePromise; } - // @ts-ignore - const promise = 'fonts' in document ? document.fonts.ready : Promise.resolve(); + const promise = 'fonts' in document ? + Promise.race([ + new Promise((resolve) => setTimeout(resolve, 1e3)), + // @ts-ignore + document.fonts.ready + ]) : + Promise.resolve(); fadeInWhenFontsReady(scrollable, promise); }