Skip to content

fix(compat/function/debounce): skip maxWait invocation when both leading and trailing are false#1678

Open
sukvvon wants to merge 2 commits intotoss:mainfrom
sukvvon:fix/compat-debounce-maxwait-guard
Open

fix(compat/function/debounce): skip maxWait invocation when both leading and trailing are false#1678
sukvvon wants to merge 2 commits intotoss:mainfrom
sukvvon:fix/compat-debounce-maxwait-guard

Conversation

@sukvvon
Copy link
Copy Markdown
Contributor

@sukvvon sukvvon commented Apr 3, 2026

Summary

  • Guard maxWait forced invocation with leading || trailing check in compat debounce
  • When both leading and trailing are false, maxWait expiry no longer triggers function execution, matching lodash behavior
  • Add regression tests for both compat debounce and compat throttle

Root Cause

The compat debounce unconditionally called func.apply() when maxWait elapsed, ignoring the leading/trailing options. Lodash skips execution when both edges are disabled — even if maxWait is reached.

This was previously attempted in #1560 (workaround in throttle), which was reverted. This fix addresses the root cause in debounce itself, as suggested by @raon0211.

Fixes #1494

Test Plan

  • Added test: compat debounce with { leading: false, trailing: false, maxWait: 64 } → 0 invocations
  • Added test: compat throttle with { leading: false, trailing: false } → 0 invocations
  • All existing 4333 tests pass
  • Verified output matches lodash for all 4 leading/trailing combinations

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment Apr 3, 2026 11:20am

Request Review

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.

Discrepancy between lodash and compat throttle with both trailing and leading disabled

1 participant