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

高德地图在子应用中轨迹回放时报removeChild异常 #524

Open
FBin001 opened this issue Apr 23, 2023 · 6 comments
Open

高德地图在子应用中轨迹回放时报removeChild异常 #524

FBin001 opened this issue Apr 23, 2023 · 6 comments

Comments

@FBin001
Copy link

FBin001 commented Apr 23, 2023

高德地图在子应用中轨迹回放时卡顿明显,无动画效果;在主应用中正常;

@FBin001 FBin001 changed the title 高德地图在子应用中轨迹回放时卡顿明显,无动画效果 高德地图在子应用中轨迹回放时报removeChild异常 Apr 24, 2023
@tianfeng98
Copy link

我也遇到了同样的问题,拉源代码调试依然没解决。目前对于轨迹回放的部分只能先用iframe降级处理了。

@yiludege
Copy link
Collaborator

yiludege commented May 21, 2023

断点调试一下到底是什么原因,可以借鉴以下思路
#442 (comment)

@tianfeng98
Copy link

tianfeng98 commented Jun 9, 2023

@yiludege 我找到了原因,但无法解决。
异常内容:
VM842:7 Uncaught DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.

因为加载高德地图插件时有这样一个函数执行:

function F(t, i) {
  var n = document.createElement("script");
  (n.type = "text/javascript"),
    (document.body
      ? ((n.onload = function () {
          document.body.removeChild(n), i();
        }),
        (n.src = t),
        document.body)
      : ((n.onload = function () {
          document.head.removeChild(n), i();
        }),
        (n.src = t),
        document.head)
    ).appendChild(n);
}

对一个新的script标签做了增删操作。

我用两个js文件(a.jsb.js)复现了:

// a.js
const script = document.createElement("script");
script.type = "text/javascript";
script.src = "/b.js";

script.onload = function () {
  document.body.removeChild(script);
};

document.body.appendChild(script);

a.js中加载b.js,完成后调用removeChild移除script标签。

在子应用中加载a.js

const script = document.createElement("script");
script.type = "text/javascript";
script.src = "/a.js";
document.body.appendChild(script);

通过上述步骤就可以复现问题。

我调试无界源码时,发现b.jsscript加载会被移至iframe中加载,是否因为这个原因导致removeChild异常?

@tianfeng98
Copy link

codesandbox 复现示例

我用无界官网的 React17 子应用复现了这个问题,codesandbox沙箱内子应用加载失败,在浏览器中打开正常。
按照我上面的描述,增加a.jsb.js
image

我在wujie-core/src/effect.ts文件中加了一行console,以便定位问题。
image

问题截图:
image

@zouyujie
Copy link

zouyujie commented Jun 14, 2023

这个问题我遇到并解决了,子应用用到高德地图的界面,捕获这个异常,然后重新实例化地图对象就可以解决这个问题

onMounted(() => {
  //界面页面第一次加载,地图白屏的问题
  window.onerror = function (message) {
    if (message.toString().includes("Failed to execute 'removeChild'")) {
      initAmap();
    }
  }
})
onUnmounted(() => {
  window.onerror = null;
})

@wentt
Copy link

wentt commented Jun 5, 2024

jsLoader: (code: string) => {
      code = code.replace(
        /document.body.removeChild\((.+?)\)/g,
        '(document.head.contains($1) && document.head.removeChild($1))'
      )
      return code
    }

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

5 participants