CJY0208 / react-activation

Hack <KeepAlive /> for React
https://www.npmjs.com/package/react-activation
MIT License
1.78k stars 140 forks source link

Qiankun技术栈,子应用切换,手动调用clear,无法清除所有cache? #278

Open Caesar-APAX opened 1 year ago

Caesar-APAX commented 1 year ago
  const aliveController = useAliveController()
  window.aliveController = aliveController
const initQianKun = () => {
  renderWithQiankun({
    // 文档 https://qiankun.umijs.org/zh/guide/getting-started#
    mount(props: any) {
      console.log('QMS子应用开始挂载......')
      const { container, namespace } = props
      renderApp(container, namespace)
      // 监听主应用传值
      props.onGlobalStateChange((res: any) => {
        console.log(res.count)
      })
    },
    bootstrap() {},
    update() {},
    unmount() {
      console.log('QMS子应用已经卸载......')
      window.aliveController.clear()
      console.log(window.aliveController.getCachingNodes())
    }
  })
}

// 判断当前应用是否在主应用中
qiankunWindow.__POWERED_BY_QIANKUN__ ? initQianKun() : renderApp()
 window.aliveController.clear()
  console.log(window.aliveController.getCachingNodes())

清除后,打印还有当前子应用最后停留的页面缓存cache??? Screen Shot 2023-07-05 at 8 25 09 AM

Caesar-APAX commented 1 year ago

@CJY0208 子应用卸载了,但是console.log的缓存就是切换前子应用最后停留的页面,clear并没有清除掉所有缓存。如何解决呢?

CJY0208 commented 1 year ago

setTimeout 延时清楚和打印命令试试,可能子应用还没有完全卸载,处于激活状态的缓存是无法清楚的

Caesar-APAX commented 1 year ago

@CJY0208 对于乾坤,有没有办法,强制卸载处于激活状态的缓存

Caesar-APAX commented 1 year ago

@CJY0208 因为我切换到其他子应用的时候,当前页面肯定属于激活状态。

CJY0208 commented 1 year ago

是基座的 KeepAlive 还是子应用的 KeepAlive? 如果是子应用的 KeepAlive,就算缓存没及时清,qiankun 依然会移除整个子应用,在这之后子应用内的缓存会被一同清理

如果是基座的 KeepAlive,想要清除子应用的缓存,那就不要对子应用做 KeepAlive 就好