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

同时使用useRequest、useCookieState、useNavigate(react-router 6.8)会导致cookie设置失效 #2073

Closed
4innocent opened this issue Feb 21, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@4innocent
Copy link

image

使用setTimeout可以解决这个问题,但我认为这里不应该有一个setTimeout。看起来似乎是代码的执行顺序被打乱,直接跳转了。有没有什么解决办法?
@4innocent
Copy link
Author

btw,onFinally、runAsync,我试过了,都没有用

@liuyib
Copy link
Collaborator

liuyib commented Feb 21, 2023

@crazylxr

以上问题,对于具有“存储能力的 hook” 验证结果如下:

  • useUrlStateuseCookieState 均存在以上问题
  • useLocalStorageStateuseSessionStorageState 没有问题

@liuyib
Copy link
Collaborator

liuyib commented Feb 21, 2023

useCookieState 的问题已提 PR:#2074
useUrlState 也有 bug,我目前还没有排查代码useUrlState 在路由跳转前更新,会被后面路由跳转给覆盖掉。也就是路由查询参数确实被更新了,但是路由跳转时没带上的话,就会表现出“被覆盖掉 或 没更新”的行为,其实是正常的,预期之中)。

@liuyib
Copy link
Collaborator

liuyib commented Feb 22, 2023

@4innocent 可以临时先按照你的方法(setTimeout)解决,目前已初步证实有 bug,在修复了

@crazylxr crazylxr added this to In progress in ahooks tasks Feb 22, 2023
@liuyib
Copy link
Collaborator

liuyib commented Feb 22, 2023

useUrlState 我这边初步验证的也是存在这个问题 (再次验证,这个 hook 没问题),useCookieState 的已经提 PR 了,可以 review 下(useCookieState 的 PR 已合并)

crazylxr added a commit that referenced this issue Feb 23, 2023
@liuyib liuyib added the bug Something isn't working label Feb 23, 2023
@crazylxr
Copy link
Collaborator

3.7.5 已发布

ahooks tasks automation moved this from In progress to Done Feb 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Development

No branches or pull requests

3 participants