diff --git a/packages/wujie-core/src/effect.ts b/packages/wujie-core/src/effect.ts index e559e3c72..c969af804 100644 --- a/packages/wujie-core/src/effect.ts +++ b/packages/wujie-core/src/effect.ts @@ -163,7 +163,10 @@ function rewriteAppendOrInsertChild(opts: { if (element.tagName) { switch (element.tagName?.toUpperCase()) { case "LINK": { - const { href } = element as HTMLLinkElement; + const { href, rel, type } = element as HTMLLinkElement; + const styleFlag = rel === "stylesheet" || type === "text/css" || href.endsWith(".css"); + // 非 stylesheet 不做处理 + if (!styleFlag) return rawDOMAppendOrInsertBefore.call(this, element, refChild); // 排除css if (href && !isMatchUrl(href, getEffectLoaders("cssExcludes", plugins))) { getExternalStyleSheets( diff --git a/packages/wujie-core/src/shadow.ts b/packages/wujie-core/src/shadow.ts index 2c599d1b1..74c9b372f 100644 --- a/packages/wujie-core/src/shadow.ts +++ b/packages/wujie-core/src/shadow.ts @@ -103,7 +103,8 @@ async function processCssLoaderForTemplate(sandbox: Wujie, html: HTMLHtmlElement styleElement.setAttribute("type", "text/css"); styleElement.appendChild(document.createTextNode(content ? cssLoader(content, src, curUrl) : content)); const head = html.querySelector("head"); - head?.insertBefore(styleElement, html.querySelector("head")?.firstChild); + const body = html.querySelector("body"); + html.insertBefore(styleElement, head || body || html.firstChild); }); }), Promise.all(