Skip to content
Source
Sign inSign up
TanStack/pacer

Queued AsyncDebounce execution is silently dropped if it is executed after an in-flight run completes #257

Send to my agent
Opengrant-progress(GitHub profile, opens in a new tab) opened this issue 0 comments

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.

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.
  1. KevinVandy linked this to #271

Sign in to join this conversation.