Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] 添加对Element.insertAdjacentElement()方法的劫持 #3018

Open
missmess opened this issue Oct 28, 2024 · 0 comments
Open

Comments

@missmess
Copy link

背景

qiankun目前支持微应用使用appendChildinsertBefore动态添加样式表和脚本元素。并劫持了这两个方法。但是对于insertAdjacentElement方法没有劫持。

而Vite下处理import "xxxx.css"的时候,它最终会使用insertAdjacentElement方法添加动态样式表。

let lastInsertedStyle;
function updateStyle(id, content) {
  let style = sheetsMap.get(id);
  if (!style) {
    //...
    if (!lastInsertedStyle) {
      document.head.appendChild(style);
      //...
    } else {
      lastInsertedStyle.insertAdjacentElement("afterend", style);
    }
    lastInsertedStyle = style;
  }

这就导致了vite应用里的样式,在应用卸载后再次加载时,无法被rebuild()

建议

patchHTMLDynamicAppendPrototypeFunctions方法里,添加** HTMLHeadElement.prototype.insertAdjacentElement劫持的相关代码,和appendChild**其实是一样的。

辛苦各位开发大姥!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant