-
Notifications
You must be signed in to change notification settings - Fork 666
Open
Description
描述bug
当子应用使用vite时,第二个css文件以后的font-face无效
如何复现
1、使用vite开发子应用
2、 当font-face的设置不在第一个css或者第二个css的时候,font-face无法按照文档描述,放到shadow-root在主应用加载
问题分析
1 vite加载css资源时,使用updateStyle
第一个css使用appendChild
后面加载的css使用insertAdjacentElement,确保加载顺序
function updateStyle(id, content) {
let style = sheetsMap.get(id);
if (!style) {
style = document.createElement("style");
style.setAttribute("type", "text/css");
style.setAttribute("data-vite-dev-id", id);
style.textContent = content;
if (cspNonce) {
style.setAttribute("nonce", cspNonce);
}
if (!lastInsertedStyle) {
document.head.appendChild(style);
setTimeout(() => {
lastInsertedStyle = void 0;
}, 0);
} else {
lastInsertedStyle.insertAdjacentElement("afterend", style);
}
lastInsertedStyle = style;
} else {
style.textContent = content;
}
sheetsMap.set(id, style);
}第一个css,使用appendChild加载的css可以正常被patch,从而正确提取font-face,如文档所述
第二个css也可以正常被patch
但是以后的css,由于style节点不是被appendChild加载的,导致没有被wujie正确patch。其中的资源路径没有被cssLoader处理,font-face也没有被提取
Metadata
Metadata
Assignees
Labels
No labels