fix(useThrottledCallback): invoke the callback when the first value is false - #404
Merged
Merged
Conversation
…s false The hook compares an incoming value against the last one it forwarded to onChange so it can skip redundant invocations. That comparison was seeded with `false`, but the hook never receives an initial value from the caller, so a first call of `false` looked redundant and was dropped. Consumers whose state starts as `true` therefore lost the transition back to `false` entirely, with no way to tell the hook otherwise. Seed the comparison with a sentinel instead so the first call is always forwarded.
🦋 Changeset detectedLatest commit: 8f04f14 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 #404 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 58 58
Lines 1639 1643 +4
Branches 499 499
=========================================
+ Hits 1639 1643 +4 🚀 New features to boost your workflow:
|
bbjbc
force-pushed
the
fix/throttled-callback-initial-false
branch
2 times, most recently
from
August 13, 2026 14:54
be481ef to
8f04f14
Compare
hyesungoh
approved these changes
Aug 13, 2026
hyesungoh
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution! 👍
Merged
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.
Overview
useThrottledCallbackdrops the very first call when the value isfalse.The hook skips redundant invocations by comparing the incoming value against the last one it forwarded to
onChange. That comparison is seeded withfalse:Since the hook takes no initial value from the caller, a first call of
falsematches the seed and returns early, soonChangenever fires.This matters for consumers whose state does not start at
false. If a panel is open by default, the first close emitsfalse, and that transition is silently dropped with no way to tell the hook the state started astrue.useDebouncedCallbackhas the same seed. I left it alone here because #267 is already changing that line. Its generic rewrite switches the seed tonull, which fixes this case as a side effect, though a narrower version of the problem survives there: a first call ofnullwould still be dropped.Changes
false, so the first call is forwarded regardless of its value. The dedup comparison itself is unchanged, so repeated values are still skipped.false, one asserting a repeatedfalseis still skipped so the dedup behavior stays pinned.A
Symbolis used rather thannullorundefinedbecause it cannot collide with a caller-supplied value if this hook later becomes generic, asuseDebouncedCallbackis doing in #267.Existing tests all start with
result.current(true), which is why this was not caught. The early-return branch is already covered by the repeated-truecases, so branch coverage was 100% while the first-call-falsepath was never exercised.Checklist
yarn run fixto format and lint the code and docs?yarn run test:coverageto make sure there is no uncovered line?