Repository navigation
🐛 Run the latest callback when a debounced call fires - #227
Merged
Merged
Conversation
…test func A call that was pending when the component unmounted still ran, unless the caller passed `cancelOnUnmount: true`. A call also ran the `func` of the render that made it, even if a later render passed a new one. `cancelOnUnmount` now defaults to `true`, and a call runs the latest `func` when the delay ends. The returned function changes only when `wait` changes. Closes #225. Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm BREAKING CHANGE: `useDebounced` cancels a pending call when the component unmounts. To run it after the unmount, as before, pass `{ cancelOnUnmount: false }`.
mbret
marked this pull request as ready for review
November 3, 2026 21:47
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
…n the latest func" This reverts commit 3869164. Cancelling a pending call on unmount loses its work, such as the last save of a form, without an error. Running it late is mostly harmless. So `cancelOnUnmount` stays `false` by default. The next commit adds the latest-func fix again, without the breaking change. Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
A call ran the `func` of the render that made it, even if a later render passed a new one. It now runs the latest `func`, and the returned function changes only when `wait` changes. `cancelOnUnmount` keeps its `false` default, so a pending call, such as a save, still runs after the component unmounts. Closes #225. Claude-Session: https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm
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.
Why
A pending debounced call runs the
funcof the render that made it, with the props and state of that render. If a later render passes a newfunc, the pending call still uses the old one.funcwhen the delay ends.What's new
useDebouncedruns the latestfuncwhen the delay ends (closes useDebounced: calls func after unmount by default, and runs the func of the calling render #225)Other changes
funcand both unmount optionsuseDebounceddocs pageDetails
Unmount
cancelOnUnmountkeeps itsfalsedefault. So a pending call, such as the last save of a form, still runs after the component unmounts. Cancelling it would lose that work without an error.Returned function
The returned function changes only when
waitchanges. Before, it also changed with each newfunc. The JSDoc no longer claims a defaultwaitof 300 ms: the hook has no default.Release
The branch holds a commit that changed the unmount default, with a
BREAKING CHANGE:footer, and its revert. semantic-release ignores a reverted commit and its revert, so merging publishes a patch release. The commit analyzer returnspatchfor the branch commits.🔍 Self-reviewed with selfcorrect-review
🤖 Made within harness coverage
🤖 Generated with Claude Code
https://claude.ai/code/session_01BvSDyJABLGit75HAjpnsqm