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

升级到rc20版本后,子应用间切换,document.body获取不到导致ui库antdesign报错 #1519

Open
baichengda opened this issue Feb 7, 2025 · 5 comments
Assignees
Labels
bug Something isn't working Working on it Working on this issue

Comments

@baichengda
Copy link

问题描述

问题的具体描述
1、升级到rc20版本后,vite-vue3子应用中使用ui库antdesign中的notification组件,切换报错Cannot read properties of undefined (reading 'appendChild'),报错原因是因为切换页面时document.body为null导致。
2、应用中其他插件涉及到document.body,都会出现因获取不到导致报错的问题,比如vite-plugin-svg-icons

复现步骤

  1. 导航child-vue3 、child-vite来回切换就会出现报错,单独刷新页面正常运行

上传截图

请上传代码截图、控制台、终端等截图以帮助我们了解您的问题。

Image

Image

Image

复现仓库

请提供一个精简的代码仓库,然后上传到自己的 github,以帮助我们复现您的问题。
https://github.com/baichengda/demo

环境信息

  • micro-app版本:rc20
  • 主应用前端框架&版本:Vue@3.x
  • 子应用前端框架&版本:Vue@3.x
  • 构建工具&版本:"vite": "^4.5.5"
@iGarym
Copy link

iGarym commented Feb 8, 2025

Setting getContainer can solve this problem, but an error will occur when the component is destroyed. Because the Transition component depends on document.

notification.config({
  getContainer: () => window.__MICRO_APP_ENVIRONMENT__ ? window.rawDocument.body : document.body,
})

@maoxian-1
Copy link

同样的问题,如果需要每个子应用都修改window.rawDocument那太麻烦了

@icemirror
Copy link

同样的问题,在最新的rc20版本,子应用是vite构建工具,在主应用和子应用间来回切换会导致子应用UI库有关document的报错,多测试几次页面就会崩溃。 @timhub66

@timhub66 timhub66 self-assigned this Feb 13, 2025
@timhub66 timhub66 added the bug Something isn't working label Feb 13, 2025
@timhub66
Copy link
Collaborator

用vite 的同学,先把版本锁死在1.0.0-rc.19;这个问题,下个版本修复

@timhub66 timhub66 added the Working on it Working on this issue label Feb 13, 2025
@hehanli101
Copy link

hehanli101 commented Feb 19, 2025

@timhub66 1.0.0-rc.19 我把版本锁死在这个也不行啊,Antd全局注册的话“createApp(App).use(Antd).use(router).mount('#app');” 第二次进来就报错了,没办法用了

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Working on it Working on this issue
Projects
None yet
Development

No branches or pull requests

6 participants