umijs / qiankun

📦 🚀 Blazing fast, simple and complete solution for micro frontends.
https://qiankun.umijs.org
MIT License
15.74k stars 2.01k forks source link

子应用中往父容器 `head` 节点动态 `appendChild` 新节点时,新节点挂载在子应用 #2511

Closed xinyu-shopastro closed 1 year ago

xinyu-shopastro commented 1 year ago

What happens?

子应用中往父容器 head 节点动态 appendChild 新节点时,新节点实际挂载在子应用里面

How To Reproduce

Steps to reproduce the behavior: 1. 2.

  const head = document.querySelector('head');
  const linkTag = document.createElement('link');
  linkTag.setAttribute('rel', 'shortcut icon');
  linkTag.setAttribute('type', 'image/svg');
  linkTag.setAttribute('id', 'new-favicon');
  linkTag.setAttribute('href', iconUrl);
  head.appendChild(linkTag);

Expected behavior 1. 2. 子应用中往父容器 head 节点 appendChild 新节点时,新节点应该添加到父级 head

Context

求告知这种需求应该怎么实现

xinyu-shopastro commented 1 year ago

2502

kuitos commented 1 year ago

子应用要操作主应用的 dom 就属于沙箱逃逸了,这个不符合预期。 如果一定要这么做只能把沙箱关了。