react-activation icon indicating copy to clipboard operation
react-activation copied to clipboard

[Bug] 激活缓存前同步执行 drop 操作会造成组件不渲染

Open CJY0208 opened this issue 5 years ago • 4 comments

和 @CHEN-J-H 在微信的问题反馈中得知存在此问题,当代码中存在类似如下操作时,造成组件不渲染

356f5d3f9f50b3424aa52383aaa7167

猜测原因为,drop 动作是异步的,但目前和 push 同步调用了,造成了,push 先执行后,drop 生效,KeepAlive 内部的 dom 操作(inject/eject)出现了问题

此处做记录,后续修复

CJY0208 avatar Oct 21 '20 01:10 CJY0208

目前的想法:

首先,兼容同步 drop 的场景:在 drop 期间如果组件重新激活了,则取消 drop 行为

后续:drop 返回 Promise 类型,以便允许依赖 await 语法进行异步卸载行为完成后的事件

await drop('demo-list')
console.log('demo-list dropped ')

考虑参考 React class component 的 setState 方法,兼容 callback 参数(不一定做)

drop('demo-list', () => {
  console.log('demo-list dropped ')
})

CJY0208 avatar Oct 21 '20 02:10 CJY0208

drop('demo-list') setTimeout(() => { history.push('xxxxx') }, 50)

luoxq avatar Jun 30 '21 01:06 luoxq

@luoxq drop 方法支持 promise 了,可以写为

await drop('demo-list')
history.push('xxxxx')

或者

drop('demo-list').then(() => history.push('xxxxx'))

CJY0208 avatar Jun 30 '21 02:06 CJY0208

clear 是不是有同样的问题,

Jickey avatar Jul 16 '21 10:07 Jickey