Skip to content

Conversation

@lvboda
Copy link

@lvboda lvboda commented Oct 24, 2025

[中文版模板 / Chinese template]

🤔 This is a ...

  • New feature
  • Bug fix
  • Site / documentation update
  • Demo update
  • TypeScript definition update
  • Bundle size optimization
  • Performance optimization
  • Enhancement feature
  • Internationalization
  • Refactoring
  • Code style optimization
  • Test Case
  • Branch merge
  • Other (about what?)

🔗 Related issue link

Close #2792

💡 Background and solution

  • Background:
    • In useRequest, when ready=false, calling runAsync returns a Promise that stays pending, causing the call to hang.
  • Solution:
    • In Fetch.runAsync, when a plugin signals stopNow, return Promise.resolve(state.data) instead of a never-resolving Promise.
    • Add tests to ensure that when ready=false (in both manual and auto modes), runAsync resolves immediately and does not remain pending.

📝 Changelog

function Component() {
  const { runAsync } = useRequest(fetchUser, { manual: true, ready: false });

  const onSave = async () => {
    const res = await runAsync({ id: 1 });
    // Before: this code never ran because the await above blocked indefinitely
    // After: written like this, it throws:
    // Uncaught TypeError: Cannot read properties of undefined (reading 'user')
    alert(res.user);
  };

  return <button onClick={onSave}>Save</button>;
}
Language Changelog
🇺🇸 English fix(useRequest): return immediately in runAsync when ready=false (no pending)
🇨🇳 Chinese fix(useRequest): 当 ready=false 时调用 runAsync 立即返回而不是阻塞

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • 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

@CLAassistant
Copy link

CLAassistant commented Oct 24, 2025

CLA assistant check
All committers have signed the CLA.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 27, 2025

npm i https://pkg.pr.new/ahooks@2866
npm i https://pkg.pr.new/@ahooksjs/use-url-state@2866

commit: e443b02

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.

useRequest 当 manual 为 true,ready 为 false 时调用 runAsync 会一直 pending

3 participants