Skip to content

fix(core): stop debounce double-invoking a single leading+trailing call - #198

Merged
JosunLP merged 1 commit into
devfrom
fix/178-debounce-double-invoke
Jul 6, 2026
Merged

fix(core): stop debounce double-invoking a single leading+trailing call#198
JosunLP merged 1 commit into
devfrom
fix/178-debounce-double-invoke

Conversation

@JosunLP

@JosunLP JosunLP commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #178 (Low; correctness).

With { leading: true, trailing: true }, a single call double-invoked: the leading branch invoked with preservePending = trailing (keeping pendingArgs), then trailingTrigger saw pendingArgs still set and invoked again. One call → two invocations.

Fix

The leading invoke now clears pendingArgs. A subsequent call within the window re-sets pendingArgs (the leading branch is skipped once leadingDone), so the trailing edge still fires — but only when the function was called more than once, matching lodash semantics.

Verification

  • Existing multi-call test (fn(1); fn(2); fn(3)[1, 3]) still passes.
  • Rewrote the single-call test that previously codified the bug: fn(1) now yields [1], not [1, 1]. It fails on the pre-fix code.
  • function/utils/core suites: all pass. tsc --noEmit clean.

🤖 Generated with Claude Code

With { leading: true, trailing: true } a single call fired twice: the
leading branch invoked with preservePending=trailing (keeping pendingArgs),
then trailingTrigger saw pendingArgs still set and invoked again. The
leading invoke now clears pendingArgs; a subsequent call within the window
re-sets it (the leading branch is skipped), so the trailing edge still
fires only when the function was called more than once (lodash semantics).

Fixes #178

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: aa7e9b6a-1240-44d9-a09c-6df6ef01e205

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/178-debounce-double-invoke

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.

@github-actions github-actions Bot added core Changes to the core module tests Chenges to the tests labels Jul 6, 2026
@JosunLP
JosunLP merged commit c8bc8a3 into dev Jul 6, 2026
9 of 10 checks passed
@JosunLP
JosunLP deleted the fix/178-debounce-double-invoke branch July 6, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Changes to the core module tests Chenges to the tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant