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:
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
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
executeafter another run has finished executing,lastArgsis reset toundefinedand 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:
The root cause seems to be the following sequence:
AexecutesBis queued andsetTimeoutis calledAcompletes andlastArgsis reset to undefinedB's timeout procs but this condition resolves false becauselastArgswas resetInstead 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
waitand intrinsic async delay of the search behavior.I suspect the fix may be as simple as reading and immediately "consuming"
lastArgsbefore actually invoking the debounced callback. I believe this would allow a subsequent enqueued run to safely set itslastArgsand 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