fix: emoji icons on iphone and plugins with frontend_js

Massimo Melina committed Jun 3, 2024 at 11:02 UTC c811c0ad1ff2c1e5e1da728fe5a387699946e9d6
1 file changed +5 -2
frontend/src/icons.ts
+5 -2
@@ -47,10 +47,13 @@ const SYS_ICONS: Record<string, [string] | [string, string | false]> = { // fals
47 warning: ['⚠️', false],
48 }
49
50 -document.fonts.ready.then(async ()=> {
50 +const documentComplete = document.readyState === 'complete' ? Promise.resolve()
51 + : new Promise(res => document.addEventListener('readystatechange', res))
52 +// fonts.ready seems to be unreliable with iphone + additional <script> in custom-html + plugins using frontend_js, but still can be interesting if it resolves faster the document.complete, as we specifically interested in the fonts
53 +Promise.race([documentComplete, document.fonts?.ready]).then(async () => {
54 const fontTester = '9px fontello'
55 await document.fonts.load(fontTester) // force font to be loaded even if we didn't display anything with it yet
53 - state.iconsReady = document.fonts.check(fontTester)
56 + state.iconsReady = document.fonts.check(fontTester)//Boolean(Array.from(document.fonts.values()).find(x => x.family === 'fontello'))
57 })
58
59 interface IconProps { name:string, className?:string, alt?:string, [rest:string]: any }