Queued AsyncDebounce execution is silently dropped if it is executed after an in-flight run completes
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 769
- Forks
- 64
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 3
Description
TanStack Pacer version
0.23.0
Framework/Library version
React 19
Describe the bug and the steps to reproduce it
When the timing of the debounce wait aligns to call execute after another run has finished executing, lastArgs is reset to undefined and the execution is skipped. This is consistently reproducible when a new execution is queued while a current one is in flight, and the new execution begins after the current one has completed.
It might be easier to explain by counterexample: this bug is not reproducible if:
- A new execution is queued and executed before the current one completed
- A new execution is queued after the current one completed
The root cause seems to be the following sequence:
- Run
Aexecutes - Run
Bis queued andsetTimeoutis called - Run
Acompletes andlastArgsis reset to undefined - Run
B's timeout procs but this condition resolves false becauselastArgswas reset
Instead of firing the queued invocation, the trailing execution is dropped.
The attached reproduction sandbox produces the problem by aligning the timing of the second execution with the wait and intrinsic async delay of the search behavior.
I suspect the fix may be as simple as reading and immediately "consuming" lastArgs before actually invoking the debounced callback. I believe this would allow a subsequent enqueued run to safely set its lastArgs and rely on it to stay in place, but this still feels a little fragile.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
https://codesandbox.io/p/sandbox/gallant-voice-dddk6m
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
Yes, I think I know how to fix it and will discuss it in the comments of this issue
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/pacer/src/async-debouncer.ts, especially the setTimeout condition around lines 343-345 and the lastArgs reset around line 394. Reproduce the timing from the linked CodeSandbox, then add regression coverage showing that a queued execution still runs after the in-flight execution completes. Done means the trailing invocation is no longer silently dropped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100