You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for the fix! The current change handles the reported case, but there is still one edge case.
After ready becomes false, calling run() while it remains false creates a new leading debounce window. Although the request itself is stopped by the ready plugin, switching ready back to true within debounceWait will still delay the next auto run.
Steps to reproduce:
Start with ready: true and debounceLeading: true.
Change ready to false.
Call run() while ready is false.
Change ready back to true before debounceWait expires.
The service is not called immediately in step 4.
Could we bypass debounce when fetchInstance.options.ready === false and add a regression test for this case? Once this edge case is covered, the fix should be good to merge.
Thanks for the fix! The current change handles the reported case, but there is still one edge case.
After ready becomes false, calling run() while it remains false creates a new leading debounce window. Although the request itself is stopped by the ready plugin, switching ready back to true within debounceWait will still delay the next auto run.
Steps to reproduce:
Start with ready: true and debounceLeading: true.
Change ready to false.
Call run() while ready is false.
Change ready back to true before debounceWait expires.
The service is not called immediately in step 4.
Could we bypass debounce when fetchInstance.options.ready === false and add a regression test for this case? Once this edge case is covered, the fix should be good to merge.
Thanks for pointing out this edge case.
I’ve updated the fix to bypass debounce when fetchInstance.options.ready === false, so calling run() while ready remains false will no longer create a new leading debounce window. I also updated the regression test to cover the exact flow you described: ready: true -> ready: false -> manual run() -> ready: true again within debounceWait.
Validation:
pnpm --filter ahooks test src/useRequest/__tests__/useDebouncePlugin.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤔 This is a ...
🔗 Related issue link
Fix #2581
💡 Background and solution
When
useRequestis used withreadyanddebounceLeading, the pending debounce window may remain active afterreadybecomesfalse.If
readyturns back totruebefore that debounce window ends, the next auto run may not trigger immediately as expected bydebounceLeading.This PR cancels the current debounce window when
readybecomesfalse, so the nextready=trueauto run can trigger immediately withdebounceLeading.A test case is added for the
ready + debounceLeadingscenario.📝 Changelog
useRequestmay not trigger immediately whenreadyis used withdebounceLeading.useRequest同时使用ready和debounceLeading时可能无法立即触发请求的问题。☑️ Self Check before Merge