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

fix: resolves useRquest debounce issue #2606

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

ruixingshi
Copy link
Contributor

@ruixingshi ruixingshi commented Jul 22, 2024

[English Template / 英文模板]

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

useRequest的debounceLeading和ready结合使用时不生效

💡 需求背景和解决方案

需求背景
useRequest的debounceLeading和ready结合使用时不生效

解决方案
①问题定位,核心原因是在useRequest在mount的时候,只会通过判断manual决定是否执行第一次:
image
因此,会在mount时,执行一次debounce的request动作,导致在debounceWait的时间里都无法执行。如果上面这个codebox的demo把debounceWait时间改成10s,将更容易复现。

②但是为什么执行了会不生效呢?也就是没有loading,也不会出现结果:
image
因为在这里第一次runASync时,拿到的回调至stopNow会根据ready设置为true,因此实际上是首次执行了一次方法,但这个方法被终止,但是debounceWait的效果还在。

③如何修复:
image
在useRequest Mount的地方加上ready的判断,和stopNow判断保持一致。

修复Demo仓库

📝 更新日志

语言 更新描述
🇺🇸 英文 Fix the problem that useRequest cannot request correctly for the first time mount in the debounce scenario
🇨🇳 中文 修复useRequest在debounce场景下,首次mount时无法正常发起请求的问题

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


shiruixing seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@crazylxr crazylxr merged commit ac46912 into alibaba:master Aug 5, 2024
5 of 6 checks passed
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

Successfully merging this pull request may close these issues.

3 participants