Skip to content

fix: reset pending state after leading-only debouncer execution - #234

Open
Don-Erfan wants to merge 3 commits into
TanStack:mainfrom
Don-Erfan:Fix/debouncer-leading-pending-state
Open

fix: reset pending state after leading-only debouncer execution#234
Don-Erfan wants to merge 3 commits into
TanStack:mainfrom
Don-Erfan:Fix/debouncer-leading-pending-state

Conversation

@Don-Erfan

@Don-Erfan Don-Erfan commented Jul 14, 2026

Copy link
Copy Markdown

🎯 Changes

With leading: true and trailing: true, a single call to maybeExecute executed on the leading edge but still set isPending: true and stored lastArgs. The trailing timeout correctly skips calls already handled by the leading edge, so nothing ever reset that state: status stayed 'pending' forever, and a later flush() re-executed the function with stale, already-executed arguments.

Fix

  • Only set isPending / lastArgs for calls that were not consumed by the leading edge, so the debouncer returns to 'idle' after a single execution.
  • Applied the same fix to LiteDebouncer, which stored lastArgs unconditionally and could therefore re-execute a leading-edge call via flush().

Tests

  • Added coverage for leading + trailing execution, flush() behavior after a leading-edge call, pending state, and idle transitions.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes

    • Prevented debounced actions configured for leading and trailing execution from being invoked twice with the same arguments.
    • Improved flush() behavior so it no longer re-executes completed leading-edge calls.
    • Corrected pending-state and idle-status handling after a single debounced execution.
  • Tests

    • Added coverage for leading/trailing execution, flush(), pending state, and idle transitions.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6407c534-35fd-48dc-8ad3-b63667e82198

📥 Commits

Reviewing files that changed from the base of the PR and between 5bea64f and 2b2cd3f.

📒 Files selected for processing (1)
  • .changeset/leading-edge-pending-reset.md

Included review availability: Your plan includes up to 4 reviews per rolling hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Both debouncer implementations now prevent leading-edge calls from running again through trailing execution or flush(). Tests cover duplicate prevention, cleared arguments, pending state, and idle status. A changeset records patch releases for both packages.

Changes

Debouncer leading-edge behavior

Layer / File(s) Summary
Prevent duplicate trailing and flush execution
packages/pacer/src/debouncer.ts, packages/pacer-lite/src/lite-debouncer.ts, packages/pacer/tests/debouncer.ts, packages/pacer-lite/tests/lite-debouncer.test.ts, .changeset/leading-edge-pending-reset.md
Leading-handled calls no longer retain arguments or enter pending trailing state. Tests verify that flush() does not invoke them again and that the debouncer clears arguments and returns to idle. The changeset records patch releases for both packages.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 2b2cd

This change resets debouncer state correctly after a leading-edge execution and prevents stale re-execution through flush; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix to debouncer pending state after leading-edge execution.
Description check ✅ Passed The description explains the problem, fix, tests, checklist completion, and changeset, and it follows the repository template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai

coderabbitai Bot commented Aug 15, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants