Skip to content

fix(useRequest): respect ready when throttling requests - #2996

Open
Aminark wants to merge 2 commits into
alibaba:masterfrom
Aminark:fix/request-throttle-ready
Open

Aminark wants to merge 2 commits into
alibaba:masterfrom
Aminark:fix/request-throttle-ready

Conversation

@Aminark

@Aminark Aminark commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

🤔 This is a ...

  • Bug fix
  • Test Case

🔗 Related issue link

No linked issue. Reproduced with the regression tests in this PR.

💡 Background and solution

A trailing throttled call made while ready is false can execute if ready becomes true before the throttle timer fires. A previously queued call also survives a false/true ready transition and sends stale parameters.

Apply the same ready handling already used by the debounce plugin: bypass scheduling when ready is false and cancel queued work when ready becomes false. Cancelled queued promises reject with the existing CancelledError; later valid calls still work.

Validation:

  • Regression cases fail against the unchanged implementation and pass with this fix.
  • vitest run src/useRequest (52 tests).
  • tsc --noEmit passes for the hooks package.

📝 Changelog

Language Changelog
🇺🇸 English Respect ready when scheduling and cancelling throttled useRequest calls.
🇨🇳 Chinese 修复 useRequest 节流请求越过 ready 限制,以及关闭后重新开启仍发送过期请求的问题。

☑️ Self Check before Merge

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • TypeScript definition is updated/provided or not needed
  • Changelog is provided or not needed

@pkg-pr-new

pkg-pr-new Bot commented Oct 29, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/ahooks@2996
npm i https://pkg.pr.new/@ahooks.js/use-url-state@2996

commit: d292e67

This branch has not been deployed

No deployments
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.

1 participant