TanStack / TanStack/pacer

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

Open
#257 0 comments 0 reactions 0 assignees View on GitHub

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:

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.