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

v1.12.1 useDidRecover拿不到最新的redux中的state #141

Open
chocking opened this issue Feb 8, 2022 · 8 comments
Open

v1.12.1 useDidRecover拿不到最新的redux中的state #141

chocking opened this issue Feb 8, 2022 · 8 comments

Comments

@chocking
Copy link

chocking commented Feb 8, 2022

相关issure: #115
相关文件: https://github.com/CJY0208/react-router-cache-route/blob/v1.12.1/src/core/Updatable.js

import { useSelector } from 'react-redux';
import { useDidRecover } from 'react-router-cache-route';

export default () => {
  const stateA = useSelector((state: RootState) => state.stateA);

 useDidRecover(() => {
    console.log('did recover: ', stateA.count);
  },[stateA.count]);

 ...
}
...

大致代码如上,当页面隐藏时全局store数据改变了,useDidRecover的effect没有更新(因为react-freeze的原因?),导致didRecover时拿到的是旧数据,目前尝试切回到v1.11.1一切正常

@CJY0208
Copy link
Owner

CJY0208 commented Feb 9, 2022

是的,应该是 react-freeze 的原因,我调整下 freeze 的时机,改为延迟冻结

@CJY0208
Copy link
Owner

CJY0208 commented Feb 9, 2022

试试 1.12.4

@CJY0208 CJY0208 closed this as completed Feb 9, 2022
@chocking
Copy link
Author

chocking commented Feb 9, 2022

请问下如果redux的更新是在延迟冻结后的话,效果不是一样的吗,因为依赖的store的更新时机是人为操作的、不确定的

@CJY0208
Copy link
Owner

CJY0208 commented Feb 9, 2022

不太确定,按理来说 freeze 后组件就不再更新了,上边的代码如果获取不到最新值,也需要考虑可能是闭包问题

@chocking
Copy link
Author

chocking commented Feb 9, 2022

感觉不让缓存了的页面进行更新 很容易出现问题,就拿上面的代码来说,就算页面隐藏起来了,但是当全局的stateA.count更新了之后,应该是要重新触发调用useDidRecover,把新的callback传过去的。不仅是全局store这种情况,在页面隐藏之后,页面的任何props变化了,useDidRecover callback里面的都是旧的值。

@chapery
Copy link

chapery commented Feb 9, 2022

升级到 1.12.4 还是拿不到最新的 state @CJY0208

@CJY0208
Copy link
Owner

CJY0208 commented Feb 9, 2022

更新了 1.12.5,发布当中,优化了 effect 的引用,可以不再传入 deps,尝试避免闭包问题

@CJY0208 CJY0208 reopened this Feb 9, 2022
@TrendAlan
Copy link

为什么我的1.12.5这样import会报错?
import { useDidCache, useDidRecover } from 'react-router-cache-route';

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

4 participants