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

fix: 适配子应用处理script标签 #453

Merged
merged 1 commit into from
Mar 23, 2023

Conversation

Xusenbiao
Copy link
Contributor

  • 提交符合commit规范
  • 测试用例添加
  • npm run test通过
详细描述

wujie重写了子应用ShadowRoothead.appendChild方法,将子应用插入的script转移到了同域Iframe内的head。然而containsremoveChild方法依然指向的是ShadowRoot,这导致子应用在插入script后无法通过contains判断该script的存在,也无法通过document.head.removeChild将其移除。

此PR调整了ShadowRoothead.containscontainshead.removeChild这三个方法,尝试适配子应用对script的处理。适配后效果如下:

  const script = document.createElement('script')
  script.type = 'text/javascript'
  script.async = true
  script.src = 'test.js'
  document.head.appendChild(script)

  console.log(document.contains(script)) // false, [wujie warn]: 目标Script尚未准备好或已经被移除 <script wujie='1679239314179'/>
  console.log(document.head.contains(script)) // false, [wujie warn]: 目标Script尚未准备好或已经被移除 <script wujie='1679239314179'/>

  // 等待wujie的script加载完成
  setTimeout(() => {
    console.log(document.contains(script)) // true
    console.log(document.head.contains(script)) // true
    document.head.removeChild(script) // succeed
  }, 2000)

@yiludege yiludege merged commit f7e83b8 into Tencent:master Mar 23, 2023
@yiludege
Copy link
Collaborator

感谢添砖加瓦

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

Successfully merging this pull request may close these issues.

2 participants