From 6440622e93dd1d637bebf9c51e73d598bb49790d Mon Sep 17 00:00:00 2001 From: MV88 Date: Wed, 29 Nov 2023 12:58:55 +0100 Subject: [PATCH] Fix #9653 force load of font when fontAwesome css is loaded --- .../utils/styleparser/StyleParserUtils.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/web/client/utils/styleparser/StyleParserUtils.js b/web/client/utils/styleparser/StyleParserUtils.js index b77a911df6..404f214a13 100644 --- a/web/client/utils/styleparser/StyleParserUtils.js +++ b/web/client/utils/styleparser/StyleParserUtils.js @@ -853,6 +853,7 @@ export const parseSymbolizerExpressions = (symbolizer, feature) => { }; +let loaded = false; const loadFontAwesome = () => { return new Promise((resolve) => { const fontAwesomeHref = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css'; @@ -862,13 +863,25 @@ const loadFontAwesome = () => { fontAwesome.setAttribute('href', fontAwesomeHref); document.head.appendChild(fontAwesome); fontAwesome.onload = () => { - resolve(); + const font = document.createElement('link'); + font.setAttribute('rel', 'preload'); + font.setAttribute('as', 'font'); + font.setAttribute('crossorigin', true); + font.setAttribute('href', "https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff?v=4.7.0"); + document.head.appendChild(font); + font.onload = () => { + loaded = true; + resolve(); + }; }; fontAwesome.onerror = () => { resolve(); }; } else { - resolve(); + if (loaded) { + // delaying the resolve to make sure the fontAwesome.onload is triggered before + resolve(); + } } }); };