Skip to content
Source
Sign inSign up
TanStack/pacer

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

OpenDon-Erfan(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/234/headopened

🎯 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.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      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 5bea64ffc5861ffe16ed99d00755a32f5005c578 and 2b2cd3fe15f14f056f6633eadceeb71cb9446e2f.

      📒 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 nameStatusExplanation
      Title check✅ PassedThe title clearly and concisely describes the main fix to debouncer pending state after leading-edge execution.
      Description check✅ PassedThe description explains the problem, fix, tests, checklist completion, and changeset, and it follows the repository template.
      Docstring Coverage✅ PassedNo functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck 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.
    2. 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 in to join this conversation.