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

偶现情况: hookElement 出来的不是 Node,导致 appendChild 的时候出错。 #91

Closed
moecasts opened this issue Jun 29, 2022 · 12 comments · May be fixed by #103
Closed

偶现情况: hookElement 出来的不是 Node,导致 appendChild 的时候出错。 #91

moecasts opened this issue Jun 29, 2022 · 12 comments · May be fixed by #103

Comments

@moecasts
Copy link

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request

Current behavior

hookElement 出来的不是 Node,导致 appendChild 的时候出错。

{
  "message":"Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.",
  "name":"TypeError",
  "stack":"TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.\n"
}

Expected behavior

能确保 hookElement 出来的一定是 Node.

Minimal reproduction of the problem with instructions

偶现情况,暂未找到原因

What is the motivation / use case for changing the behavior?

不会阻塞其他脚本的加载

Environment


Assets-retry version: 0.3.3

 
For Tooling issues:
- Browser version: Edge(103.0)
- Platform:  Windows

Others:
- userAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Safari/537.36 Edg/103.0.1264.37

@Nikaple
Copy link
Owner

Nikaple commented Jun 29, 2022

请提供一个最小复现示例来帮助复现并定位问题

(可以在报错前断点看看,有可能是你传递给appendChild的参数真的不是Node类型)

@moecasts
Copy link
Author

@Nikaple 目前无法复现,所以想来这里问一下,出错的 appendChildwebpack 里的那个动态加载的 createElement('script')。经过 hookElement 之后这个元素的返回值是 hookedElement

@Nikaple
Copy link
Owner

Nikaple commented Jun 29, 2022

出错的 appendChildwebpack 里的那个动态加载的 createElement('script')。经过 hookElement 之后这个元素的返回值是 hookedElement

这是为了重试动态加载 JS 而执行的正常逻辑。

@moecasts
Copy link
Author

这是为了重试动态加载 JS 而执行的正常逻辑。

嗯嗯,我理解,不过根据报错,像是有某种情况 hook 失败了,导致的 Failed to execute 'appendChild' on 'Node'

@Nikaple
Copy link
Owner

Nikaple commented Jun 30, 2022

所以需要你提供复现链接,或者定位到问题的原因,只提一个issue并不能解决问题

@moecasts
Copy link
Author

目前就是无法稳定复现,所以来这里提 issue 看看有没有啥头绪的,等找到稳定复现的情况再继续这个 issue 吧。

@Nikaple Nikaple closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2022
@DillionZ
Copy link

目前就是无法稳定复现,所以来这里提 issue 看看有没有啥头绪的,等找到稳定复现的情况再继续这个 issue 吧。

老哥,你解决了吗?我也遇到了这个问题。

@moecasts
Copy link
Author

老哥,你解决了吗?我也遇到了这个问题。

还没解决。

@WinneyFeng
Copy link

WinneyFeng commented Oct 18, 2023

hi @Nikaple 我们找到了百分百复现的步骤,你这边最近会修复吗?
复现代码:
<script> var iframe = document.createElement('iframe'); iframe.src = 'about:blank'; document.body.appendChild(iframe); iframe.addEventListener('load', function() { // !!! NOTE: 这一行如果改成 var script = iframe.contentDocument.createElement('script'); 就不会有问题 var script = document.createElement('script'); script.src = 'https://example.com/your-script.js'; iframe.contentDocument.head.appendChild(script); }); </script>

@Nikaple
Copy link
Owner

Nikaple commented Oct 21, 2023

@DillionZ @moecasts @WinneyFeng 有空可以尝试下 #103 是否解决问题:https://github.com/Nikaple/assets-retry/tree/fix/iframe/dist

@WinneyFeng
Copy link

@DillionZ @moecasts @WinneyFeng 有空可以尝试下 #103 是否解决问题:https://github.com/Nikaple/assets-retry/tree/fix/iframe/dist

hi @Nikaple 上一次提供的最小复现代码是fixed了,但是我这边的页面代码还是可以百分百复现,于是再给你提供一个最小复现代码:
<script> var iframe = document.createElement('iframe'); iframe.src = 'about:blank'; document.body.appendChild(iframe); var script = document.createElement('script'); script.src = '/assets/plugins/storehub-frontend-utils/frontend-utils.2.0.4.umd.production.min.js'; iframe.contentDocument.head.appendChild(script); </script>

@Nikaple
Copy link
Owner

Nikaple commented Sep 26, 2024

在iframe中append父页面document创建的HTML标签这种场景过于小众,且修复成本很高,暂不考虑支持了

@Nikaple Nikaple closed this as not planned Won't fix, can't repro, duplicate, stale Sep 26, 2024
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 a pull request may close this issue.

4 participants