Skip to content

Commit

Permalink
fix: 修复子应用切换插件样式重复问题 (#163)
Browse files Browse the repository at this point in the history
close #161
  • Loading branch information
yiludege committed Sep 22, 2022
1 parent 49f95e6 commit bf0fb18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/wujie-core/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion packages/wujie-core/src/shadow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit bf0fb18

Please sign in to comment.