From 92de0a64e7e746834dc855c93b9a146f0e55db00 Mon Sep 17 00:00:00 2001 From: Bryan Valverde U Date: Wed, 4 Sep 2024 12:42:58 -0600 Subject: [PATCH] Resolve null sheet in convertInlineCss (#2784) * init * update --- .../createModelFromHtml/convertInlineCss.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts b/packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts index 2e70912a611..e26cae1c002 100644 --- a/packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts +++ b/packages/roosterjs-content-model-core/lib/command/createModelFromHtml/convertInlineCss.ts @@ -28,16 +28,18 @@ export function retrieveCssRules(doc: Document): CssRule[] { const result: CssRule[] = []; styles.forEach(styleNode => { - const sheet = styleNode.sheet as CSSStyleSheet; + const sheet = styleNode.sheet; - for (let ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) { - const rule = sheet.cssRules[ruleIndex] as CSSStyleRule; + if (sheet) { + for (let ruleIndex = 0; ruleIndex < sheet.cssRules.length; ruleIndex++) { + const rule = sheet.cssRules[ruleIndex] as CSSStyleRule; - if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) { - result.push({ - selectors: splitSelectors(rule.selectorText), - text: rule.style.cssText, - }); + if (rule.type == CSSRule.STYLE_RULE && rule.selectorText) { + result.push({ + selectors: splitSelectors(rule.selectorText), + text: rule.style.cssText, + }); + } } }