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

[改进]缓存的副作用 #2267

Open
Aeero opened this issue Sep 7, 2022 · 0 comments
Open

[改进]缓存的副作用 #2267

Aeero opened this issue Sep 7, 2022 · 0 comments

Comments

@Aeero
Copy link

Aeero commented Sep 7, 2022

What happens?

子应用切换的时候只会执行mount生命周期,而不会重新从entry.js执行,这会导致一些副作用

最小可复现仓库

官方repo即可

子应用A

地址:http://localhost:7099/A

伪代码如下:

const href = location.href;
 
export async function mount() {
    console.log(href);
    ...
}
 
...

复现步骤,错误日志以及相关配置

第一步
打开链接:http://localhost:7099/A?query=1
console输出:http://localhost:7099/A?query=1

第二步
切换到另外一个子应用

第三步
切换回到子应用A,链接:http://localhost:7099/A?query=2
console输出:http://localhost:7099/A?query=1

此时期望应该是:http://localhost:7099/A?query=2

当然解决方法也很简单,可以改成

export async function mount()  {
    const href = location.href;
    console.log(href);
    ...
}
 ...

why

此类的写法其实还是挺常见的,比如在mount外部,存储localstorage、存储接口返回等等。尤其是一个已经在线上运行的应用想要接入到qiankun中的时候,还得排查此类问题,带来不小的心智负担

伪代码

const key = window.localstorage.getItem('key'); // 123
 
export async function mount() {
    console.log(href); // 都是123
    ...
    const onClick = () => {
        window.localstorage.setItem('key', '456');
    };
    ...
}
 
...

子应用的缓存机制反而会带来副作用

请问一下应该如何解决此类问题?有没有办法配置某些应用禁用缓存?

相关环境信息

  • qiankun 版本
    latest
  • 浏览器版本
    无关
  • 操作系统
    无关
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

1 participant