fix(useDebouncedCallback, useThrottledCallback): cancel the pending call when returning to the last forwarded value - #450
Merged
Conversation
…the last forwarded value The dedupe check returned before clearPreviousDebounce(), so a call that matched the last forwarded value left a pending call for a different value alive. Typing 'seoul' → 'seo' → 'seoul' forwarded 'seo'.
🦋 Changeset detectedLatest commit: 4b62235 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #450 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 58 58
Lines 1664 1664
Branches 500 500
=========================================
Hits 1664 1664 🚀 New features to boost your workflow:
|
Contributor
|
Size Change: +7 B (+0.01%) Total Size: 97.3 kB 📦 View Changed
ℹ️ View Unchanged
|
…rning to the last forwarded value Same ordering defect as useDebouncedCallback. The default leading edge forwards the intermediate value immediately and masked it; with edges: ['trailing'] the pending call survived the dedupe early return.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Both
useDebouncedCallbackanduseThrottledCallbackskip a call whose value equals the last forwarded one — but they did so before cancelling the pending call, so a call for a different value scheduled in between survived and fired.useThrottledCallbackhas the same ordering. With the defaultedgesthe leading edge forwards'seo'immediately and updates the compared value, so the third call is not a duplicate and the defect is masked. Withedges: ['trailing']it reproduces exactly as above.The comparison has been first in both callbacks since #90; #446 changed the type but not this ordering.
Fix
Move
clearPreviousDebounce()/clearPreviousThrottle()above the dedupe check. Cancelling was already unconditional on every non-duplicate call, so the only behaviour change is that a duplicate call now also cancels whatever was pending.Tests
One new test per hook,
discards a pending (trailing) value when the caller returns to the last forwarded one. Each fails onmain(onChangecalled 2 times, second with'seo') and passes with the fix. All 521 tests pass, coverage stays at 100%.Changeset
patch— behaviour fix, no API change.