From 16a62310e3e0e2a79c5392cec0e7658b97d0ee21 Mon Sep 17 00:00:00 2001 From: Innei Date: Fri, 20 Sep 2024 23:13:11 +0800 Subject: [PATCH] fix: catch access stylesheet error Signed-off-by: Innei --- .../src/components/common/ShadowDOM.tsx | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/apps/renderer/src/components/common/ShadowDOM.tsx b/apps/renderer/src/components/common/ShadowDOM.tsx index 96b3ede6af..80135fd9ef 100644 --- a/apps/renderer/src/components/common/ShadowDOM.tsx +++ b/apps/renderer/src/components/common/ShadowDOM.tsx @@ -151,21 +151,25 @@ function getLinkedStaticStyleSheets() { if (!sheet) continue if (!sheet.href) continue const hasCache = cacheCssTextMap[sheet.href] - if (!hasCache) { - if (!sheet.href) continue - const rules = sheet.cssRules || sheet.rules - let cssText = "" - for (const rule of rules) { - cssText += rule.cssText + try { + if (!hasCache) { + if (!sheet.href) continue + const rules = sheet.cssRules || sheet.rules + let cssText = "" + for (const rule of rules) { + cssText += rule.cssText + } + + cacheCssTextMap[sheet.href] = cssText + cssArray.push({ + cssText: cacheCssTextMap[sheet.href], + ref: $link, + }) } - - cacheCssTextMap[sheet.href] = cssText + } catch (e) { + console.info("Parse css error", sheet.href) + console.error(e) } - - cssArray.push({ - cssText: cacheCssTextMap[sheet.href], - ref: $link, - }) } return cssArray