From 310da17e4c814cd28b43155f48bb06a76426e7b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9C=A8de?= <1762982273@qq.com> Date: Sat, 28 Aug 2021 23:57:57 +0800 Subject: [PATCH 1/3] fix(font): ios13+ font loading errror In ios 13+, documents fonts loaded,but documents,fonts.ready not resolve but in pending,so that whole process is pending. --- src/dom/document-cloner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index 796e5579f..5d1b6cb9b 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -109,7 +109,7 @@ export class DocumentCloner { return Promise.reject(`Error finding the ${this.referenceElement.nodeName} in the cloned document`); } - if (documentClone.fonts && documentClone.fonts.ready) { + if (documentClone.fonts && documentClone.fonts.status === "loading" && documentClone.fonts.ready) { await documentClone.fonts.ready; } From d3553667240da748aa426ba1d23f309106b66751 Mon Sep 17 00:00:00 2001 From: jacket <1762982273@qq.com> Date: Sat, 11 Sep 2021 14:56:42 +0800 Subject: [PATCH 2/3] fix: code prettier --- src/dom/document-cloner.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index 5d1b6cb9b..b04ea8dc2 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -109,7 +109,7 @@ export class DocumentCloner { return Promise.reject(`Error finding the ${this.referenceElement.nodeName} in the cloned document`); } - if (documentClone.fonts && documentClone.fonts.status === "loading" && documentClone.fonts.ready) { + if (documentClone.fonts && documentClone.fonts.status === 'loading' && documentClone.fonts.ready) { await documentClone.fonts.ready; } From 24688ac608679a76c2ccbb6448101198206ec942 Mon Sep 17 00:00:00 2001 From: kete Date: Tue, 18 Jan 2022 15:43:08 +0800 Subject: [PATCH 3/3] fix(font load): fix when font load timeout --- src/dom/document-cloner.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/dom/document-cloner.ts b/src/dom/document-cloner.ts index b04ea8dc2..859e1dbaf 100644 --- a/src/dom/document-cloner.ts +++ b/src/dom/document-cloner.ts @@ -109,8 +109,18 @@ export class DocumentCloner { return Promise.reject(`Error finding the ${this.referenceElement.nodeName} in the cloned document`); } - if (documentClone.fonts && documentClone.fonts.status === 'loading' && documentClone.fonts.ready) { - await documentClone.fonts.ready; + if (documentClone.fonts && documentClone.fonts.status === 'loading') { + return Promise.race([ + documentClone.fonts.ready, + new Promise((resolve) => { + const fontLoadTimer = setInterval(() => { + if (documentClone.fonts.status === 'loaded') { + clearInterval(fontLoadTimer); + resolve(); + } + }, 1000); + }) + ]); } if (/(AppleWebKit)/g.test(navigator.userAgent)) {