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

主应用使用vue,并且使用了路由懒加载 #517

Closed
daichunlin1995 opened this issue Apr 26, 2020 · 13 comments · Fixed by #995
Closed

主应用使用vue,并且使用了路由懒加载 #517

daichunlin1995 opened this issue Apr 26, 2020 · 13 comments · Fixed by #995
Assignees

Comments

@daichunlin1995
Copy link

What happens?

主应用使用vue,并且使用了路由懒加载,当子应用加载之后,切换主应用的路由,相对应懒加载的组件样式不加载

复现

1.在加载子应用之后切换到该页面
image

2.加载子应用之前点击切换到该页面
image

相关环境信息

  • qiankun 版本:2.0.5
  • 浏览器版本:chrome
  • 操作系统:win10
@kuitos
Copy link
Member

kuitos commented Apr 26, 2020

提供可复现仓库

@daichunlin1995
Copy link
Author

提供可复现仓库

https://github.com/daichunlin1995/qiankun-demo.git

@kuitos
Copy link
Member

kuitos commented Apr 27, 2020

跟这个是同一个问题?#503 @Deturium

@daichunlin1995
Copy link
Author

跟这个是同一个问题?#503 @Deturium

嗯,应该是一个问题,请问这个该怎么解决啊

@zhxx
Copy link

zhxx commented May 9, 2020

遇到了相同的问题,看了下,是因为document.head.appendChild被改写了,导致vue-style-loader没有把样式加到正确的节点上。@kuitos 有什么建议吗?

@zhxx
Copy link

zhxx commented May 12, 2020

vue-router在路由变化之前加载资源,加载完毕再跳转。因为路由没有变化,qiankun判断微应用还是activated状态,用newAppendChild加载css。

const activated = checkActivityFunctions(window.location).some(name => name === appName); // only hijack dynamic style injection when app activated if (activated) { dynamicStyleSheetElements.push(stylesheetElement); return rawAppendChild.call(appWrapperGetter(), stylesheetElement) as T; }

我觉得是不是可以加一个手动卸载微应用的方法?@Deturium

@zhxx
Copy link

zhxx commented May 12, 2020

目前解决这个问题的临时方案如下:
在main.js里保存一份appendChild,然后在vue-router的钩子函数beforeEach里判断to.path是不是微应用,如果不是,就把HTMLHeadElement.prototype.appendChild改回来

@kawhi66
Copy link

kawhi66 commented May 18, 2020

应该考虑从沙箱内部做隔离,在修正引导阶段的副作用的时候,可以考虑通过 assetPublicPath 隔离站点资源。

// only hijack dynamic style injection when app activated
if (
  activated &&
  stylesheetElement.baseURI.startsWith(assetPublicPath)
) {
  dynamicStyleSheetElements.push(stylesheetElement);

  const appWrapper = getWrapperElement(appName);
  assertElementExist(appName, appWrapper);
  return rawAppendChild.call(appWrapper, stylesheetElement) as T;
}

@warplan
Copy link

warplan commented May 25, 2020

遇到了相同的问题,在不同的子应用来回切换,会引发样式丢失现象

@shuyanzi
Copy link

shuyanzi commented Jun 2, 2020

遇到了相同的问题,在不同的子应用来回切换,会引发样式丢失现象
同问
1、子应用用动态style的方式,子应用间来回切换会出现样式丢失的问题
2、子应用用动态link的方式,子应用间切换会样式闪烁,css资源加载慢,等一会儿才正常

@kuitos

@liuzhen88
Copy link

遇到了相同的问题,在不同的子应用来回切换,会引发样式丢失现象
同问
1、子应用用动态style的方式,子应用间来回切换会出现样式丢失的问题
2、子应用用动态link的方式,子应用间切换会样式闪烁,css资源加载慢,等一会儿才正常

@kuitos

我也遇到了这种问题,有解决办法吗?

@littleluckly
Copy link

遇到了相同的问题,在不同的子应用来回切换,会引发样式丢失现象
同问
1、子应用用动态style的方式,子应用间来回切换会出现样式丢失的问题
2、子应用用动态link的方式,子应用间切换会样式闪烁,css资源加载慢,等一会儿才正常

@kuitos

我也遇到了这种问题,有解决办法吗?

#578 有人回答了,不知道可不可行

@lkiarest
Copy link
Contributor

lkiarest commented Jul 7, 2020

测试了一下,动态样式丢失的情况出现在 dynamicAppend.ts 最后一行 rebuild 中的处理,

if (mounting) {
        dynamicStyleSheetElements = [];
}

子应用切换的时候,有的样式是在动态加载的 js 脚本里创建的,这个时候 mounting 为 true,导致缓存的样式被清理掉了,第二次切换样式就会丢失(貌似第二次加载也不会再通过动态 js 去创建了)。

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.

10 participants